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