Caching of XML/email templates finished:
[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 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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 // Init variables
47 $MORE = '';
48
49 // Add lock reason?
50 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
51         // Add them...
52         $MORE .= ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
53 } // END - if
54
55 // Is the extension 'country' installed?
56 if (isExtensionActive('country')) {
57         // Add country code
58         $MORE .= ',`country_code`';
59 } else {
60         // Add direct value
61         $MORE .= ',`country`';
62 }
63
64 // Init unset data
65 if (!isGetRequestElementSet('letter')) { setGetRequestElement('letter', '');       }
66 if (!isGetRequestElementSet('sortby')) { setGetRequestElement('sortby', 'userid'); }
67 if (!isGetRequestElementSet('page'))   { setGetRequestElement('page'  , 1);        }
68
69 // Set base URL
70 $base = '[<a href="{%url=modules.php?module=admin';
71
72 if (isGetRequestElementSet('userid')) {
73         // Secure the user id
74         $userid = bigintval(getRequestElement('userid'));
75
76         // Does the account exists?
77         $result_user = SQL_QUERY_ESC("SELECT
78         `userid`,
79         `country`,
80         `email`,
81         `birth_day`,
82         `birth_month`,
83         `birth_year`,
84         `last_online`,
85         `used_points`,
86         `emails_sent`,
87         `joined`,
88         `last_update`,
89         `last_profile_sent`,
90         `notified`,
91         `emails_received`,
92         `mails_confirmed`
93         ".$MORE."
94 FROM
95         `{?_MYSQL_PREFIX?}_user_data`
96 WHERE
97         `userid`=%s
98 LIMIT 1",
99                 array($userid), __FILE__, __LINE__);
100
101         // User found?
102         if (SQL_NUMROWS($result_user) == 1) {
103                 // Account found
104                 $content  = SQL_FETCHARRAY($result_user);
105
106                 // Get count/sum of refs, selected categories, unconfirmed mails
107                 $content['refs']  = countSumTotalData($userid, 'refsystem', 'counter');
108                 $content['cats']  = countSumTotalData($userid, 'user_cats', 'id', 'userid', true);
109                 $content['links'] = getTotalUnconfirmedMails($userid);
110
111                 // Add links to the numbers
112                 if ($content['links'] > 0) {
113                         $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $userid . '%}">' . $content['links'] . '</a>]';
114                 } // END - if
115                 if ($content['refs']  > 0) {
116                         $content['refs']  = $base . '&amp;what=list_refs&amp;userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
117                 } // END - if
118                 if ($content['cats']  > 0) {
119                         $content['cats']  = $base . '&amp;what=list_cats&amp;userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
120                 } // END - if
121
122                 // Calculate timestamp for birthday
123                 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
124
125                 // Is this above zero?
126                 if ($stamp > 0) {
127                         // Then use it
128                         $content['birthday'] = generateDateTime($stamp, '2');
129                 } else {
130                         // Zero or below so set zero!
131                         $content['birthday'] = generateDateTime(0, '2');
132                 }
133
134                 // Prepare data for template
135                 $content['email_link']        = generateEmailLink($content['email'], 'user_data');
136                 $content['last_online']       = generateDateTime($content['last_online'], '2');
137                 $content['joined']            = generateDateTime($content['joined'], '2');
138                 $content['last_update']       = generateDateTime($content['last_update'], '2');
139                 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], '2');
140                 $content['locked_points']     = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
141
142                 // Prepare array for filter
143                 $data = array(
144                         'userid' => $content['userid'],
145                         'points' => 0
146                 );
147
148                 // Run the filter chain
149                 $data = runFilterChain('get_own_points', $data);
150
151                 // Add more data
152                 $content['own_points']     = $data['points'];
153                 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
154
155                 // Link to email_details if some are sent
156                 if ($content['emails_sent'] > 0) {
157                         $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
158                 } // END - if
159
160                 // Clickrate
161                 $content['click_rate'] = '0';
162                 if ($content['emails_received'] > 0) {
163                         $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
164                 } // END - if
165
166                 // Is the extension 'country' installed?
167                 if (isExtensionActive('country')) {
168                         // Then overwrite country information
169                         $content['country'] = generateCountryInfo($content['country_code']);
170                 } elseif ($content['country'] == '0') {
171                         // Zero id???
172                         $content['country'] = '???';
173                 }
174
175                 // Add userid
176                 $content['userid'] = $userid;
177
178                 // Load user-details template
179                 loadTemplate('admin_user_details', false, $content);
180         } else {
181                 // Account does not exist!
182                 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
183         }
184
185         // Free the result
186         SQL_FREERESULT($result_user);
187 } else {
188         $whereStatement = '';
189         if (isGetRequestElementSet('letter')) {
190                 // List only persons w
191                 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
192         } // END - if
193
194         // Parse the status or mode parameter
195         if (isGetRequestElementSet('status')) {
196                 // Is a WHERE statement already there?
197                 if (!empty($whereStatement)) {
198                         // Then append the status column
199                         $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
200                 } else {
201                         // Start a new one
202                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
203                 }
204         } elseif (isGetRequestElementSet('do')) {
205                 // Choose what we need to list
206                 switch (getRequestElement('do')) {
207                         case 'norefs': // Users w/o refs
208                                 if (!empty($whereStatement)) {
209                                         // Add AND statement
210                                         $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
211                                 } else {
212                                         // Add WHERE statement
213                                         $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
214                                 }
215                                 break;
216
217                         case 'random_refid': // Users available for random referral id
218                                 if (!empty($whereStatement)) {
219                                         // Add AND statement
220                                         $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
221                                 } else {
222                                         // Add WHERE statement
223                                         $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
224                                 }
225                                 break;
226
227                         case 'testers': // Test accounts
228                                 // Add statement through filter
229                                 $whereStatement = runFilterChain('user_inclusion_sql', $whereStatement);
230                                 break;
231
232                         default: // Invalid list mode
233                                 reportBug(__FILE__, __LINE__, sprintf("Invalid do %s detected.", SQL_ESCAPE(secureString(getRequestElement('do')))));
234                                 break;
235                 } // END - switch
236
237                 // If it is not 'testers', add exclusion SQL
238                 if (getRequestElement('do') != 'testers') {
239                         // Exclude tester users
240                         $whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
241                 } // END - if
242         } // END - if
243
244         // Generate master query string
245         $sql = sprintf("SELECT
246         `userid`,
247         `email`,
248         `emails_sent`,
249         `mails_confirmed`,
250         `emails_received`
251         " . $MORE . "
252 FROM
253         `{?_MYSQL_PREFIX?}_user_data`
254 " . $whereStatement . "
255 ORDER BY
256         `%s` ASC",
257                 getRequestElement('sortby')
258         );
259
260         // Prepare SQL and run it
261         $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
262
263         // Is the user limit zero?
264         if (getUserLimit() == '0') {
265                 // Then set it to default ...
266                 setConfigEntry('user_limit', 100);
267
268                 // ... but output warning
269                 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
270         } // END - if
271
272         // Calculate page count (0.5 fixes a bug with page count)
273         $numPages = round(SQL_NUMROWS($result_master) / getUserLimit() + 0.5);
274
275         if (!isGetRequestElementSet('page'))   setGetRequestElement('page'  , 1);
276         if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getUserLimit());
277
278         // Add limitation to SQL string and run him again
279         $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
280         $result = SQL_QUERY($sql, __FILE__, __LINE__);
281
282         // Are there some entries?
283         if (!SQL_HASZERONUMS($result_master)) {
284                 // Sorting links and number of pages
285                 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
286                 $templateContent['num_pages'] = $numPages;
287
288                 // Column with nickname when nickname extension is present
289                 // @TODO Rewrite this into a filter
290                 $templateContent['nickname_th'] = '';
291                 if (isExtensionActive('nickname')) {
292                         // Nickname extension found
293                         $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
294                 } // END - if
295
296                 // Load all users
297                 $OUT = '';
298                 while ($content = SQL_FETCHARRAY($result)) {
299                         // Merge more data in
300                         $content = merge_array($content, $templateContent);
301
302                         // Get number of unconfirmed mails
303                         $content['links'] = getTotalUnconfirmedMails($content['userid']);
304                         if ($content['links'] > 0) {
305                                 $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
306                         } // END - if
307
308                         // Set link to sent mails if present
309                         if ($content['emails_sent'] > 0) {
310                                 $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
311                         } // END - if
312
313                         // Click rate
314                         $content['click_rate'] = '0';
315                         if ($content['emails_received'] > 0) {
316                                 $content['click_rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
317                         } // END - if
318
319                         // Transfer data to array
320                         $content['email']          = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
321                         $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
322                         $content['refs']           = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
323
324                         // Prepare array for filter
325                         $data = array(
326                                 'userid' => $content['userid'],
327                                 'points' => 0
328                         );
329
330                         // Run the filter chain
331                         $data = runFilterChain('get_own_points', $data);
332
333                         // Copy points
334                         $content['own_points'] = $data['points'];
335
336                         // Prepare array for filter again
337                         $data = array(
338                                 'userid' => $content['userid'],
339                                 'points' => 0
340                         );
341
342                         // Run the filter chain
343                         $data = runFilterChain('get_locked_points', $data);
344
345                         // Copy points
346                         $content['locked_points']  = $data['points'];
347
348                         // If we have at least one referral, make it clickable to referral list
349                         if ($content['refs'] > 0) {
350                                 $content['refs'] = $base . '&amp;what=list_refs&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
351                         } // END - if
352
353                         // Is the extension 'country' installed?
354                         // @TODO Rewrite this into a filter
355                         if (isExtensionActive('country')) {
356                                 // Then overwrite country information
357                                 $content['country'] = generateCountryInfo($content['country_code']);
358                         } elseif ($content['country'] == '') {
359                                 // Zero id???
360                                 $content['country'] = '???';
361                         }
362
363                         // Load row template and switch colors
364                         $OUT .= loadTemplate('admin_list_user_row', true, $content);
365                 } // END - while
366
367                 // Free memory
368                 SQL_FREERESULT($result);
369
370                 // Free some memory
371                 SQL_FREERESULT($result_master);
372
373                 // Remember all rows
374                 $content['rows'] = $OUT;
375
376                 // Merge more data again
377                 $content = merge_array($content, $templateContent);
378
379                 // Load main template
380                 loadTemplate('admin_list_user', false, $content);
381         } else {
382                 // No one as registered so far! :-(
383                 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
384         }
385
386         // Free memory
387         SQL_FREERESULT($result_master);
388 }
389
390 // [EOF]
391 ?>