ca6a77dbd33eeb682b3f506013c01e5b74612b93
[mailer.git] / inc / modules / admin / what-list_user.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 08/18/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif ((!EXT_IS_ACTIVE("user")) || (GET_EXT_VERSION("user") == "")) {
39         // Missing extension!
40         addFatalMessage(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "user"));
41         return;
42 }
43
44 // Add description as navigation point
45 ADD_DESCR("admin", __FILE__);
46
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']))));
55 }
56
57 // Remember it
58 define('__TITLE', $listHeader);
59
60 // Init variables
61 $MORE = ", userid"; $colspan = "4";
62
63 // Add nickname if extension is found&active
64 if (EXT_IS_ACTIVE("nickname")) { $MORE = ", nickname"; }
65
66 // Add random confirmed if extension version matches
67 if (GET_EXT_VERSION("user") >= "0.3.4") {
68         // Add it...
69         $MORE .= ", rand_confirmed";
70
71         // Add lock reason?
72         if (GET_EXT_VERSION("user") >= "0.3.5") {
73                 // Add them...
74                 $MORE .= ", lock_reason, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
75         } // END - if
76 } // END - if
77
78 // Is the extension "country" installed?
79 if (EXT_IS_ACTIVE("country")) {
80         // Add country code
81         $MORE .= ", country_code";
82 } else {
83         // Add direct value
84         $MORE .= ", country";
85 }
86
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";      }
91
92 // Set base URL
93 $BASE = "[<a href=\"{!URL!}/modules.php?module=admin";
94
95 if (!empty($_GET['u_id'])) {
96         // Secure the user ID
97         $uid = bigintval($_GET['u_id']);
98
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`
102 WHERE userid=%s
103 LIMIT 1",
104                 array($uid), __FILE__, __LINE__);
105         if (SQL_NUMROWS($result_user) == 1) {
106                 // Account found!
107                 $DATA  = SQL_FETCHARRAY($result_user);
108
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);
113
114                 // Add links to the numbers
115                 if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;u_id=".$uid."\">".$LINKS."</a>]";
116                 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&amp;what=list_user&amp;u_id=".$DATA['refid']."\">".$DATA['refid']."</a>]";
117                 if (empty($DATA['last_module'])) $DATA['last_module'] = "---";
118                 if ($REFS > 0) $REFS = $BASE."&amp;what=list_refs&amp;u_id=".$uid."\">".$REFS."</a>]";
119                 if ($CATS > 0) $CATS = $BASE."&amp;what=list_cats&amp;u_id=".$uid."\">".$CATS."</a>]";
120
121                 // Calculate timestamp for birthday
122                 $stamp = mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']);
123
124                 // Is this above zero?
125                 if ($stamp > 0) {
126                         // Then use it
127                         define('_BIRTHDAY', MAKE_DATETIME($stamp, "3"));
128                 } else {
129                         // Zero or below so set zero!
130                         define('_BIRTHDAY', MAKE_DATETIME(0, "3"));
131                 }
132
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."&amp;what=email_details&amp;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");
150
151                 // Is the lock reason not set?
152                 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = "---";
153
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'] = "---";
158                 } else {
159                         // Extension not found
160                         $DATA['nickname'] = EXT_NICKNAME_404;
161                 }
162
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']);
167                 } // END - if
168
169                 // Clickrate
170                 $DATA['click_rate'] = 0;
171                 if ($DATA['emails_received'] > 0) {
172                         $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
173                 } // END - if
174
175                 // "Translate" more data
176                 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
177                 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
178
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) {
184                         // Zero ID???
185                         $DATA['country'] = "???";
186                 }
187
188                 // Load user-details template
189                 LOAD_TEMPLATE("admin_user_details", false, $uid);
190         } else {
191                 // Account does not exist!
192                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$uid.ADMIN_MEMBER_404_2);
193         }
194
195         // Free the result
196         SQL_FREERESULT($result_user);
197 } else {
198         $whereStatement = "";
199         if (($_GET['letter'] != getMessage('_ALL2')) && ($_GET['letter'] != getMessage('_OTHERS')) && (!empty($_GET['letter']))) {
200                 // List only persons w
201                 $whereStatement = " WHERE family LIKE '".$_GET['letter']."%'";
202         } // END - if
203         if ($_GET['sortby'] == "family_name") $_GET['sortby'] = "family";
204
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']))));
211                 } else {
212                         // Start a new one
213                         $whereStatement = sprintf(" WHERE status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['status']))));
214                 }
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)) {
220                                         // Add AND statement
221                                         $whereStatement .= " AND refid=0";
222                                 } else {
223                                         // Add WHERE statement
224                                         $whereStatement = " WHERE refid=0";
225                                 }
226                                 break;
227
228                         default: // Invalid list mode
229                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", SQL_ESCAPE($_GET['mode'])));
230                                 break;
231                 }
232         } // END = if
233
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__);
237
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);
242         } // END - if
243
244         // Activate the extension please!
245         $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
246
247         if (empty($_GET['page']))   $_GET['page']   = "1";
248         if (empty($_GET['offset'])) $_GET['offset'] = getConfig('user_limit');
249
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__);
253
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);
257
258         if (SQL_NUMROWS($result_master) > 0) {
259                 // Free memory
260                 SQL_FREERESULT($result_master);
261
262                 // We have some (new?) registrations!
263                 define('__COLSPAN1'  , $colspan);
264                 define('__COLSPAN2'  , ($colspan + 2));
265                 define('__USER_CNT'  , $user_count);
266
267                 // Sorting links
268                 define('__ALPHA_SORT', alpha($_GET['sortby'], $colspan, true));
269                 define('__SORT_LINKS', SortLinks($_GET['letter'], $_GET['sortby'], $colspan, true));
270
271                 if ($PAGES > 1) {
272                         define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
273                 } else {
274                         // No page navigation is required
275                         define('__PAGE_NAV', "");
276                 }
277
278                 // Column with nickname when nickname extension is present
279                 if (EXT_IS_ACTIVE("nickname"))
280                 {
281                         // Nickname extension found
282                         define('__NICKNAME_TH', "  <td class=\"admin_title bottom2\" align=\"center\">".NICKNAME."</td>");
283                 }
284                  else
285                 {
286                         // Not found
287                         define('__NICKNAME_TH', "");
288                 }
289
290                 // Load all users
291                 $SW = 2; $OUT = "";
292                 while ($content = SQL_FETCHARRAY($result)) {
293                         // Set refid link
294                         if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
295
296                         // Get number of unconfirmed mails
297                         $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
298                         if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</a>]";
299
300                         // Set link to sent mails if present
301                         if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&amp;what=email_details&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</a>]";
302
303                         // Add nickname
304                         if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
305
306                         // Calculate total points
307                         $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points")  - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
308
309                         // Clickrate
310                         $clickRate = 0;
311                         if ($content['emails_received'] > 0) {
312                                 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
313                         } // END - if
314
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']);
328
329                         // Is the lock reason not set?
330                         if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
331
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'] == "") {
337                                 // Zero ID???
338                                 $content['country'] = "???";
339                         }
340
341                         // Load row template and switch colors
342                         $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
343                         $SW = 3 - $SW;
344                 } // END - while
345
346                 // Free memory
347                 SQL_FREERESULT($result);
348
349                 define('__USER_ROWS', $OUT);
350
351                 // Load main template
352                 LOAD_TEMPLATE("admin_list_user");
353
354                 // Free some memory
355                 SQL_FREERESULT($result_master);
356         } else {
357                 // No one as registered so far! :-(
358                 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_NO_NONE_REGISTERED'));
359         }
360 }
361
362 //
363 ?>