7aac557d3a2620223daec4f273047409231a1589
[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         ADD_FATAL(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                 // Prepare data for template
122                 define('_BIRTHDAY', MAKE_DATETIME(mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']), "3"));
123                 define('_REFS' , $REFS);
124                 define('_CATS' , $CATS);
125                 define('_LINKS', $LINKS);
126                 define('_ADMIN_LINKS', MEMBER_ACTION_LINKS($uid, $DATA['status']));
127                 $DATA['gender']            = TRANSLATE_GENDER($DATA['gender']);
128                 $DATA['email_link']        = CREATE_EMAIL_LINK($DATA['email'], "user_data");
129                 $DATA['status']            = TRANSLATE_STATUS($DATA['status']);
130                 $DATA['last_online']       = MAKE_DATETIME($DATA['last_online'], "0");
131                 $DATA['used_points']       = TRANSLATE_COMMA($DATA['used_points']);
132                 if ($DATA['emails_sent'] > 0) $DATA['emails_sent'] = $BASE."&amp;what=email_details&amp;u_id=".$uid."\">".TRANSLATE_COMMA($DATA['emails_sent'])."</A>]";
133                 $DATA['joined']            = MAKE_DATETIME($DATA['joined'], "0");
134                 $DATA['last_update']       = MAKE_DATETIME($DATA['last_update'], "0");
135                 $DATA['last_profile_sent'] = MAKE_DATETIME($DATA['last_profile_sent'], "0");
136                 $DATA['total']             = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points"));
137                 $DATA['locked']            = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "locked_points"));
138                 $DATA['lock_timestamp']    = MAKE_DATETIME($DATA['lock_timestamp'], "2");
139
140                 // Is the lock reason not set?
141                 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = "---";
142
143                 // Nickname inclusion?
144                 if (EXT_IS_ACTIVE("nickname")) {
145                         // Nickname not set or invalid? Then 
146                         if ((empty($DATA['nickname'])) || ($DATA['nickname'] == $uid)) $DATA['nickname'] = "---";
147                 } else {
148                         // Extension not found
149                         $DATA['nickname'] = EXT_NICKNAME_404;
150                 }
151
152                 // Is the user extension newer?
153                 if (GET_EXT_VERSION("user") >= "0.3.4") {
154                         // Then "translate" the number
155                         $DATA['rand_confirmed'] = TRANSLATE_COMMA($DATA['rand_confirmed']);
156                 } // END - if
157
158                 // Clickrate
159                 $DATA['click_rate'] = 0;
160                 if ($DATA['emails_received'] > 0) {
161                         $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
162                 } // END - if
163
164                 // "Translate" more data
165                 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
166                 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
167
168                 // Is the extension "country" installed?
169                 if (EXT_IS_ACTIVE("country")) {
170                         // Then overwrite country information
171                         $DATA['country'] = COUNTRY_GENERATE_INFO($DATA['country_code']);
172                 } elseif ($DATA['country'] == 0) {
173                         // Zero ID???
174                         $DATA['country'] = "???";
175                 }
176
177                 // Load user-details template
178                 LOAD_TEMPLATE("admin_user_details", false, $uid);
179         } else {
180                 // Account does not exist!
181                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$uid.ADMIN_MEMBER_404_2);
182         }
183
184         // Free the result
185         SQL_FREERESULT($result_user);
186 } else {
187         $whereStatement = "";
188         if (($_GET['letter'] != _ALL2) && ($_GET['letter'] != _OTHERS) && (!empty($_GET['letter']))) {
189                 // List only persons w
190                 $whereStatement = " WHERE family LIKE '".$_GET['letter']."%'";
191         } // END - if
192         if ($_GET['sortby'] == "family_name") $_GET['sortby'] = "family";
193
194         // Parse the status or mode parameter
195         if (isset($_GET['status'])) {
196                 // Is a WHERE statement already there?
197                 if (!empty($whereStatement)) {
198                         // Then append the status column
199                         $whereStatement .= sprintf(" AND status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['status']))));
200                 } else {
201                         // Start a new one
202                         $whereStatement = sprintf(" WHERE status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['status']))));
203                 }
204         } elseif (isset($_GET['mode'])) {
205                 // Choose what we need to list
206                 switch ($_GET['mode']) {
207                         case "norefs": // Users w/o refs
208                                 if (!empty($whereStatement)) {
209                                         // Add AND statement
210                                         $whereStatement .= " AND refid=0";
211                                 } else {
212                                         // Add WHERE statement
213                                         $whereStatement = " WHERE refid=0";
214                                 }
215                                 break;
216
217                         default: // Invalid list mode
218                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", SQL_ESCAPE($_GET['mode'])));
219                                 break;
220                 }
221         } // END = if
222
223         // Prepare SQL and run it
224         $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']);
225         $result_master = SQL_QUERY($SQL, __FILE__, __LINE__);
226
227         // Calculate page count (0.5 fixes a bug with page count)
228         if (getConfig('user_limit') == 0) {
229                 $_CONFIG['user_limit'] = 100;
230                 LOAD_TEMPLATE("admin_settings_saved", false, EXTENSION_WARNING_USER_LIMIT);
231         } // END - if
232
233         // Activate the extension please!
234         $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
235
236         if (empty($_GET['page']))   $_GET['page']   = "1";
237         if (empty($_GET['offset'])) $_GET['offset'] = getConfig('user_limit');
238
239         // Add limitation to SQL string and run him again
240         $SQL .= " LIMIT ".($_GET['offset'] * $_GET['page'] - $_GET['offset']).", ".$_GET['offset'];
241         $result = SQL_QUERY($SQL, __FILE__, __LINE__);
242
243         $result_user = SQL_QUERY("SELECT emails_sent FROM `"._MYSQL_PREFIX."_user_data` WHERE status='CONFIRMED'", __FILE__, __LINE__);
244         $user_count = SQL_NUMROWS($result_user);
245         SQL_FREERESULT($result_user);
246
247         if (SQL_NUMROWS($result_master) > 0) {
248                 // Free memory
249                 SQL_FREERESULT($result_master);
250
251                 // We have some (new?) registrations!
252                 define('__COLSPAN1'  , $colspan);
253                 define('__COLSPAN2'  , ($colspan + 2));
254                 define('__USER_CNT'  , $user_count);
255
256                 if ((function_exists('alpha')) && (function_exists('SortLinks'))) {
257                         define('__ALPHA_SORT', alpha($_GET['sortby'], $colspan, true));
258                         define('__SORT_LINKS', SortLinks($_GET['letter'], $_GET['sortby'], $colspan, true));
259                 } else {
260                         define('__ALPHA_SORT', "");
261                         define('__SORT_LINKS', "");
262                 }
263
264                 if ($PAGES > 1) {
265                         define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
266                 } else {
267                         // No page navigation is required
268                         define('__PAGE_NAV', "");
269                 }
270
271                 // Column with nickname when nickname extension is present
272                 if (EXT_IS_ACTIVE("nickname"))
273                 {
274                         // Nickname extension found
275                         define('__NICKNAME_TH', "  <TD class=\"admin_title bottom2\" align=\"center\">".NICKNAME."</TD>");
276                 }
277                  else
278                 {
279                         // Not found
280                         define('__NICKNAME_TH', "");
281                 }
282
283                 // Load all users
284                 $SW = 2; $OUT = "";
285                 while ($content = SQL_FETCHARRAY($result)) {
286                         // Set refid link
287                         if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
288
289                         // Get number of unconfirmed mails
290                         $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
291                         if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</A>]";
292
293                         // Set link to sent mails if present
294                         if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&amp;what=email_details&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</A>]";
295
296                         // Add nickname
297                         if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
298
299                         // Calculate total points
300                         $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points")  - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
301
302                         // Clickrate
303                         $clickRate = 0;
304                         if ($content['emails_received'] > 0) {
305                                 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
306                         } // END - if
307
308                         // Transfer data to array
309                         $content['sw']     = $SW;
310                         $content['uid']    = ADMIN_USER_PROFILE_LINK($content['userid']);
311                         $content['gender'] = TRANSLATE_GENDER($content['gender']);
312                         $content['email']  = "[<A href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".$content['email']."</A>]";
313                         $content['addr']   = $content['REMOTE_ADDR'];
314                         $content['links']  = $LINKS;
315                         $content['alinks'] = MEMBER_ACTION_LINKS($content['userid'], $content['status']);
316                         $content['points'] = TRANSLATE_COMMA($pointsTotal);
317                         $content['rate']   = TRANSLATE_COMMA($clickRate);
318                         $content['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
319                         $content['lock_timestamp'] = MAKE_DATETIME($content['lock_timestamp'], "2");
320                         $content['status'] = TRANSLATE_STATUS($content['status']);
321
322                         // Is the lock reason not set?
323                         if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
324
325                         // Is the extension "country" installed?
326                         if (EXT_IS_ACTIVE("country")) {
327                                 // Then overwrite country information
328                                 $content['country'] = COUNTRY_GENERATE_INFO($content['country_code']);
329                         } elseif ($content['country'] == "") {
330                                 // Zero ID???
331                                 $content['country'] = "???";
332                         }
333
334                         // Load row template and switch colors
335                         $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
336                         $SW = 3 - $SW;
337                 } // END - while
338
339                 // Free memory
340                 SQL_FREERESULT($result);
341
342                 define('__USER_ROWS', $OUT);
343
344                 // Load main template
345                 LOAD_TEMPLATE("admin_list_user");
346
347                 // Free some memory
348                 SQL_FREERESULT($result_master);
349         } else {
350                 // No one as registered so far! :-(
351                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_NONE_REGISTERED);
352         }
353 }
354
355 //
356 ?>