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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38 } elseif ((!EXT_IS_ACTIVE("user")) || (GET_EXT_VERSION("user") == "")) {
40 addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "user");
44 // Add description as navigation point
45 ADD_DESCR("admin", __FILE__);
47 // Init title with "all accounts"
48 $listHeader = getMessage('ADMIN_ALL_ACCOUNTS');
49 if (REQUEST_ISSET_GET(('status'))) {
50 // Set title according to the "status"
51 $listHeader = getMessage(sprintf("ADMIN_LIST_STATUS_%s_ACCOUNTS", strtoupper(REQUEST_GET(('status')))));
52 } elseif (REQUEST_ISSET_GET(('mode'))) {
53 // Set title according to the "mode"
54 $listHeader = getMessage(sprintf("ADMIN_LIST_MODE_%s_ACCOUNTS", strtoupper(REQUEST_GET(('mode')))));
58 define('__TITLE', $listHeader);
61 $MORE = ", userid"; $colspan = "4";
63 // Add nickname if extension is found&active
64 if (EXT_IS_ACTIVE("nickname")) { $MORE = ", nickname"; }
66 // Add random confirmed if extension version matches
67 if (GET_EXT_VERSION("user") >= "0.3.4") {
69 $MORE .= ", rand_confirmed";
72 if (GET_EXT_VERSION("user") >= "0.3.5") {
74 $MORE .= ", lock_reason, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
78 // Is the extension "country" installed?
79 if (EXT_IS_ACTIVE("country")) {
81 $MORE .= ", country_code";
87 // Init unset data (bad that we change $_GET here!)
88 if (!REQUEST_ISSET_GET(('letter'))) { REQUEST_SET_GET('letter', getMessage('_ALL2')); }
89 if (!REQUEST_ISSET_GET(('sortby'))) { REQUEST_SET_GET('sortby', "userid"); }
90 if (!REQUEST_ISSET_GET(('page'))) { REQUEST_SET_GET('page' , "1"); }
93 $BASE = "[<a href=\"{!URL!}/modules.php?module=admin";
95 if (REQUEST_ISSET_GET(('uid'))) {
97 $uid = bigintval(REQUEST_GET('uid'));
99 // Does the account exists?
100 $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."
101 FROM `{!_MYSQL_PREFIX!}_user_data`
104 array($uid), __FILE__, __LINE__);
105 if (SQL_NUMROWS($result_user) == 1) {
107 $DATA = SQL_FETCHARRAY($result_user);
109 // Get count/sum of refs, selected categories, unconfirmed mails
110 $REFS = GET_TOTAL_DATA($uid, "refsystem", "counter");
111 $CATS = GET_TOTAL_DATA($uid, "user_cats", "id", "userid", true);
112 $LINKS = GET_TOTAL_DATA($uid, "user_links", "id", "userid", true);
114 // Add links to the numbers
115 if ($LINKS > 0) $LINKS = $BASE."&what=list_links&uid=".$uid."\">".$LINKS."</a>]";
116 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&what=list_user&uid=".$DATA['refid']."\">".$DATA['refid']."</a>]";
117 if (empty($DATA['last_module'])) $DATA['last_module'] = "---";
118 if ($REFS > 0) $REFS = $BASE."&what=list_refs&uid=".$uid."\">".$REFS."</a>]";
119 if ($CATS > 0) $CATS = $BASE."&what=list_cats&uid=".$uid."\">".$CATS."</a>]";
121 // Calculate timestamp for birthday
122 $stamp = mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']);
124 // Is this above zero?
127 define('_BIRTHDAY', MAKE_DATETIME($stamp, "3"));
129 // Zero or below so set zero!
130 define('_BIRTHDAY', MAKE_DATETIME(0, "3"));
133 // Prepare data for template
134 define('_REFS' , $REFS);
135 define('_CATS' , $CATS);
136 define('_LINKS', $LINKS);
137 define('_ADMIN_LINKS', MEMBER_ACTION_LINKS($uid, $DATA['status']));
138 $DATA['gender'] = TRANSLATE_GENDER($DATA['gender']);
139 $DATA['email_link'] = CREATE_EMAIL_LINK($DATA['email'], "user_data");
140 $DATA['status'] = TRANSLATE_STATUS($DATA['status']);
141 $DATA['last_online'] = MAKE_DATETIME($DATA['last_online'], "0");
142 $DATA['used_points'] = TRANSLATE_COMMA($DATA['used_points']);
143 if ($DATA['emails_sent'] > 0) $DATA['emails_sent'] = $BASE."&what=email_details&uid=".$uid."\">".TRANSLATE_COMMA($DATA['emails_sent'])."</a>]";
144 $DATA['joined'] = MAKE_DATETIME($DATA['joined'], "0");
145 $DATA['last_update'] = MAKE_DATETIME($DATA['last_update'], "0");
146 $DATA['last_profile_sent'] = MAKE_DATETIME($DATA['last_profile_sent'], "0");
147 $DATA['total'] = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points"));
148 $DATA['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "locked_points"));
149 $DATA['lock_timestamp'] = MAKE_DATETIME($DATA['lock_timestamp'], "2");
151 // Is the lock reason not set?
152 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = "---";
154 // Nickname inclusion?
155 // @TODO Rewrite these to filters
156 if (EXT_IS_ACTIVE("nickname")) {
157 // Nickname not set or invalid? Then
158 if ((empty($DATA['nickname'])) || ($DATA['nickname'] == $uid)) $DATA['nickname'] = "---";
160 // Extension not found
161 $DATA['nickname'] = getMessage('EXT_NICKNAME_404');
164 // Is the user extension newer?
165 if (GET_EXT_VERSION("user") >= "0.3.4") {
166 // Then "translate" the number
167 $DATA['rand_confirmed'] = TRANSLATE_COMMA($DATA['rand_confirmed']);
171 $DATA['click_rate'] = 0;
172 if ($DATA['emails_received'] > 0) {
173 $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
176 // "Translate" more data
177 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
178 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
180 // Is the extension "country" installed?
181 if (EXT_IS_ACTIVE("country")) {
182 // Then overwrite country information
183 $DATA['country'] = COUNTRY_GENERATE_INFO($DATA['country_code']);
184 } elseif ($DATA['country'] == 0) {
186 $DATA['country'] = "???";
189 // Load user-details template
190 LOAD_TEMPLATE("admin_user_details", false, $uid);
192 // Account does not exist!
193 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_MEMBER_404'), $uid));
197 SQL_FREERESULT($result_user);
199 $whereStatement = "";
200 if ((REQUEST_GET('letter') != getMessage('_ALL2')) && (REQUEST_GET('letter') != getMessage('_OTHERS')) && (REQUEST_ISSET_GET(('letter')))) {
201 // List only persons w
202 $whereStatement = " WHERE family LIKE '".REQUEST_GET('letter')."%'";
204 if (REQUEST_GET('sortby') == "family_name") REQUEST_SET_GET('sortby', "family");
206 // Parse the status or mode parameter
207 if (REQUEST_ISSET_GET(('status'))) {
208 // Is a WHERE statement already there?
209 if (!empty($whereStatement)) {
210 // Then append the status column
211 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
214 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
216 } elseif (REQUEST_ISSET_GET(('mode'))) {
217 // Choose what we need to list
218 switch (REQUEST_GET('mode')) {
219 case "norefs": // Users w/o refs
220 if (!empty($whereStatement)) {
222 $whereStatement .= " AND refid=0";
224 // Add WHERE statement
225 $whereStatement = " WHERE refid=0";
229 default: // Invalid list mode
230 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", REQUEST_GET(('mode'))));
235 // Prepare SQL and run it
236 $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'));
237 $result_master = SQL_QUERY($SQL, __FILE__, __LINE__);
239 // Calculate page count (0.5 fixes a bug with page count)
240 if (getConfig('user_limit') == 0) {
241 setConfigEntry('user_limit', 100);
242 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('EXTENSION_WARNING_USER_LIMIT'));
245 // Activate the extension please!
246 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
248 if (!REQUEST_ISSET_GET(('page'))) REQUEST_SET_GET('page' , "1");
249 if (!REQUEST_ISSET_GET(('offset'))) REQUEST_SET_GET('offset', getConfig('user_limit'));
251 // Add limitation to SQL string and run him again
252 $SQL .= " LIMIT ".(REQUEST_GET('offset') * REQUEST_GET('page') - REQUEST_GET('offset')).", ".REQUEST_GET('offset');
253 $result = SQL_QUERY($SQL, __FILE__, __LINE__);
255 $result_user = SQL_QUERY("SELECT emails_sent FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `status`='CONFIRMED'", __FILE__, __LINE__);
256 $user_count = SQL_NUMROWS($result_user);
257 SQL_FREERESULT($result_user);
259 if (SQL_NUMROWS($result_master) > 0) {
261 SQL_FREERESULT($result_master);
263 // We have some (new?) registrations!
264 define('__COLSPAN1' , $colspan);
265 define('__COLSPAN2' , ($colspan + 2));
266 define('__USER_CNT' , $user_count);
269 define('__ALPHA_SORT', alpha(REQUEST_GET('sortby'), $colspan, true));
270 define('__SORT_LINKS', SortLinks(REQUEST_GET('letter'), REQUEST_GET('sortby'), $colspan, true));
273 define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
275 // No page navigation is required
276 define('__PAGE_NAV', "");
279 // Column with nickname when nickname extension is present
280 // @TODO Rewrite this into a filter
281 if (EXT_IS_ACTIVE("nickname")) {
282 // Nickname extension found
283 define('__NICKNAME_TH', " <td class=\"admin_title bottom2\" align=\"center\">{--NICKNAME--}</td>");
286 define('__NICKNAME_TH', "");
291 while ($content = SQL_FETCHARRAY($result)) {
293 if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
295 // Get number of unconfirmed mails
296 $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
297 if ($LINKS > 0) $LINKS = $BASE."&what=list_links&uid=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</a>]";
299 // Set link to sent mails if present
300 if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&what=email_details&uid=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</a>]";
303 if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
305 // Calculate total points
306 $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points") - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
310 if ($content['emails_received'] > 0) {
311 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
314 // Transfer data to array
315 $content['sw'] = $SW;
316 $content['uid'] = ADMIN_USER_PROFILE_LINK($content['userid']);
317 $content['gender'] = TRANSLATE_GENDER($content['gender']);
318 $content['email'] = "[<a href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".$content['email']."</a>]";
319 $content['addr'] = $content['REMOTE_ADDR'];
320 $content['links'] = $LINKS;
321 $content['alinks'] = MEMBER_ACTION_LINKS($content['userid'], $content['status']);
322 $content['points'] = TRANSLATE_COMMA($pointsTotal);
323 $content['rate'] = TRANSLATE_COMMA($clickRate);
324 $content['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
325 $content['lock_timestamp'] = MAKE_DATETIME($content['lock_timestamp'], "2");
326 $content['status'] = TRANSLATE_STATUS($content['status']);
328 // Is the lock reason not set?
329 if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
331 // Is the extension "country" installed?
332 // @TODO Rewrite this into a filter
333 if (EXT_IS_ACTIVE("country")) {
334 // Then overwrite country information
335 $content['country'] = COUNTRY_GENERATE_INFO($content['country_code']);
336 } elseif ($content['country'] == "") {
338 $content['country'] = "???";
341 // Load row template and switch colors
342 $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
347 SQL_FREERESULT($result);
349 define('__USER_ROWS', $OUT);
351 // Load main template
352 LOAD_TEMPLATE("admin_list_user");
355 SQL_FREERESULT($result_master);
357 // No one as registered so far! :-(
358 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_NONE_REGISTERED'));