2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/28/2003 *
4 * =================== Last change: 08/18/2004 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_user.php *
8 * -------------------------------------------------------------------- *
9 * Short description : List all or partial members *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Alle oder nur bestimmte Mitglieder auflisten *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009, 2010 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addMenuDescription('admin', __FILE__);
46 if ((!isExtensionInstalled('user')) || (!isExtensionActive('user'))) {
48 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
56 // Add nickname if extension is found&active
57 // @TODO Rewrite these if-blocks in a filter
58 if (isExtensionActive('nickname')) {
60 $MORE .= ", `nickname`";
62 $MORE .= ", `userid`";
65 // Add random confirmed if extension version matches
66 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
68 $MORE .= ", `rand_confirmed`";
71 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
73 $MORE .= ", `lock_reason`, UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`";
77 // Is the extension 'country' installed?
78 if (isExtensionActive('country')) {
80 $MORE .= ", `country_code`";
83 $MORE .= ", `country`";
87 if (!isGetRequestParameterSet('letter')) { setGetRequestParameter('letter', ''); }
88 if (!isGetRequestParameterSet('sortby')) { setGetRequestParameter('sortby', 'userid'); }
89 if (!isGetRequestParameterSet('page')) { setGetRequestParameter('page' , 1); }
92 $base = '[<a href="{%url=modules.php?module=admin';
94 if (isGetRequestParameterSet('userid')) {
96 $userid = bigintval(getRequestParameter('userid'));
98 // Does the account exists?
99 $result_user = SQL_QUERY_ESC("SELECT
100 `userid`, `gender`, `surname`, `family`, `street_nr`, `zip`, `city`, `country`, `email`, `birth_day`, `birth_month`, `birth_year`, `max_mails`, `receive_mails`, `refid`, `status`, `REMOTE_ADDR`, `last_online`, `last_module`, `ref_clicks`, `total_logins`, `used_points`, `emails_sent`, `joined`, `last_update`, `last_profile_sent`, `notified`, `ref_payout`, `emails_received`, `mails_confirmed`".$MORE."
102 `{?_MYSQL_PREFIX?}_user_data`
106 array($userid), __FILE__, __LINE__);
109 if (SQL_NUMROWS($result_user) == 1) {
111 $content = SQL_FETCHARRAY($result_user);
113 // Get count/sum of refs, selected categories, unconfirmed mails
114 $content['refs'] = countSumTotalData($userid, 'refsystem' , 'counter');
115 $content['cats'] = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
116 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
118 // Add links to the numbers
119 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
120 if (isValidUserId($content['refid'])) $content['refid'] = $base . '&what=list_user&userid=' . $content['refid'] . '%}">'.$content['refid'] . '</a>]';
121 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
122 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
124 // Calculate timestamp for birthday
125 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
127 // Is this above zero?
130 $content['birthday'] = generateDateTime($stamp, 3);
132 // Zero or below so set zero!
133 $content['birthday'] = generateDateTime(0, 3);
136 // Prepare data for template
137 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
138 $content['last_online'] = generateDateTime($content['last_online'], 0);
139 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $userid . '%}">}{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
140 $content['joined'] = generateDateTime($content['joined'], 0);
141 $content['last_update'] = generateDateTime($content['last_update'], 0);
142 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
143 $content['total'] = countSumTotalData($userid, 'user_points', 'points');
144 $content['locked'] = countSumTotalData($userid, 'user_points', 'locked_points');
145 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
146 $content['nickname'] = '{--EXT_NICKNAME_404--}';
148 // Nickname inclusion?
149 // @TODO Rewrite these to filters
150 if (isExtensionInstalled('nickname')) $content['nickname'] = getNickname($content['userid']);
153 $content['click_rate'] = '0';
154 if ($content['emails_received'] > 0) {
155 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
158 // Is the extension 'country' installed?
159 if (isExtensionActive('country')) {
160 // Then overwrite country information
161 $content['country'] = generateCountryInfo($content['country_code']);
162 } elseif ($content['country'] == '0') {
164 $content['country'] = '???';
168 $content['userid'] = $userid;
170 // Load user-details template
171 loadTemplate('admin_user_details', false, $content);
173 // Account does not exist!
174 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_404', $userid));
178 SQL_FREERESULT($result_user);
180 $whereStatement = '';
181 if (isGetRequestParameterSet('letter')) {
182 // List only persons w
183 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
186 // Parse the status or mode parameter
187 if (isGetRequestParameterSet('status')) {
188 // Is a WHERE statement already there?
189 if (!empty($whereStatement)) {
190 // Then append the status column
191 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
194 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
196 } elseif (isGetRequestParameterSet('mode')) {
197 // Choose what we need to list
198 switch (getRequestParameter('mode')) {
199 case 'norefs': // Users w/o refs
200 if (!empty($whereStatement)) {
202 $whereStatement .= " AND `refid`=0";
204 // Add WHERE statement
205 $whereStatement = " WHERE `refid`=0";
209 default: // Invalid list mode
210 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
215 // Generate master query string
216 $sql = sprintf("SELECT `userid`, `gender`, `surname`, `family`, `email`, `REMOTE_ADDR`, `refid`, `status`, `emails_sent`, `mails_confirmed`, `emails_received`" . $MORE . " FROM `{?_MYSQL_PREFIX?}_user_data`" . $whereStatement . " ORDER BY `%s` ASC",
217 getRequestParameter('sortby')
220 // Prepare SQL and run it
221 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
223 // Calculate page count (0.5 fixes a bug with page count)
224 if (getConfig('user_limit') == '0') {
225 setConfigEntry('user_limit', 100);
226 loadTemplate('admin_settings_saved', false, '{--EXTENSION_WARNING_USER_LIMIT--}');
229 // Activate the extension please!
230 $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
232 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page' , 1);
233 if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
235 // Add limitation to SQL string and run him again
236 $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
237 $result = SQL_QUERY($sql, __FILE__, __LINE__);
239 // Are there some entries?
240 if (!SQL_HASZERONUMS($result_master)) {
241 // We have some (new?) registrations!
242 $templateContent['colspan2'] = ($colspan + 2);
243 $templateContent['user_count'] = getTotalConfirmedUser();
246 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
247 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
248 $templateContent['page_nav'] = '';
251 $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
254 // Column with nickname when nickname extension is present
255 // @TODO Rewrite this into a filter
256 $templateContent['nickname_th'] = '';
257 if (isExtensionActive('nickname')) {
258 // Nickname extension found
259 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
264 while ($content = SQL_FETCHARRAY($result)) {
265 // Merge more data in
266 $content = merge_array($content, $templateContent);
268 // Get number of unconfirmed mails
269 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
270 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
272 // Set link to sent mails if present
273 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
276 $content['nickname'] = '{--EXT_NICKNAME_404--}';
277 if (isExtensionInstalled('nickname')) $content['nickname'] = getNickname($content['userid']);
280 $content['rate'] = '0';
281 if ($content['emails_received'] > 0) {
282 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
285 // Transfer data to array
286 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
287 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
288 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
289 $content['locked'] = countSumTotalData($content['userid'], 'user_points', 'locked_points');
291 // If we have at least one referal, make it clickable to referal list
292 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
294 // Is the extension 'country' installed?
295 // @TODO Rewrite this into a filter
296 if (isExtensionActive('country')) {
297 // Then overwrite country information
298 $content['country'] = generateCountryInfo($content['country_code']);
299 } elseif ($content['country'] == '') {
301 $content['country'] = '???';
304 // Load row template and switch colors
305 $OUT .= loadTemplate('admin_list_user_row', true, $content);
309 SQL_FREERESULT($result);
312 SQL_FREERESULT($result_master);
315 $content['rows'] = $OUT;
317 // Init title with "all accounts"
318 $content['title'] = '{--ADMIN_ALL_ACCOUNTS--}';
319 if (isGetRequestParameterSet('status')) {
320 // Set title according to the 'status'
321 $content['title'] = sprintf("{--ADMIN_LIST_STATUS_%s_ACCOUNTS--}", strtoupper(getRequestParameter('status')));
322 } elseif (isGetRequestParameterSet('mode')) {
323 // Set title according to the "mode"
324 $content['title'] = sprintf("{--ADMIN_LIST_MODE_%s_ACCOUNTS--}", strtoupper(getRequestParameter('mode')));
327 // Merge more data again
328 $content = merge_array($content, $templateContent);
330 // Load main template
331 loadTemplate('admin_list_user', false, $content);
333 // No one as registered so far! :-(
334 loadTemplate('admin_settings_saved', false, '{--ADMIN_NO_NONE_REGISTERED--}');
338 SQL_FREERESULT($result_master);