2 /************************************************************************
3 * MXChange v0.2.1 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 - 2008 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')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
43 } elseif ((!EXT_IS_ACTIVE('user')) || (GET_EXT_VERSION('user') == '')) {
45 addFatalMessage(__FILE__, __LINE__, generateExtensionInactiveNotInstalledMessage('user'));
49 // Add description as navigation point
50 ADD_DESCR('admin', __FILE__);
52 // Init title with "all accounts"
53 $listHeader = getMessage('ADMIN_ALL_ACCOUNTS');
54 if (REQUEST_ISSET_GET(('status'))) {
55 // Set title according to the 'status'
56 $listHeader = getMessage(sprintf("ADMIN_LIST_STATUS_%s_ACCOUNTS", strtoupper(REQUEST_GET(('status')))));
57 } elseif (REQUEST_ISSET_GET('mode')) {
58 // Set title according to the "mode"
59 $listHeader = getMessage(sprintf("ADMIN_LIST_MODE_%s_ACCOUNTS", strtoupper(REQUEST_GET('mode'))));
63 define('__TITLE', $listHeader);
66 $MORE = ", userid"; $colspan = "4";
68 // Add nickname if extension is found&active
69 if (EXT_IS_ACTIVE('nickname')) { $MORE = ", nickname"; }
71 // Add random confirmed if extension version matches
72 if (GET_EXT_VERSION('user') >= '0.3.4') {
74 $MORE .= ", rand_confirmed";
77 if (GET_EXT_VERSION('user') >= '0.3.5') {
79 $MORE .= ", lock_reason, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
83 // Is the extension 'country' installed?
84 if (EXT_IS_ACTIVE('country')) {
86 $MORE .= ", country_code";
93 if (!REQUEST_ISSET_GET('letter')) { REQUEST_SET_GET('letter', getMessage('_ALL2')); }
94 if (!REQUEST_ISSET_GET('sortby')) { REQUEST_SET_GET('sortby', 'userid'); }
95 if (!REQUEST_ISSET_GET('page')) { REQUEST_SET_GET('page' , '1'); }
98 $base = "[<a href=\"{?URL?}/modules.php?module=admin";
100 if (REQUEST_ISSET_GET('uid')) {
101 // Secure the user ID
102 $uid = bigintval(REQUEST_GET('uid'));
104 // Does the account exists?
105 $result_user = SQL_QUERY_ESC("SELECT 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."
106 FROM `{!_MYSQL_PREFIX!}_user_data`
109 array($uid), __FILE__, __LINE__);
110 if (SQL_NUMROWS($result_user) == 1) {
112 $DATA = SQL_FETCHARRAY($result_user);
114 // Get count/sum of refs, selected categories, unconfirmed mails
115 $REFS = GET_TOTAL_DATA($uid, 'refsystem', 'counter');
116 $CATS = GET_TOTAL_DATA($uid, 'user_cats', 'id', 'userid', true);
117 $LINKS = GET_TOTAL_DATA($uid, 'user_links', 'id', 'userid', true);
119 // Add links to the numbers
120 if ($LINKS > 0) $LINKS = $base."&what=list_links&uid=".$uid."\">".$LINKS."</a>]";
121 if ($DATA['refid'] > 0) $DATA['refid'] = $base."&what=list_user&uid=".$DATA['refid']."\">".$DATA['refid']."</a>]";
122 if (empty($DATA['last_module'])) $DATA['last_module'] = '---';
123 if ($REFS > 0) $REFS = $base."&what=list_refs&uid=".$uid."\">".$REFS."</a>]";
124 if ($CATS > 0) $CATS = $base."&what=list_cats&uid=".$uid."\">".$CATS."</a>]";
126 // Calculate timestamp for birthday
127 $stamp = mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']);
129 // Is this above zero?
132 define('_BIRTHDAY', generateDateTime($stamp, '3'));
134 // Zero or below so set zero!
135 define('_BIRTHDAY', generateDateTime(0, '3'));
138 // Prepare data for template
139 define('_REFS' , $REFS);
140 define('_CATS' , $CATS);
141 define('_LINKS', $LINKS);
142 define('_ADMIN_LINKS', generateMemberAdminActionLinks($uid, $DATA['status']));
143 $DATA['gender'] = translateGender($DATA['gender']);
144 $DATA['email_link'] = generateEmailLink($DATA['email'], 'user_data');
145 $DATA['status'] = translateUserStatus($DATA['status']);
146 $DATA['last_online'] = generateDateTime($DATA['last_online'], '0');
147 $DATA['used_points'] = translateComma($DATA['used_points']);
148 if ($DATA['emails_sent'] > 0) $DATA['emails_sent'] = $base."&what=email_details&uid=".$uid."\">".translateComma($DATA['emails_sent'])."</a>]";
149 $DATA['joined'] = generateDateTime($DATA['joined'], '0');
150 $DATA['last_update'] = generateDateTime($DATA['last_update'], '0');
151 $DATA['last_profile_sent'] = generateDateTime($DATA['last_profile_sent'], '0');
152 $DATA['total'] = translateComma(GET_TOTAL_DATA($uid, 'user_points', 'points'));
153 $DATA['locked'] = translateComma(GET_TOTAL_DATA($uid, 'user_points', 'locked_points'));
154 $DATA['lock_timestamp'] = generateDateTime($DATA['lock_timestamp'], '2');
156 // Is the lock reason not set?
157 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = '---';
159 // Nickname inclusion?
160 // @TODO Rewrite these to filters
161 if (EXT_IS_ACTIVE('nickname')) {
162 // Nickname not set or invalid? Then
163 if ((empty($DATA['nickname'])) || ($DATA['nickname'] == $uid)) $DATA['nickname'] = '---';
165 // Extension not found
166 $DATA['nickname'] = getMessage('EXT_NICKNAME_404');
169 // Is the user extension newer?
170 if (GET_EXT_VERSION('user') >= '0.3.4') {
171 // Then "translate" the number
172 $DATA['rand_confirmed'] = translateComma($DATA['rand_confirmed']);
176 $DATA['click_rate'] = 0;
177 if ($DATA['emails_received'] > 0) {
178 $DATA['click_rate'] = translateComma($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
181 // "Translate" more data
182 $DATA['mails_confirmed'] = translateComma($DATA['mails_confirmed']);
183 $DATA['emails_received'] = translateComma($DATA['emails_received']);
185 // Is the extension 'country' installed?
186 if (EXT_IS_ACTIVE('country')) {
187 // Then overwrite country information
188 $DATA['country'] = COUNTRY_GENERATE_INFO($DATA['country_code']);
189 } elseif ($DATA['country'] == 0) {
191 $DATA['country'] = '???';
194 // Load user-details template
195 LOAD_TEMPLATE('admin_user_details', false, $uid);
197 // Account does not exist!
198 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_MEMBER_404'), $uid));
202 SQL_FREERESULT($result_user);
204 $whereStatement = '';
205 if ((REQUEST_GET('letter') != getMessage('_ALL2')) && (REQUEST_GET('letter') != getMessage('_OTHERS')) && (REQUEST_ISSET_GET('letter'))) {
206 // List only persons w
207 $whereStatement = " WHERE family LIKE '".REQUEST_GET('letter') . "%'";
209 if (REQUEST_GET('sortby') == 'family_name') REQUEST_SET_GET('sortby', 'family');
211 // Parse the status or mode parameter
212 if (REQUEST_ISSET_GET(('status'))) {
213 // Is a WHERE statement already there?
214 if (!empty($whereStatement)) {
215 // Then append the status column
216 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
219 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
221 } elseif (REQUEST_ISSET_GET('mode')) {
222 // Choose what we need to list
223 switch (REQUEST_GET('mode')) {
224 case "norefs": // Users w/o refs
225 if (!empty($whereStatement)) {
227 $whereStatement .= " AND `refid`=0";
229 // Add WHERE statement
230 $whereStatement = " WHERE `refid`=0";
234 default: // Invalid list mode
235 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", REQUEST_GET('mode')));
240 // Generate master query string
241 $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",
242 REQUEST_GET('sortby')
245 // Prepare SQL and run it
246 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
248 // Calculate page count (0.5 fixes a bug with page count)
249 if (getConfig('user_limit') == 0) {
250 setConfigEntry('user_limit', 100);
251 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('EXTENSION_WARNING_USER_LIMIT'));
254 // Activate the extension please!
255 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
257 if (!REQUEST_ISSET_GET('page')) REQUEST_SET_GET('page' , '1');
258 if (!REQUEST_ISSET_GET('offset')) REQUEST_SET_GET('offset', getConfig('user_limit'));
260 // Add limitation to SQL string and run him again
261 $sql .= " LIMIT ".(REQUEST_GET('offset') * REQUEST_GET('page') - REQUEST_GET('offset')).", ".REQUEST_GET('offset');
262 $result = SQL_QUERY($sql, __FILE__, __LINE__);
264 $result_user = SQL_QUERY("SELECT `emails_sent` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED'", __FILE__, __LINE__);
265 $user_count = SQL_NUMROWS($result_user);
266 SQL_FREERESULT($result_user);
268 if (SQL_NUMROWS($result_master) > 0) {
270 SQL_FREERESULT($result_master);
272 // We have some (new?) registrations!
273 define('__COLSPAN1' , $colspan);
274 define('__COLSPAN2' , ($colspan + 2));
275 define('__USER_CNT' , $user_count);
278 define('__ALPHA_SORT', alpha(REQUEST_GET('sortby'), $colspan, true));
279 define('__SORT_LINKS', SortLinks(REQUEST_GET('letter'), REQUEST_GET('sortby'), $colspan, true));
282 define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
284 // No page navigation is required
285 define('__PAGE_NAV', '');
288 // Column with nickname when nickname extension is present
289 // @TODO Rewrite this into a filter
290 if (EXT_IS_ACTIVE('nickname')) {
291 // Nickname extension found
292 define('__NICKNAME_TH', " <td class=\"admin_title bottom2\" align=\"center\">{--NICKNAME--}</td>");
295 define('__NICKNAME_TH', '');
300 while ($content = SQL_FETCHARRAY($result)) {
302 if ($content['refid'] > 0) $content['refid'] = generateUserProfileLink($content['refid']);
304 // Get number of unconfirmed mails
305 $LINKS = GET_TOTAL_DATA($content['userid'], 'user_links', 'id', 'userid', true);
306 if ($LINKS > 0) $LINKS = $base."&what=list_links&uid=".$content['userid']."\">".translateComma($LINKS)."</a>]";
308 // Set link to sent mails if present
309 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base."&what=email_details&uid=".$content['userid']."\">".translateComma($content['emails_sent'])."</a>]";
312 if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = '---';
314 // Calculate total points
315 $pointsTotal = GET_TOTAL_DATA($content['userid'], 'user_points', 'points') - GET_TOTAL_DATA($content['userid'], 'user_data', 'used_points');
319 if ($content['emails_received'] > 0) {
320 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
323 // Transfer data to array
324 $content['sw'] = $SW;
325 $content['uid'] = generateUserProfileLink($content['userid']);
326 $content['gender'] = translateGender($content['gender']);
327 $content['email'] = "[<a href=\"".generateEmailLink($content['email'], 'user_data')."\">".$content['email']."</a>]";
328 $content['addr'] = $content['REMOTE_ADDR'];
329 $content['links'] = $LINKS;
330 $content['alinks'] = generateMemberAdminActionLinks($content['userid'], $content['status']);
331 $content['points'] = translateComma($pointsTotal);
332 $content['rate'] = translateComma($clickRate);
333 $content['locked'] = translateComma(GET_TOTAL_DATA($content['userid'], 'user_points', 'locked_points'));
334 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
335 $content['status'] = translateUserStatus($content['status']);
336 $content['refs'] = 0;
339 $refs = GET_TOTAL_DATA($content['userid'], 'refsystem', 'counter');
340 if ($refs > 0) $content['refs'] = $base."&what=list_refs&uid=".$content['userid']."\">".$refs."</a>]";
342 // Is the lock reason not set?
343 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
345 // Is the extension 'country' installed?
346 // @TODO Rewrite this into a filter
347 if (EXT_IS_ACTIVE('country')) {
348 // Then overwrite country information
349 $content['country'] = COUNTRY_GENERATE_INFO($content['country_code']);
350 } elseif ($content['country'] == '') {
352 $content['country'] = '???';
355 // Load row template and switch colors
356 $OUT .= LOAD_TEMPLATE('admin_list_user_row', true, $content);
361 SQL_FREERESULT($result);
363 define('__USER_ROWS', $OUT);
365 // Load main template
366 LOAD_TEMPLATE('admin_list_user');
369 SQL_FREERESULT($result_master);
371 // No one as registered so far! :-(
372 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_NONE_REGISTERED'));