A lot fixes to templates and missing functions added, more rewrites
[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(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "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 = 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')))));
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 (!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");                 }
91
92 // Set base URL
93 $BASE = "[<a href=\"{!URL!}/modules.php?module=admin";
94
95 if (REQUEST_ISSET_GET(('uid'))) {
96         // Secure the user ID
97         $uid = bigintval(REQUEST_GET('uid'));
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;uid=".$uid."\">".$LINKS."</a>]";
116                 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&amp;what=list_user&amp;uid=".$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;uid=".$uid."\">".$REFS."</a>]";
119                 if ($CATS > 0) $CATS = $BASE."&amp;what=list_cats&amp;uid=".$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;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");
150
151                 // Is the lock reason not set?
152                 if (!isset($DATA['lock_reason'])) $DATA['lock_reason'] = "---";
153
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'] = "---";
159                 } else {
160                         // Extension not found
161                         $DATA['nickname'] = getMessage('EXT_NICKNAME_404');
162                 }
163
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']);
168                 } // END - if
169
170                 // Clickrate
171                 $DATA['click_rate'] = 0;
172                 if ($DATA['emails_received'] > 0) {
173                         $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
174                 } // END - if
175
176                 // "Translate" more data
177                 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
178                 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
179
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) {
185                         // Zero ID???
186                         $DATA['country'] = "???";
187                 }
188
189                 // Load user-details template
190                 LOAD_TEMPLATE("admin_user_details", false, $uid);
191         } else {
192                 // Account does not exist!
193                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_MEMBER_404'), $uid));
194         }
195
196         // Free the result
197         SQL_FREERESULT($result_user);
198 } else {
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')."%'";
203         } // END - if
204         if (REQUEST_GET('sortby') == "family_name") REQUEST_SET_GET('sortby', "family");
205
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')))));
212                 } else {
213                         // Start a new one
214                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(strip_tags(strtoupper(REQUEST_GET('status')))));
215                 }
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)) {
221                                         // Add AND statement
222                                         $whereStatement .= " AND refid=0";
223                                 } else {
224                                         // Add WHERE statement
225                                         $whereStatement = " WHERE refid=0";
226                                 }
227                                 break;
228
229                         default: // Invalid list mode
230                                 DEBUG_LOG(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", REQUEST_GET(('mode'))));
231                                 break;
232                 }
233         } // END = if
234
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__);
238
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'));
243         } // END - if
244
245         // Activate the extension please!
246         $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
247
248         if (!REQUEST_ISSET_GET(('page')))   REQUEST_SET_GET('page'  , "1");
249         if (!REQUEST_ISSET_GET(('offset'))) REQUEST_SET_GET('offset', getConfig('user_limit'));
250
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__);
254
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);
258
259         if (SQL_NUMROWS($result_master) > 0) {
260                 // Free memory
261                 SQL_FREERESULT($result_master);
262
263                 // We have some (new?) registrations!
264                 define('__COLSPAN1'  , $colspan);
265                 define('__COLSPAN2'  , ($colspan + 2));
266                 define('__USER_CNT'  , $user_count);
267
268                 // Sorting links
269                 define('__ALPHA_SORT', alpha(REQUEST_GET('sortby'), $colspan, true));
270                 define('__SORT_LINKS', SortLinks(REQUEST_GET('letter'), REQUEST_GET('sortby'), $colspan, true));
271
272                 if ($PAGES > 1) {
273                         define('__PAGE_NAV', ADD_PAGENAV($PAGES, getConfig('user_limit'), true, $colspan, true));
274                 } else {
275                         // No page navigation is required
276                         define('__PAGE_NAV', "");
277                 }
278
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>");
284                 } else {
285                         // Not found
286                         define('__NICKNAME_TH', "");
287                 }
288
289                 // Load all users
290                 $SW = 2; $OUT = "";
291                 while ($content = SQL_FETCHARRAY($result)) {
292                         // Set refid link
293                         if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
294
295                         // Get number of unconfirmed mails
296                         $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
297                         if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;uid=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</a>]";
298
299                         // Set link to sent mails if present
300                         if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&amp;what=email_details&amp;uid=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</a>]";
301
302                         // Add nickname
303                         if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
304
305                         // Calculate total points
306                         $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points")  - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
307
308                         // Clickrate
309                         $clickRate = 0;
310                         if ($content['emails_received'] > 0) {
311                                 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
312                         } // END - if
313
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']);
327
328                         // Is the lock reason not set?
329                         if (!isset($content['lock_reason'])) $content['lock_reason'] = "---";
330
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'] == "") {
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 ?>