28f967faa12f9290a9d3ac92998171d534d415d7
[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['total_points']      = getTotalPoints($content['userid']);
141                 $content['locked_points']     = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
142
143                 // Prepare array for filter
144                 $data = array(
145                         'userid' => $content['userid'],
146                         'points' => 0
147                 );
148
149                 // Run the filter chain
150                 $data = runFilterChain('get_own_points', $data);
151
152                 // Add more data
153                 $content['own_points']     = $data['points'];
154                 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
155
156                 // Link to email_details if some are sent
157                 if ($content['emails_sent'] > 0) {
158                         $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
159                 } // END - if
160
161                 // Clickrate
162                 $content['click_rate'] = '0';
163                 if ($content['emails_received'] > 0) {
164                         $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
165                 } // END - if
166
167                 // Is the extension 'country' installed?
168                 if (isExtensionActive('country')) {
169                         // Then overwrite country information
170                         $content['country'] = generateCountryInfo($content['country_code']);
171                 } elseif ($content['country'] == '0') {
172                         // Zero id???
173                         $content['country'] = '???';
174                 }
175
176                 // Add userid
177                 $content['userid'] = $userid;
178
179                 // Load user-details template
180                 loadTemplate('admin_user_details', false, $content);
181         } else {
182                 // Account does not exist!
183                 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
184         }
185
186         // Free the result
187         SQL_FREERESULT($result_user);
188 } else {
189         $whereStatement = '';
190         if (isGetRequestElementSet('letter')) {
191                 // List only persons w
192                 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
193         } // END - if
194
195         // Parse the status or mode parameter
196         if (isGetRequestElementSet('status')) {
197                 // Is a WHERE statement already there?
198                 if (!empty($whereStatement)) {
199                         // Then append the status column
200                         $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
201                 } else {
202                         // Start a new one
203                         $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
204                 }
205         } elseif (isGetRequestElementSet('do')) {
206                 // Choose what we need to list
207                 switch (getRequestElement('do')) {
208                         case 'norefs': // Users w/o refs
209                                 if (!empty($whereStatement)) {
210                                         // Add AND statement
211                                         $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
212                                 } else {
213                                         // Add WHERE statement
214                                         $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
215                                 }
216                                 break;
217
218                         case 'random_refid': // Users available for random referral id
219                                 if (!empty($whereStatement)) {
220                                         // Add AND statement
221                                         $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
222                                 } else {
223                                         // Add WHERE statement
224                                         $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
225                                 }
226                                 break;
227
228                         case 'testers': // Test accounts
229                                 // Add statement through filter
230                                 $whereStatement = runFilterChain('user_inclusion_sql', $whereStatement);
231                                 break;
232
233                         default: // Invalid list mode
234                                 reportBug(__FILE__, __LINE__, sprintf("Invalid do %s detected.", SQL_ESCAPE(secureString(getRequestElement('do')))));
235                                 break;
236                 } // END - switch
237
238                 // If it is not 'testers', add exclusion SQL
239                 if (getRequestElement('do') != 'testers') {
240                         // Exclude tester users
241                         $whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
242                 } // END - if
243         } // END - if
244
245         // Generate master query string
246         $sql = sprintf("SELECT
247         `userid`,
248         `email`,
249         `emails_sent`,
250         `mails_confirmed`,
251         `emails_received`
252         " . $MORE . "
253 FROM
254         `{?_MYSQL_PREFIX?}_user_data`
255 " . $whereStatement . "
256 ORDER BY
257         `%s` ASC",
258                 getRequestElement('sortby')
259         );
260
261         // Prepare SQL and run it
262         $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
263
264         // Is the user limit zero?
265         if (getUserLimit() == '0') {
266                 // Then set it to default ...
267                 setConfigEntry('user_limit', 100);
268
269                 // ... but output warning
270                 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
271         } // END - if
272
273         // Calculate page count (0.5 fixes a bug with page count)
274         $numPages = round(SQL_NUMROWS($result_master) / getUserLimit() + 0.5);
275
276         if (!isGetRequestElementSet('page'))   setGetRequestElement('page'  , 1);
277         if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getUserLimit());
278
279         // Add limitation to SQL string and run him again
280         $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
281         $result = SQL_QUERY($sql, __FILE__, __LINE__);
282
283         // Are there some entries?
284         if (!SQL_HASZERONUMS($result_master)) {
285                 // Sorting links and number of pages
286                 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
287                 $templateContent['num_pages'] = $numPages;
288
289                 // Column with nickname when nickname extension is present
290                 // @TODO Rewrite this into a filter
291                 $templateContent['nickname_th'] = '';
292                 if (isExtensionActive('nickname')) {
293                         // Nickname extension found
294                         $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
295                 } // END - if
296
297                 // Load all users
298                 $OUT = '';
299                 while ($content = SQL_FETCHARRAY($result)) {
300                         // Merge more data in
301                         $content = merge_array($content, $templateContent);
302
303                         // Get number of unconfirmed mails
304                         $content['links'] = getTotalUnconfirmedMails($content['userid']);
305                         if ($content['links'] > 0) {
306                                 $content['links'] = $base . '&amp;what=list_links&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
307                         } // END - if
308
309                         // Set link to sent mails if present
310                         if ($content['emails_sent'] > 0) {
311                                 $content['emails_sent'] = $base . '&amp;what=email_details&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
312                         } // END - if
313
314                         // Click rate
315                         $content['click_rate'] = '0';
316                         if ($content['emails_received'] > 0) {
317                                 $content['click_rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
318                         } // END - if
319
320                         // Transfer data to array
321                         $content['email']          = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
322                         $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
323                         $content['refs']           = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
324
325                         // Prepare array for filter
326                         $data = array(
327                                 'userid' => $content['userid'],
328                                 'points' => 0
329                         );
330
331                         // Run the filter chain
332                         $data = runFilterChain('get_own_points', $data);
333
334                         // Copy points
335                         $content['own_points'] = $data['points'];
336
337                         // Prepare array for filter again
338                         $data = array(
339                                 'userid' => $content['userid'],
340                                 'points' => 0
341                         );
342
343                         // Run the filter chain
344                         $data = runFilterChain('get_locked_points', $data);
345
346                         // Copy points
347                         $content['locked_points']  = $data['points'];
348
349                         // If we have at least one referral, make it clickable to referral list
350                         if ($content['refs'] > 0) {
351                                 $content['refs'] = $base . '&amp;what=list_refs&amp;userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
352                         } // END - if
353
354                         // Is the extension 'country' installed?
355                         // @TODO Rewrite this into a filter
356                         if (isExtensionActive('country')) {
357                                 // Then overwrite country information
358                                 $content['country'] = generateCountryInfo($content['country_code']);
359                         } elseif ($content['country'] == '') {
360                                 // Zero id???
361                                 $content['country'] = '???';
362                         }
363
364                         // Load row template and switch colors
365                         $OUT .= loadTemplate('admin_list_user_row', true, $content);
366                 } // END - while
367
368                 // Free memory
369                 SQL_FREERESULT($result);
370
371                 // Free some memory
372                 SQL_FREERESULT($result_master);
373
374                 // Remember all rows
375                 $content['rows'] = $OUT;
376
377                 // Merge more data again
378                 $content = merge_array($content, $templateContent);
379
380                 // Load main template
381                 loadTemplate('admin_list_user', false, $content);
382         } else {
383                 // No one as registered so far! :-(
384                 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
385         }
386
387         // Free memory
388         SQL_FREERESULT($result_master);
389 }
390
391 // [EOF]
392 ?>