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