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