Introduced template call-back function 'doTemplateAdminListUserTitle':
[mailer.git] / inc / modules / admin / what-list_user.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if ((!isExtensionInstalled('user')) || (!isExtensionActive('user'))) {
47         // Missing extension!
48         displayMessage(generateExtensionInactiveNotInstalledMessage('user'));
49         return;
50 } // END - if
51
52 // Init variables
53 $MORE = '';
54 $colspan = 4;
55
56 // Add nickname if extension is found&active
57 // @TODO Rewrite these if-blocks in a filter
58 if (isExtensionActive('nickname')) {
59         // Add nickname
60         $MORE .= ", `nickname`";
61 } else {
62         $MORE .= ", `userid`";
63 }
64
65 // Add random confirmed if extension version matches
66 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
67         // Add it...
68         $MORE .= ", `rand_confirmed`";
69
70         // Add lock reason?
71         if (isExtensionInstalledAndNewer('user', '0.3.5')) {
72                 // Add them...
73                 $MORE .= ", `lock_reason`, UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`";
74         } // END - if
75 } // END - if
76
77 // Is the extension 'country' installed?
78 if (isExtensionActive('country')) {
79         // Add country code
80         $MORE .= ", `country_code`";
81 } else {
82         // Add direct value
83         $MORE .= ", `country`";
84 }
85
86 // Init unset data
87 if (!isGetRequestParameterSet('letter')) { setGetRequestParameter('letter', '');       }
88 if (!isGetRequestParameterSet('sortby')) { setGetRequestParameter('sortby', 'userid'); }
89 if (!isGetRequestParameterSet('page'))   { setGetRequestParameter('page'  , 1);        }
90
91 // Set base URL
92 $base = '[<a href="{%url=modules.php?module=admin';
93
94 if (isGetRequestParameterSet('userid')) {
95         // Secure the user id
96         $userid = bigintval(getRequestParameter('userid'));
97
98         // Does the account exists?
99         $result_user = SQL_QUERY_ESC("SELECT
100         `userid`, `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
102         `{?_MYSQL_PREFIX?}_user_data`
103 WHERE
104         `userid`=%s
105 LIMIT 1",
106                 array($userid), __FILE__, __LINE__);
107
108         // User found?
109         if (SQL_NUMROWS($result_user) == 1) {
110                 // Account found
111                 $content  = SQL_FETCHARRAY($result_user);
112
113                 // Get count/sum of refs, selected categories, unconfirmed mails
114                 $content['refs']  = countSumTotalData($userid, 'refsystem' , 'counter');
115                 $content['cats']  = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
116                 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
117
118                 // Add links to the numbers
119                 if ($content['links'] > 0) $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $userid . '%}">' . $content['links'] . '</a>]';
120                 if (isValidUserId($content['refid'])) $content['refid'] = $base . '&amp;what=list_user&amp;userid=' . $content['refid'] . '%}">'.$content['refid'] . '</a>]';
121                 if ($content['refs']  > 0) $content['refs']  = $base . '&amp;what=list_refs&amp;userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
122                 if ($content['cats']  > 0) $content['cats']  = $base . '&amp;what=list_cats&amp;userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
123
124                 // Calculate timestamp for birthday
125                 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
126
127                 // Is this above zero?
128                 if ($stamp > 0) {
129                         // Then use it
130                         $content['birthday'] = generateDateTime($stamp, 3);
131                 } else {
132                         // Zero or below so set zero!
133                         $content['birthday'] = generateDateTime(0, 3);
134                 }
135
136                 // Prepare data for template
137                 $content['email_link']        = generateEmailLink($content['email'], 'user_data');
138                 $content['last_online']       = generateDateTime($content['last_online'], 0);
139                 $content['joined']            = generateDateTime($content['joined'], 0);
140                 $content['last_update']       = generateDateTime($content['last_update'], 0);
141                 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
142                 $content['total']             = countSumTotalData($userid, 'user_points', 'points');
143                 $content['locked']            = countSumTotalData($userid, 'user_points', 'locked_points');
144                 $content['lock_timestamp']    = generateDateTime($content['lock_timestamp'], 2);
145                 $content['nickname']          = '{--EXT_NICKNAME_404--}';
146
147                 // Link to email_details if some are sent
148                 if ($content['emails_sent'] > 0) {
149                         $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $userid . '%}">}{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
150                 } // END - if
151
152                 // Nickname inclusion?
153                 // @TODO Rewrite these to filters
154                 if (isExtensionInstalled('nickname')) {
155                         $content['nickname'] = getNickname($content['userid']);
156                 } // END - if
157
158                 // Clickrate
159                 $content['click_rate'] = '0';
160                 if ($content['emails_received'] > 0) {
161                         $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
162                 } // END - if
163
164                 // Is the extension 'country' installed?
165                 if (isExtensionActive('country')) {
166                         // Then overwrite country information
167                         $content['country'] = generateCountryInfo($content['country_code']);
168                 } elseif ($content['country'] == '0') {
169                         // Zero id???
170                         $content['country'] = '???';
171                 }
172
173                 // Add userid
174                 $content['userid'] = $userid;
175
176                 // Load user-details template
177                 loadTemplate('admin_user_details', false, $content);
178         } else {
179                 // Account does not exist!
180                 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', $userid));
181         }
182
183         // Free the result
184         SQL_FREERESULT($result_user);
185 } else {
186         $whereStatement = '';
187         if (isGetRequestParameterSet('letter')) {
188                 // List only persons w
189                 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
190         } // END - if
191
192         // Parse the status or mode parameter
193         if (isGetRequestParameterSet('status')) {
194                 // Is a WHERE statement already there?
195                 if (!empty($whereStatement)) {
196                         // Then append the status column
197                         $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
198                 } else {
199                         // Start a new one
200                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
201                 }
202         } elseif (isGetRequestParameterSet('mode')) {
203                 // Choose what we need to list
204                 switch (getRequestParameter('mode')) {
205                         case 'norefs': // Users w/o refs
206                                 if (!empty($whereStatement)) {
207                                         // Add AND statement
208                                         $whereStatement .= " AND `refid`=0";
209                                 } else {
210                                         // Add WHERE statement
211                                         $whereStatement = " WHERE `refid`=0";
212                                 }
213                                 break;
214
215                         default: // Invalid list mode
216                                 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
217                                 break;
218                 } // END - switch
219         } // END - if
220
221         // Generate master query string
222         $sql = sprintf("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 `%s` ASC",
223                 getRequestParameter('sortby')
224         );
225
226         // Prepare SQL and run it
227         $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
228
229         // Calculate page count (0.5 fixes a bug with page count)
230         if (getConfig('user_limit') == '0') {
231                 setConfigEntry('user_limit', 100);
232                 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
233         } // END - if
234
235         // Activate the extension please!
236         $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
237
238         if (!isGetRequestParameterSet('page'))   setGetRequestParameter('page'  , 1);
239         if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
240
241         // Add limitation to SQL string and run him again
242         $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
243         $result = SQL_QUERY($sql, __FILE__, __LINE__);
244
245         // Are there some entries?
246         if (!SQL_HASZERONUMS($result_master)) {
247                 // We have some (new?) registrations!
248                 $templateContent['colspan2']   = ($colspan + 2);
249                 $templateContent['user_count'] = getTotalConfirmedUser();
250
251                 // Sorting links
252                 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
253                 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
254                 $templateContent['page_nav']   = '';
255
256                 if ($numPages > 1) {
257                         $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
258                 } // END - if
259
260                 // Column with nickname when nickname extension is present
261                 // @TODO Rewrite this into a filter
262                 $templateContent['nickname_th'] = '';
263                 if (isExtensionActive('nickname')) {
264                         // Nickname extension found
265                         $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
266                 } // END - if
267
268                 // Load all users
269                 $OUT = '';
270                 while ($content = SQL_FETCHARRAY($result)) {
271                         // Merge more data in
272                         $content = merge_array($content, $templateContent);
273
274                         // Get number of unconfirmed mails
275                         $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
276                         if ($content['links'] > 0) {
277                                 $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
278                         } // END - if
279
280                         // Set link to sent mails if present
281                         if ($content['emails_sent'] > 0) {
282                                 $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
283                         } // END - if
284
285                         // Add nickname
286                         $content['nickname'] = '{--EXT_NICKNAME_404--}';
287                         if (isExtensionInstalled('nickname')) {
288                                 $content['nickname'] = getNickname($content['userid']);
289                         } // END - if
290
291                         // Clickrate
292                         $content['rate'] = '0';
293                         if ($content['emails_received'] > 0) {
294                                 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
295                         } // END - if
296
297                         // Transfer data to array
298                         $content['email']          = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
299                         $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
300                         $content['refs']           = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
301                         $content['locked']         = countSumTotalData($content['userid'], 'user_points', 'locked_points');
302
303                         // If we have at least one referal, make it clickable to referal list
304                         if ($content['refs'] > 0) {
305                                 $content['refs'] = $base . '&amp;what=list_refs&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
306                         } // END - if
307
308                         // Is the extension 'country' installed?
309                         // @TODO Rewrite this into a filter
310                         if (isExtensionActive('country')) {
311                                 // Then overwrite country information
312                                 $content['country'] = generateCountryInfo($content['country_code']);
313                         } elseif ($content['country'] == '') {
314                                 // Zero id???
315                                 $content['country'] = '???';
316                         }
317
318                         // Load row template and switch colors
319                         $OUT .= loadTemplate('admin_list_user_row', true, $content);
320                 } // END - while
321
322                 // Free memory
323                 SQL_FREERESULT($result);
324
325                 // Free some memory
326                 SQL_FREERESULT($result_master);
327
328                 // Remember all rows
329                 $content['rows'] = $OUT;
330
331                 // Merge more data again
332                 $content = merge_array($content, $templateContent);
333
334                 // Load main template
335                 loadTemplate('admin_list_user', false, $content);
336         } else {
337                 // No one as registered so far! :-(
338                 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
339         }
340
341         // Free memory
342         SQL_FREERESULT($result_master);
343 }
344
345 // [EOF]
346 ?>