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(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "user"));
44 // Add description as navigation point
45 ADD_DESCR("admin", __FILE__);
47 // Init title with "all accounts"
48 $listHeader = ADMIN_ALL_ACCOUNTS;
49 if (!empty($_GET['status'])) {
50 // Set title according to the "status"
51 $listHeader = constant(sprintf("ADMIN_LIST_STATUS_%s_ACCOUNTS", strtoupper(SQL_ESCAPE($_GET['status']))));
52 } elseif (!empty($_GET['mode'])) {
53 // Set title according to the "mode"
54 $listHeader = constant(sprintf("ADMIN_LIST_MODE_%s_ACCOUNTS", strtoupper(SQL_ESCAPE($_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 (empty($_GET['letter'])) { $_GET['letter'] = _ALL2; }
89 if (empty($_GET['sortby'])) { $_GET['sortby'] = "userid"; }
90 if (empty($_GET['page'])) { $_GET['page'] = "1"; }
93 $BASE = "[<a href=\"".URL."/modules.php?module=admin";
95 if (!empty($_GET['u_id'])) {
97 $uid = bigintval($_GET['u_id']);
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&u_id=".$uid."\">".$LINKS."</a>]";
116 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&what=list_user&u_id=".$DATA['refid']."\">".$DATA['refid']."</a>]";
117 if (empty($DATA['last_module'])) $DATA['last_module'] = "---";
118 if ($REFS > 0) $REFS = $BASE."&what=list_refs&u_id=".$uid."\">".$REFS."</a>]";
119 if ($CATS > 0) $CATS = $BASE."&what=list_cats&u_id=".$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&u_id=".$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 if (EXT_IS_ACTIVE("nickname")) {
156 // Nickname not set or invalid? Then
157 if ((empty($DATA['nickname'])) || ($DATA['nickname'] == $uid)) $DATA['nickname'] = "---";
159 // Extension not found
160 $DATA['nickname'] = EXT_NICKNAME_404;
163 // Is the user extension newer?
164 if (GET_EXT_VERSION("user") >= "0.3.4") {
165 // Then "translate" the number
166 $DATA['rand_confirmed'] = TRANSLATE_COMMA($DATA['rand_confirmed']);
170 $DATA['click_rate'] = 0;
171 if ($DATA['emails_received'] > 0) {
172 $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
175 // "Translate" more data
176 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
177 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
179 // Is the extension "country" installed?
180 if (EXT_IS_ACTIVE("country")) {
181 // Then overwrite country information
182 $DATA['country'] = COUNTRY_GENERATE_INFO($DATA['country_code']);
183 } elseif ($DATA['country'] == 0) {
185 $DATA['country'] = "???";
188 // Load user-details template
189 LOAD_TEMPLATE("admin_user_details", false, $uid);
191 // Account does not exist!
192 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$uid.ADMIN_MEMBER_404_2);
196 SQL_FREERESULT($result_user);
198 $whereStatement = "";
199 if (($_GET['letter'] != _ALL2) && ($_GET['letter'] != _OTHERS) && (!empty($_GET['letter']))) {
200 // List only persons w
201 $whereStatement = " WHERE family LIKE '".$_GET['letter']."%'";
203 if ($_GET['sortby'] == "family_name") $_GET['sortby'] = "family";
205 // Parse the status or mode parameter
206 if (isset($_GET['status'])) {
207 // Is a WHERE statement already there?
208 if (!empty($whereStatement)) {
209 // Then append the status column
210 $whereStatement .= sprintf(" AND status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['status']))));
213 $whereStatement = sprintf(" WHERE status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['status']))));
215 } elseif (isset($_GET['mode'])) {
216 // Choose what we need to list
217 switch ($_GET['mode']) {
218 case "norefs": // Users w/o refs
219 if (!empty($whereStatement)) {
221 $whereStatement .= " AND refid=0";
223 // Add WHERE statement
224 $whereStatement = " WHERE refid=0";
228 default: // Invalid list mode
229 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", SQL_ESCAPE($_GET['mode'])));
234 // Prepare SQL and run it
235 $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 ".SQL_ESCAPE($_GET['sortby']);
236 $result_master = SQL_QUERY($SQL, __FILE__, __LINE__);
238 // Calculate page count (0.5 fixes a bug with page count)
239 if (getConfig('user_limit') == 0) {
240 $_CONFIG['user_limit'] = 100;
241 LOAD_TEMPLATE("admin_settings_saved", false, EXTENSION_WARNING_USER_LIMIT);
244 // Activate the extension please!
245 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
247 if (empty($_GET['page'])) $_GET['page'] = "1";
248 if (empty($_GET['offset'])) $_GET['offset'] = getConfig('user_limit');
250 // Add limitation to SQL string and run him again
251 $SQL .= " LIMIT ".($_GET['offset'] * $_GET['page'] - $_GET['offset']).", ".$_GET['offset'];
252 $result = SQL_QUERY($SQL, __FILE__, __LINE__);
254 $result_user = SQL_QUERY("SELECT emails_sent FROM `"._MYSQL_PREFIX."_user_data` WHERE status='CONFIRMED'", __FILE__, __LINE__);
255 $user_count = SQL_NUMROWS($result_user);
256 SQL_FREERESULT($result_user);
258 if (SQL_NUMROWS($result_master) > 0) {
260 SQL_FREERESULT($result_master);
262 // We have some (new?) registrations!
263 define('__COLSPAN1' , $colspan);
264 define('__COLSPAN2' , ($colspan + 2));
265 define('__USER_CNT' , $user_count);
268 define('__ALPHA_SORT', alpha($_GET['sortby'], $colspan, true));
269 define('__SORT_LINKS', SortLinks($_GET['letter'], $_GET['sortby'], $colspan, true));
272 define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
274 // No page navigation is required
275 define('__PAGE_NAV', "");
278 // Column with nickname when nickname extension is present
279 if (EXT_IS_ACTIVE("nickname"))
281 // Nickname extension found
282 define('__NICKNAME_TH', " <td class=\"admin_title bottom2\" align=\"center\">".NICKNAME."</td>");
287 define('__NICKNAME_TH', "");
292 while ($content = SQL_FETCHARRAY($result)) {
294 if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
296 // Get number of unconfirmed mails
297 $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
298 if ($LINKS > 0) $LINKS = $BASE."&what=list_links&u_id=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</a>]";
300 // Set link to sent mails if present
301 if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&what=email_details&u_id=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</a>]";
304 if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
306 // Calculate total points
307 $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points") - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
311 if ($content['emails_received'] > 0) {
312 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
315 // Transfer data to array
316 $content['sw'] = $SW;
317 $content['uid'] = ADMIN_USER_PROFILE_LINK($content['userid']);
318 $content['gender'] = TRANSLATE_GENDER($content['gender']);
319 $content['email'] = "[<a href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".$content['email']."</a>]";
320 $content['addr'] = $content['REMOTE_ADDR'];
321 $content['links'] = $LINKS;
322 $content['alinks'] = MEMBER_ACTION_LINKS($content['userid'], $content['status']);
323 $content['points'] = TRANSLATE_COMMA($pointsTotal);
324 $content['rate'] = TRANSLATE_COMMA($clickRate);
325 $content['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
326 $content['lock_timestamp'] = MAKE_DATETIME($content['lock_timestamp'], "2");
327 $content['status'] = TRANSLATE_STATUS($content['status']);
329 // Is the lock reason not set?
330 if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
332 // Is the extension "country" installed?
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, ADMIN_NO_NONE_REGISTERED);