A lot double-quotes rewritten to single-quotes, some redirect URLs fixed
[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  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
42         require($INC);
43 } elseif ((!EXT_IS_ACTIVE('user')) || (GET_EXT_VERSION('user') == "")) {
44         // Missing extension!
45         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), 'user');
46         return;
47 }
48
49 // Add description as navigation point
50 ADD_DESCR('admin', __FILE__);
51
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')))));
60 }
61
62 // Remember it
63 define('__TITLE', $listHeader);
64
65 // Init variables
66 $MORE = ", userid"; $colspan = "4";
67
68 // Add nickname if extension is found&active
69 if (EXT_IS_ACTIVE('nickname')) { $MORE = ", nickname"; }
70
71 // Add random confirmed if extension version matches
72 if (GET_EXT_VERSION('user') >= '0.3.4') {
73         // Add it...
74         $MORE .= ", rand_confirmed";
75
76         // Add lock reason?
77         if (GET_EXT_VERSION('user') >= '0.3.5') {
78                 // Add them...
79                 $MORE .= ", lock_reason, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
80         } // END - if
81 } // END - if
82
83 // Is the extension 'country' installed?
84 if (EXT_IS_ACTIVE('country')) {
85         // Add country code
86         $MORE .= ", country_code";
87 } else {
88         // Add direct value
89         $MORE .= ", country";
90 }
91
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");                 }
96
97 // Set base URL
98 $BASE = "[<a href=\"{!URL!}/modules.php?module=admin";
99
100 if (REQUEST_ISSET_GET('uid')) {
101         // Secure the user ID
102         $uid = bigintval(REQUEST_GET('uid'));
103
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`
107 WHERE userid=%s
108 LIMIT 1",
109                 array($uid), __FILE__, __LINE__);
110         if (SQL_NUMROWS($result_user) == 1) {
111                 // Account found!
112                 $DATA  = SQL_FETCHARRAY($result_user);
113
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);
118
119                 // Add links to the numbers
120                 if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;uid=".$uid."\">".$LINKS."</a>]";
121                 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&amp;what=list_user&amp;uid=".$DATA['refid']."\">".$DATA['refid']."</a>]";
122                 if (empty($DATA['last_module'])) $DATA['last_module'] = "---";
123                 if ($REFS > 0) $REFS = $BASE."&amp;what=list_refs&amp;uid=".$uid."\">".$REFS."</a>]";
124                 if ($CATS > 0) $CATS = $BASE."&amp;what=list_cats&amp;uid=".$uid."\">".$CATS."</a>]";
125
126                 // Calculate timestamp for birthday
127                 $stamp = mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']);
128
129                 // Is this above zero?
130                 if ($stamp > 0) {
131                         // Then use it
132                         define('_BIRTHDAY', MAKE_DATETIME($stamp, "3"));
133                 } else {
134                         // Zero or below so set zero!
135                         define('_BIRTHDAY', MAKE_DATETIME(0, "3"));
136                 }
137
138                 // Prepare data for template
139                 define('_REFS' , $REFS);
140                 define('_CATS' , $CATS);
141                 define('_LINKS', $LINKS);
142                 define('_ADMIN_LINKS', MEMBER_ACTION_LINKS($uid, $DATA['status']));
143                 $DATA['gender']            = TRANSLATE_GENDER($DATA['gender']);
144                 $DATA['email_link']        = CREATE_EMAIL_LINK($DATA['email'], "user_data");
145                 $DATA['status']            = TRANSLATE_STATUS($DATA['status']);
146                 $DATA['last_online']       = MAKE_DATETIME($DATA['last_online'], "0");
147                 $DATA['used_points']       = TRANSLATE_COMMA($DATA['used_points']);
148                 if ($DATA['emails_sent'] > 0) $DATA['emails_sent'] = $BASE."&amp;what=email_details&amp;uid=".$uid."\">".TRANSLATE_COMMA($DATA['emails_sent'])."</a>]";
149                 $DATA['joined']            = MAKE_DATETIME($DATA['joined'], "0");
150                 $DATA['last_update']       = MAKE_DATETIME($DATA['last_update'], "0");
151                 $DATA['last_profile_sent'] = MAKE_DATETIME($DATA['last_profile_sent'], "0");
152                 $DATA['total']             = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points"));
153                 $DATA['locked']            = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "locked_points"));
154                 $DATA['lock_timestamp']    = MAKE_DATETIME($DATA['lock_timestamp'], "2");
155
156                 // Is the lock reason not set?
157                 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = "---";
158
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'] = "---";
164                 } else {
165                         // Extension not found
166                         $DATA['nickname'] = getMessage('EXT_NICKNAME_404');
167                 }
168
169                 // Is the user extension newer?
170                 if (GET_EXT_VERSION('user') >= '0.3.4') {
171                         // Then "translate" the number
172                         $DATA['rand_confirmed'] = TRANSLATE_COMMA($DATA['rand_confirmed']);
173                 } // END - if
174
175                 // Clickrate
176                 $DATA['click_rate'] = 0;
177                 if ($DATA['emails_received'] > 0) {
178                         $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
179                 } // END - if
180
181                 // "Translate" more data
182                 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
183                 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
184
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) {
190                         // Zero ID???
191                         $DATA['country'] = "???";
192                 }
193
194                 // Load user-details template
195                 LOAD_TEMPLATE("admin_user_details", false, $uid);
196         } else {
197                 // Account does not exist!
198                 LOAD_TEMPLATE('admin_settings_saved', false, sprintf(getMessage('ADMIN_MEMBER_404'), $uid));
199         }
200
201         // Free the result
202         SQL_FREERESULT($result_user);
203 } else {
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')."%'";
208         } // END - if
209         if (REQUEST_GET('sortby') == "family_name") REQUEST_SET_GET('sortby', "family");
210
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')))));
217                 } else {
218                         // Start a new one
219                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
220                 }
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)) {
226                                         // Add AND statement
227                                         $whereStatement .= " AND refid=0";
228                                 } else {
229                                         // Add WHERE statement
230                                         $whereStatement = " WHERE refid=0";
231                                 }
232                                 break;
233
234                         default: // Invalid list mode
235                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", REQUEST_GET(('mode'))));
236                                 break;
237                 }
238         } // END = if
239
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__);
243
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'));
248         } // END - if
249
250         // Activate the extension please!
251         $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
252
253         if (!REQUEST_ISSET_GET('page'))   REQUEST_SET_GET('page'  , "1");
254         if (!REQUEST_ISSET_GET('offset')) REQUEST_SET_GET('offset', getConfig('user_limit'));
255
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__);
259
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);
263
264         if (SQL_NUMROWS($result_master) > 0) {
265                 // Free memory
266                 SQL_FREERESULT($result_master);
267
268                 // We have some (new?) registrations!
269                 define('__COLSPAN1'  , $colspan);
270                 define('__COLSPAN2'  , ($colspan + 2));
271                 define('__USER_CNT'  , $user_count);
272
273                 // Sorting links
274                 define('__ALPHA_SORT', alpha(REQUEST_GET('sortby'), $colspan, true));
275                 define('__SORT_LINKS', SortLinks(REQUEST_GET('letter'), REQUEST_GET('sortby'), $colspan, true));
276
277                 if ($PAGES > 1) {
278                         define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
279                 } else {
280                         // No page navigation is required
281                         define('__PAGE_NAV', '');
282                 }
283
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>");
289                 } else {
290                         // Not found
291                         define('__NICKNAME_TH', '');
292                 }
293
294                 // Load all users
295                 $OUT = ''; $SW = 2;
296                 while ($content = SQL_FETCHARRAY($result)) {
297                         // Set refid link
298                         if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
299
300                         // Get number of unconfirmed mails
301                         $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", 'userid', true);
302                         if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;uid=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</a>]";
303
304                         // Set link to sent mails if present
305                         if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&amp;what=email_details&amp;uid=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</a>]";
306
307                         // Add nickname
308                         if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
309
310                         // Calculate total points
311                         $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points")  - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
312
313                         // Clickrate
314                         $clickRate = 0;
315                         if ($content['emails_received'] > 0) {
316                                 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
317                         } // END - if
318
319                         // Transfer data to array
320                         $content['sw']     = $SW;
321                         $content['uid']    = ADMIN_USER_PROFILE_LINK($content['userid']);
322                         $content['gender'] = TRANSLATE_GENDER($content['gender']);
323                         $content['email']  = "[<a href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".$content['email']."</a>]";
324                         $content['addr']   = $content['REMOTE_ADDR'];
325                         $content['links']  = $LINKS;
326                         $content['alinks'] = MEMBER_ACTION_LINKS($content['userid'], $content['status']);
327                         $content['points'] = TRANSLATE_COMMA($pointsTotal);
328                         $content['rate']   = TRANSLATE_COMMA($clickRate);
329                         $content['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
330                         $content['lock_timestamp'] = MAKE_DATETIME($content['lock_timestamp'], "2");
331                         $content['status'] = TRANSLATE_STATUS($content['status']);
332
333                         // Is the lock reason not set?
334                         if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
335
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'] == "") {
342                                 // Zero ID???
343                                 $content['country'] = "???";
344                         }
345
346                         // Load row template and switch colors
347                         $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
348                         $SW = 3 - $SW;
349                 } // END - while
350
351                 // Free memory
352                 SQL_FREERESULT($result);
353
354                 define('__USER_ROWS', $OUT);
355
356                 // Load main template
357                 LOAD_TEMPLATE("admin_list_user");
358
359                 // Free some memory
360                 SQL_FREERESULT($result_master);
361         } else {
362                 // No one as registered so far! :-(
363                 LOAD_TEMPLATE('admin_settings_saved', false, getMessage('ADMIN_NO_NONE_REGISTERED'));
364         }
365 }
366
367 //
368 ?>