Naming convention on language strings applied, ACL handling fixed:
[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_points']      = getTotalPoints($content['userid']);
143                 $content['locked_points']     = countSumTotalData($userid, 'user_points', 'locked_points') + countSumTotalData($userid, 'user_points', 'locked_order_points');
144                 $content['own_points']        = countSumTotalData($userid, 'user_points', 'points') + countSumTotalData($userid, 'user_points', 'order_points');
145                 $content['lock_timestamp']    = generateDateTime($content['lock_timestamp'], 2);
146                 $content['nickname']          = '{--EXT_NICKNAME_404--}';
147
148                 // Link to email_details if some are sent
149                 if ($content['emails_sent'] > 0) {
150                         $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $userid . '%}">}{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
151                 } // END - if
152
153                 // Nickname inclusion?
154                 // @TODO Rewrite these to filters
155                 if (isExtensionInstalled('nickname')) {
156                         $content['nickname'] = getNickname($content['userid']);
157                 } // END - if
158
159                 // Clickrate
160                 $content['click_rate'] = '0';
161                 if ($content['emails_received'] > 0) {
162                         $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
163                 } // END - if
164
165                 // Is the extension 'country' installed?
166                 if (isExtensionActive('country')) {
167                         // Then overwrite country information
168                         $content['country'] = generateCountryInfo($content['country_code']);
169                 } elseif ($content['country'] == '0') {
170                         // Zero id???
171                         $content['country'] = '???';
172                 }
173
174                 // Add userid
175                 $content['userid'] = $userid;
176
177                 // Load user-details template
178                 loadTemplate('admin_user_details', false, $content);
179         } else {
180                 // Account does not exist!
181                 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', $userid));
182         }
183
184         // Free the result
185         SQL_FREERESULT($result_user);
186 } else {
187         $whereStatement = '';
188         if (isGetRequestParameterSet('letter')) {
189                 // List only persons w
190                 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
191         } // END - if
192
193         // Parse the status or mode parameter
194         if (isGetRequestParameterSet('status')) {
195                 // Is a WHERE statement already there?
196                 if (!empty($whereStatement)) {
197                         // Then append the status column
198                         $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
199                 } else {
200                         // Start a new one
201                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
202                 }
203         } elseif (isGetRequestParameterSet('mode')) {
204                 // Choose what we need to list
205                 switch (getRequestParameter('mode')) {
206                         case 'norefs': // Users w/o refs
207                                 if (!empty($whereStatement)) {
208                                         // Add AND statement
209                                         $whereStatement .= " AND `refid`=0";
210                                 } else {
211                                         // Add WHERE statement
212                                         $whereStatement = " WHERE `refid`=0";
213                                 }
214                                 break;
215
216                         default: // Invalid list mode
217                                 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
218                                 break;
219                 } // END - switch
220         } // END - if
221
222         // Generate master query string
223         $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",
224                 getRequestParameter('sortby')
225         );
226
227         // Prepare SQL and run it
228         $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
229
230         // Calculate page count (0.5 fixes a bug with page count)
231         if (getConfig('user_limit') == '0') {
232                 setConfigEntry('user_limit', 100);
233                 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
234         } // END - if
235
236         // Activate the extension please!
237         $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
238
239         if (!isGetRequestParameterSet('page'))   setGetRequestParameter('page'  , 1);
240         if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
241
242         // Add limitation to SQL string and run him again
243         $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
244         $result = SQL_QUERY($sql, __FILE__, __LINE__);
245
246         // Are there some entries?
247         if (!SQL_HASZERONUMS($result_master)) {
248                 // We have some (new?) registrations!
249                 $templateContent['colspan2']   = ($colspan + 2);
250                 $templateContent['user_count'] = getTotalConfirmedUser();
251
252                 // Sorting links
253                 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
254                 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
255                 $templateContent['page_nav']   = '';
256
257                 if ($numPages > 1) {
258                         $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
259                 } // END - if
260
261                 // Column with nickname when nickname extension is present
262                 // @TODO Rewrite this into a filter
263                 $templateContent['nickname_th'] = '';
264                 if (isExtensionActive('nickname')) {
265                         // Nickname extension found
266                         $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
267                 } // END - if
268
269                 // Load all users
270                 $OUT = '';
271                 while ($content = SQL_FETCHARRAY($result)) {
272                         // Merge more data in
273                         $content = merge_array($content, $templateContent);
274
275                         // Get number of unconfirmed mails
276                         $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
277                         if ($content['links'] > 0) {
278                                 $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
279                         } // END - if
280
281                         // Set link to sent mails if present
282                         if ($content['emails_sent'] > 0) {
283                                 $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
284                         } // END - if
285
286                         // Add nickname
287                         $content['nickname'] = '{--EXT_NICKNAME_404--}';
288                         if (isExtensionInstalled('nickname')) {
289                                 $content['nickname'] = getNickname($content['userid']);
290                         } // END - if
291
292                         // Clickrate
293                         $content['rate'] = '0';
294                         if ($content['emails_received'] > 0) {
295                                 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
296                         } // END - if
297
298                         // Transfer data to array
299                         $content['email']          = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
300                         $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
301                         $content['refs']           = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
302                         $content['own_points']     = countSumTotalData($content['userid'], 'user_points', 'points') + countSumTotalData($content['userid'], 'user_points', 'order_points');
303                         $content['locked_points']  = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
304
305                         // If we have at least one referal, make it clickable to referal list
306                         if ($content['refs'] > 0) {
307                                 $content['refs'] = $base . '&amp;what=list_refs&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
308                         } // END - if
309
310                         // Is the extension 'country' installed?
311                         // @TODO Rewrite this into a filter
312                         if (isExtensionActive('country')) {
313                                 // Then overwrite country information
314                                 $content['country'] = generateCountryInfo($content['country_code']);
315                         } elseif ($content['country'] == '') {
316                                 // Zero id???
317                                 $content['country'] = '???';
318                         }
319
320                         // Load row template and switch colors
321                         $OUT .= loadTemplate('admin_list_user_row', true, $content);
322                 } // END - while
323
324                 // Free memory
325                 SQL_FREERESULT($result);
326
327                 // Free some memory
328                 SQL_FREERESULT($result_master);
329
330                 // Remember all rows
331                 $content['rows'] = $OUT;
332
333                 // Merge more data again
334                 $content = merge_array($content, $templateContent);
335
336                 // Load main template
337                 loadTemplate('admin_list_user', false, $content);
338         } else {
339                 // No one as registered so far! :-(
340                 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
341         }
342
343         // Free memory
344         SQL_FREERESULT($result_master);
345 }
346
347 // [EOF]
348 ?>