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