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__, sprintf(getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), '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";
92 // Init unset data (bad that we change $_GET here!)
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'] = generateMemberEmailLink($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 // Prepare SQL and run it
241 $sql = "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 ".REQUEST_GET(('sortby'));
242 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
244 // Calculate page count (0.5 fixes a bug with page count)
245 if (getConfig('user_limit') == 0) {
246 setConfigEntry('user_limit', 100);
247 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('EXTENSION_WARNING_USER_LIMIT'));
250 // Activate the extension please!
251 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
253 if (!REQUEST_ISSET_GET('page')) REQUEST_SET_GET('page' , '1');
254 if (!REQUEST_ISSET_GET('offset')) REQUEST_SET_GET('offset', getConfig('user_limit'));
256 // Add limitation to SQL string and run him again
257 $sql .= " LIMIT ".(REQUEST_GET('offset') * REQUEST_GET('page') - REQUEST_GET('offset')).", ".REQUEST_GET('offset');
258 $result = SQL_QUERY($sql, __FILE__, __LINE__);
260 $result_user = SQL_QUERY("SELECT emails_sent FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED'", __FILE__, __LINE__);
261 $user_count = SQL_NUMROWS($result_user);
262 SQL_FREERESULT($result_user);
264 if (SQL_NUMROWS($result_master) > 0) {
266 SQL_FREERESULT($result_master);
268 // We have some (new?) registrations!
269 define('__COLSPAN1' , $colspan);
270 define('__COLSPAN2' , ($colspan + 2));
271 define('__USER_CNT' , $user_count);
274 define('__ALPHA_SORT', alpha(REQUEST_GET('sortby'), $colspan, true));
275 define('__SORT_LINKS', SortLinks(REQUEST_GET('letter'), REQUEST_GET('sortby'), $colspan, true));
278 define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
280 // No page navigation is required
281 define('__PAGE_NAV', '');
284 // Column with nickname when nickname extension is present
285 // @TODO Rewrite this into a filter
286 if (EXT_IS_ACTIVE('nickname')) {
287 // Nickname extension found
288 define('__NICKNAME_TH', " <td class=\"admin_title bottom2\" align=\"center\">{--NICKNAME--}</td>");
291 define('__NICKNAME_TH', '');
296 while ($content = SQL_FETCHARRAY($result)) {
298 if ($content['refid'] > 0) $content['refid'] = generateUserProfileLink($content['refid']);
300 // Get number of unconfirmed mails
301 $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", 'id', 'userid', true);
302 if ($LINKS > 0) $LINKS = $base."&what=list_links&uid=".$content['userid']."\">".translateComma($LINKS)."</a>]";
304 // Set link to sent mails if present
305 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base."&what=email_details&uid=".$content['userid']."\">".translateComma($content['emails_sent'])."</a>]";
308 if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = '---';
310 // Calculate total points
311 $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points") - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
315 if ($content['emails_received'] > 0) {
316 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
319 // Transfer data to array
320 $content['sw'] = $SW;
321 $content['uid'] = generateUserProfileLink($content['userid']);
322 $content['gender'] = translateGender($content['gender']);
323 $content['email'] = "[<a href=\"".generateMemberEmailLink($content['email'], "user_data")."\">".$content['email']."</a>]";
324 $content['addr'] = $content['REMOTE_ADDR'];
325 $content['links'] = $LINKS;
326 $content['alinks'] = generateMemberAdminActionLinks($content['userid'], $content['status']);
327 $content['points'] = translateComma($pointsTotal);
328 $content['rate'] = translateComma($clickRate);
329 $content['locked'] = translateComma(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
330 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
331 $content['status'] = translateUserStatus($content['status']);
333 // Is the lock reason not set?
334 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
336 // Is the extension 'country' installed?
337 // @TODO Rewrite this into a filter
338 if (EXT_IS_ACTIVE('country')) {
339 // Then overwrite country information
340 $content['country'] = COUNTRY_GENERATE_INFO($content['country_code']);
341 } elseif ($content['country'] == '') {
343 $content['country'] = '???';
346 // Load row template and switch colors
347 $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
352 SQL_FREERESULT($result);
354 define('__USER_ROWS', $OUT);
356 // Load main template
357 LOAD_TEMPLATE("admin_list_user");
360 SQL_FREERESULT($result_master);
362 // No one as registered so far! :-(
363 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_NONE_REGISTERED'));