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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
47 if ((!isExtensionInstalled('user')) || (!isExtensionActive('user'))) {
49 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
57 // Add nickname if extension is found&active
58 // @TODO Rewrite these if-blocks in a filter
59 if (isExtensionActive('nickname')) {
61 $MORE .= ", `nickname`";
63 $MORE .= ", `userid`";
66 // Add random confirmed if extension version matches
67 if (getExtensionVersion('user') >= '0.3.4') {
69 $MORE .= ", `rand_confirmed`";
72 if (getExtensionVersion('user') >= '0.3.5') {
74 $MORE .= ", `lock_reason`, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
78 // Is the extension 'country' installed?
79 if (isExtensionActive('country')) {
81 $MORE .= ", `country_code`";
84 $MORE .= ", `country`";
88 if (!isGetRequestElementSet('letter')) { setRequestGetElement('letter', getMessage('_ALL2')); }
89 if (!isGetRequestElementSet('sortby')) { setRequestGetElement('sortby', 'userid'); }
90 if (!isGetRequestElementSet('page')) { setRequestGetElement('page' , 1); }
93 $base = '[<a href="{?URL?}/modules.php?module=admin';
95 if (isGetRequestElementSet('userid')) {
97 $userid = bigintval(getRequestElement('userid'));
99 // Does the account exists?
100 $result_user = SQL_QUERY_ESC("SELECT
101 `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."
103 `{?_MYSQL_PREFIX?}_user_data`
107 array($userid), __FILE__, __LINE__);
110 if (SQL_NUMROWS($result_user) == 1) {
112 $content = SQL_FETCHARRAY($result_user);
114 // Get count/sum of refs, selected categories, unconfirmed mails
115 $content['refs'] = countSumTotalData($userid, 'refsystem' , 'counter');
116 $content['cats'] = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
117 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
119 // Add links to the numbers
120 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '">' . $content['links'] . '</a>]';
121 if ($content['refid'] > 0) $content['refid'] = $base . '&what=list_user&userid=' . $content['refid'] . '">'.$content['refid'] . '</a>]';
122 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '">' . $content['refs'] . '</a>]';
123 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '">' . $content['cats'] . '</a>]';
126 if (empty($content['last_module'])) $content['last_module'] = '---';
128 // Calculate timestamp for birthday
129 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
131 // Is this above zero?
134 $content['birthday'] = generateDateTime($stamp, 3);
136 // Zero or below so set zero!
137 $content['birthday'] = generateDateTime(0, 3);
140 // Prepare data for template
141 $content['admin_links'] = generateMemberAdminActionLinks($userid, $content['status']);
142 $content['gender'] = translateGender($content['gender']);
143 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
144 $content['status'] = translateUserStatus($content['status']);
145 $content['last_online'] = generateDateTime($content['last_online'], 0);
146 $content['used_points'] = translateComma($content['used_points']);
147 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $userid . '">' . translateComma($content['emails_sent']) . '</a>]';
148 $content['joined'] = generateDateTime($content['joined'], 0);
149 $content['last_update'] = generateDateTime($content['last_update'], 0);
150 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
151 $content['total'] = translateComma(countSumTotalData($userid, 'user_points', 'points'));
152 $content['locked'] = translateComma(countSumTotalData($userid, 'user_points', 'locked_points'));
153 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
155 // Is the lock reason not set?
156 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
158 // Nickname inclusion?
159 // @TODO Rewrite these to filters
160 if (isExtensionActive('nickname')) {
161 // Nickname not set or invalid? Then
162 if ((empty($content['nickname'])) || ($content['nickname'] == $userid)) $content['nickname'] = '---';
164 // Extension not found
165 $content['nickname'] = getMessage('EXT_NICKNAME_404');
168 // Is the user extension newer?
169 if (getExtensionVersion('user') >= '0.3.4') {
170 // Then "translate" the number
171 $content['rand_confirmed'] = translateComma($content['rand_confirmed']);
175 $content['click_rate'] = '0';
176 if ($content['emails_received'] > 0) {
177 $content['click_rate'] = translateComma($content['mails_confirmed'] / $content['emails_received'] * 100);
180 // "Translate" more data
181 $content['mails_confirmed'] = translateComma($content['mails_confirmed']);
182 $content['emails_received'] = translateComma($content['emails_received']);
184 // Is the extension 'country' installed?
185 if (isExtensionActive('country')) {
186 // Then overwrite country information
187 $content['country'] = generateCountryInfo($content['country_code']);
188 } elseif ($content['country'] == '0') {
190 $content['country'] = '???';
194 $content['userid'] = $userid;
196 // Load user-details template
197 loadTemplate('admin_user_details', false, $content);
199 // Account does not exist!
200 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_MEMBER_404'), $userid));
204 SQL_FREERESULT($result_user);
206 $whereStatement = '';
207 if ((getRequestElement('letter') != getMessage('_ALL2')) && (getRequestElement('letter') != getMessage('_OTHERS')) && (isGetRequestElementSet('letter'))) {
208 // List only persons w
209 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%'";
212 // Parse the status or mode parameter
213 if (isGetRequestElementSet(('status'))) {
214 // Is a WHERE statement already there?
215 if (!empty($whereStatement)) {
216 // Then append the status column
217 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
220 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
222 } elseif (isGetRequestElementSet('mode')) {
223 // Choose what we need to list
224 switch (getRequestElement('mode')) {
225 case 'norefs': // Users w/o refs
226 if (!empty($whereStatement)) {
228 $whereStatement .= " AND `refid`=0";
230 // Add WHERE statement
231 $whereStatement = " WHERE `refid`=0";
235 default: // Invalid list mode
236 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestElement('mode')));
241 // Generate master query string
242 $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",
243 getRequestElement('sortby')
246 // Prepare SQL and run it
247 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
249 // Calculate page count (0.5 fixes a bug with page count)
250 if (getConfig('user_limit') == '0') {
251 setConfigEntry('user_limit', 100);
252 loadTemplate('admin_settings_saved', false, getMessage('EXTENSION_WARNING_USER_LIMIT'));
255 // Activate the extension please!
256 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
258 if (!isGetRequestElementSet('page')) setRequestGetElement('page' , 1);
259 if (!isGetRequestElementSet('offset')) setRequestGetElement('offset', getConfig('user_limit'));
261 // Add limitation to SQL string and run him again
262 $sql .= " LIMIT ".(getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')).", ".getRequestElement('offset');
263 $result = SQL_QUERY($sql, __FILE__, __LINE__);
265 // Count all confirmed users
266 $user_count = countSumTotalData('CONFIRMED','user_data','userid','status',true);
268 // Are there some entries?
269 if (SQL_NUMROWS($result_master) > 0) {
270 // We have some (new?) registrations!
271 define('__COLSPAN2' , ($colspan + 2));
272 define('__USER_CNT' , $user_count);
275 define('__ALPHA_SORT', alpha(getRequestElement('sortby'), $colspan, true));
276 define('__SORT_LINKS', addSortLinks(getRequestElement('letter'), getRequestElement('sortby'), $colspan, true));
279 define('__PAGE_NAV', addPageNavigation($PAGES, getConfig('user_limit'), true, $colspan, true));
281 // No page navigation is required
282 define('__PAGE_NAV', '');
285 // Column with nickname when nickname extension is present
286 // @TODO Rewrite this into a filter
287 if (isExtensionActive('nickname')) {
288 // Nickname extension found
289 define('__NICKNAME_TH', " <td class=\"header_column bottom\" align=\"center\">{--NICKNAME--}</td>");
292 define('__NICKNAME_TH', '');
297 while ($content = SQL_FETCHARRAY($result)) {
299 if ($content['refid'] > 0) $content['refid'] = generateUserProfileLink($content['refid']);
301 // Get number of unconfirmed mails
302 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
303 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '">' . translateComma($content['links']) . '</a>]';
305 // Set link to sent mails if present
306 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '">' . translateComma($content['emails_sent']) . '</a>]';
309 if ((empty($content['nickname'])) || ($content['nickname'] == $content['userid'])) $content['nickname'] = '---';
311 // Calculate total points
312 $content['points'] = countSumTotalData($content['userid'], 'user_points', 'points') - countSumTotalData($content['userid'], 'user_data', 'used_points');
315 $content['rate'] = '0';
316 if ($content['emails_received'] > 0) {
317 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
320 // Transfer data to array
321 $content['sw'] = $SW;
322 $content['userid_link'] = generateUserProfileLink($content['userid']);
323 $content['gender'] = translateGender($content['gender']);
324 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
325 $content['alinks'] = generateMemberAdminActionLinks($content['userid'], $content['status']);
326 $content['points'] = translateComma($content['points']);
327 $content['rate'] = translateComma($content['rate']);
328 $content['locked'] = translateComma(countSumTotalData($content['userid'], 'user_points', 'locked_points'));
329 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
330 $content['status'] = translateUserStatus($content['status']);
331 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
333 // If we have at least one referal, make it clickable to referal list
334 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '">' . $content['refs'] . '</a>]';
336 // Is the lock reason not set?
337 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
339 // Is the extension 'country' installed?
340 // @TODO Rewrite this into a filter
341 if (isExtensionActive('country')) {
342 // Then overwrite country information
343 $content['country'] = generateCountryInfo($content['country_code']);
344 } elseif ($content['country'] == '') {
346 $content['country'] = '???';
349 // Load row template and switch colors
350 $OUT .= loadTemplate('admin_list_user_row', true, $content);
355 SQL_FREERESULT($result);
358 SQL_FREERESULT($result_master);
361 $content['rows'] = $OUT;
363 // Init title with "all accounts"
364 $content['title'] = getMessage('ADMIN_ALL_ACCOUNTS');
365 if (isGetRequestElementSet(('status'))) {
366 // Set title according to the 'status'
367 $content['title'] = getMessage(sprintf("ADMIN_LIST_STATUS_%s_ACCOUNTS", strtoupper(getRequestElement(('status')))));
368 } elseif (isGetRequestElementSet('mode')) {
369 // Set title according to the "mode"
370 $content['title'] = getMessage(sprintf("ADMIN_LIST_MODE_%s_ACCOUNTS", strtoupper(getRequestElement('mode'))));
373 // Load main template
374 loadTemplate('admin_list_user', false, $content);
376 // No one as registered so far! :-(
377 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_NONE_REGISTERED'));
381 SQL_FREERESULT($result_master);