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