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