2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 09/28/2003 *
4 * =================== Last change: 08/18/2004 *
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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
50 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
52 $MORE .= ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
55 // Is the extension 'country' installed?
56 if (isExtensionActive('country')) {
58 $MORE .= ',`country_code`';
61 $MORE .= ',`country`';
65 if (!isGetRequestElementSet('letter')) { setGetRequestElement('letter', ''); }
66 if (!isGetRequestElementSet('sortby')) { setGetRequestElement('sortby', 'userid'); }
67 if (!isGetRequestElementSet('page')) { setGetRequestElement('page' , 1); }
70 $base = '[<a href="{%url=modules.php?module=admin';
72 if (isGetRequestElementSet('userid')) {
74 $userid = bigintval(getRequestElement('userid'));
76 // Does the account exists?
77 $result_user = SQL_QUERY_ESC("SELECT
95 `{?_MYSQL_PREFIX?}_user_data`
99 array($userid), __FILE__, __LINE__);
102 if (SQL_NUMROWS($result_user) == 1) {
104 $content = SQL_FETCHARRAY($result_user);
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);
111 // Add links to the numbers
112 if ($content['links'] > 0) {
113 $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
115 if ($content['refs'] > 0) {
116 $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
118 if ($content['cats'] > 0) {
119 $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
122 // Calculate timestamp for birthday
123 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
125 // Is this above zero?
128 $content['birthday'] = generateDateTime($stamp, '2');
130 // Zero or below so set zero!
131 $content['birthday'] = generateDateTime(0, '2');
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['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
142 // Prepare array for filter
144 'userid' => $content['userid'],
148 // Run the filter chain
149 $data = runFilterChain('get_own_points', $data);
152 $content['own_points'] = $data['points'];
153 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
155 // Link to email_details if some are sent
156 if ($content['emails_sent'] > 0) {
157 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
161 $content['click_rate'] = '0';
162 if ($content['emails_received'] > 0) {
163 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
166 // Is the extension 'country' installed?
167 if (isExtensionActive('country')) {
168 // Then overwrite country information
169 $content['country'] = generateCountryInfo($content['country_code']);
170 } elseif ($content['country'] == '0') {
172 $content['country'] = '???';
176 $content['userid'] = $userid;
178 // Load user-details template
179 loadTemplate('admin_user_details', false, $content);
181 // Account does not exist!
182 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
186 SQL_FREERESULT($result_user);
188 $whereStatement = '';
189 if (isGetRequestElementSet('letter')) {
190 // List only persons w
191 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
194 // Parse the status or mode parameter
195 if (isGetRequestElementSet('status')) {
196 // Is a WHERE statement already there?
197 if (!empty($whereStatement)) {
198 // Then append the status column
199 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
202 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
204 } elseif (isGetRequestElementSet('do')) {
205 // Choose what we need to list
206 switch (getRequestElement('do')) {
207 case 'norefs': // Users w/o refs
208 if (!empty($whereStatement)) {
210 $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
212 // Add WHERE statement
213 $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
217 case 'random_refid': // Users available for random referral id
218 if (!empty($whereStatement)) {
220 $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
222 // Add WHERE statement
223 $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
227 case 'testers': // Test accounts
228 // Add statement through filter
229 $whereStatement = runFilterChain('user_inclusion_sql', $whereStatement);
232 default: // Invalid list mode
233 reportBug(__FILE__, __LINE__, sprintf("Invalid do %s detected.", SQL_ESCAPE(secureString(getRequestElement('do')))));
237 // If it is not 'testers', add exclusion SQL
238 if (getRequestElement('do') != 'testers') {
239 // Exclude tester users
240 $whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
244 // Generate master query string
245 $sql = sprintf("SELECT
253 `{?_MYSQL_PREFIX?}_user_data`
254 " . $whereStatement . "
257 getRequestElement('sortby')
260 // Prepare SQL and run it
261 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
263 // Is the user limit zero?
264 if (getUserLimit() == '0') {
265 // Then set it to default ...
266 setConfigEntry('user_limit', 100);
268 // ... but output warning
269 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
272 // Calculate page count (0.5 fixes a bug with page count)
273 $numPages = round(SQL_NUMROWS($result_master) / getUserLimit() + 0.5);
275 if (!isGetRequestElementSet('page')) setGetRequestElement('page' , 1);
276 if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getUserLimit());
278 // Add limitation to SQL string and run him again
279 $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
280 $result = SQL_QUERY($sql, __FILE__, __LINE__);
282 // Are there some entries?
283 if (!SQL_HASZERONUMS($result_master)) {
284 // Sorting links and number of pages
285 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
286 $templateContent['num_pages'] = $numPages;
288 // Column with nickname when nickname extension is present
289 // @TODO Rewrite this into a filter
290 $templateContent['nickname_th'] = '';
291 if (isExtensionActive('nickname')) {
292 // Nickname extension found
293 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
298 while ($content = SQL_FETCHARRAY($result)) {
299 // Merge more data in
300 $content = merge_array($content, $templateContent);
302 // Get number of unconfirmed mails
303 $content['links'] = getTotalUnconfirmedMails($content['userid']);
304 if ($content['links'] > 0) {
305 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
308 // Set link to sent mails if present
309 if ($content['emails_sent'] > 0) {
310 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
314 $content['click_rate'] = '0';
315 if ($content['emails_received'] > 0) {
316 $content['click_rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
319 // Transfer data to array
320 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
321 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
322 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
324 // Prepare array for filter
326 'userid' => $content['userid'],
330 // Run the filter chain
331 $data = runFilterChain('get_own_points', $data);
334 $content['own_points'] = $data['points'];
336 // Prepare array for filter again
338 'userid' => $content['userid'],
342 // Run the filter chain
343 $data = runFilterChain('get_locked_points', $data);
346 $content['locked_points'] = $data['points'];
348 // If we have at least one referral, make it clickable to referral list
349 if ($content['refs'] > 0) {
350 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
353 // Is the extension 'country' installed?
354 // @TODO Rewrite this into a filter
355 if (isExtensionActive('country')) {
356 // Then overwrite country information
357 $content['country'] = generateCountryInfo($content['country_code']);
358 } elseif ($content['country'] == '') {
360 $content['country'] = '???';
363 // Load row template and switch colors
364 $OUT .= loadTemplate('admin_list_user_row', true, $content);
368 SQL_FREERESULT($result);
371 SQL_FREERESULT($result_master);
374 $content['rows'] = $OUT;
376 // Merge more data again
377 $content = merge_array($content, $templateContent);
379 // Load main template
380 loadTemplate('admin_list_user', false, $content);
382 // No one as registered so far! :-(
383 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
387 SQL_FREERESULT($result_master);