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 - 2015 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 $moreColumns .= ', UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`';
55 // Is the extension 'country' installed?
56 if (isExtensionActive('country')) {
58 $moreColumns .= ',`country_code`';
62 if (!isGetRequestElementSet('letter')) { setGetRequestElement('letter', ''); }
63 if (!isGetRequestElementSet('sortby')) { setGetRequestElement('sortby', 'userid'); }
64 if (!isGetRequestElementSet('page')) { setGetRequestElement('page' , 1); }
67 $base = '[<a href="{%url=modules.php?module=admin';
69 if (isGetRequestElementSet('userid')) {
71 $userid = bigintval(getRequestElement('userid'));
73 // Does the account exists?
74 $result_user = sqlQueryEscaped('SELECT
92 `{?_MYSQL_PREFIX?}_user_data`
96 array($userid), __FILE__, __LINE__);
99 if (sqlNumRows($result_user) == 1) {
101 $content = sqlFetchArray($result_user);
103 // Get count/sum of refs, selected categories, unconfirmed mails
104 // @TODO Refacture these old link generation to functions
105 $content['refs'] = countSumTotalData($userid, 'refsystem', 'counter');
106 $content['cats'] = countSumTotalData($userid, 'user_cats', 'id', 'userid', TRUE);
107 $content['links'] = getTotalUnconfirmedMails($userid);
109 // Add links to the numbers
110 if ($content['links'] > 0) {
111 $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
113 if ($content['refs'] > 0) {
114 $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
116 if ($content['cats'] > 0) {
117 $content['cats'] = $base . '&what=list_user_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
120 // Calculate timestamp for birthday
121 // @TODO Refacture birth_foo to avoid uni* timetstamps as older members cannot be greeded correctly
122 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
124 // Is this above zero?
127 $content['birthday'] = generateDateTime($stamp, '2');
129 // Zero or below so set zero!
130 $content['birthday'] = generateDateTime(0, '2');
133 // Prepare data for template
134 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
135 $content['last_online'] = generateDateTime($content['last_online'], '2');
136 $content['joined'] = generateDateTime($content['joined'], '2');
137 $content['last_update'] = generateDateTime($content['last_update'], '2');
138 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], '2');
139 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
141 // Prepare array for filter
143 'userid' => $content['userid'],
147 // Run the filter chain
148 $data = runFilterChain('get_own_points', $data);
151 $content['own_points'] = $data['points'];
152 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
154 // Link to email_details if some are sent
155 if ($content['emails_sent'] > 0) {
156 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
160 $content['click_rate'] = calculatePercentageRate($content['mails_confirmed'], $content['emails_received']);
162 // Is the extension 'country' installed?
163 if (isExtensionActive('country')) {
164 // Then overwrite country information
165 $content['country'] = generateCountryInfo($content['country_code']);
166 } elseif ($content['country'] == '0') {
168 $content['country'] = '???';
172 $content['userid'] = $userid;
174 // Load user-details template
175 loadTemplate('admin_user_details', FALSE, $content);
177 // Account does not exist!
178 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
182 sqlFreeResult($result_user);
184 $whereStatement = '';
185 if (isGetRequestElementSet('letter')) {
186 // List only persons w
187 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
190 // Parse the status or mode parameter
191 if (isGetRequestElementSet('status')) {
192 // Is a WHERE statement already there?
193 if (!empty($whereStatement)) {
194 // Then append the status column
195 $whereStatement .= sprintf(" AND `status`='%s'", sqlEscapeString(strtoupper(getRequestElement('status'))));
198 $whereStatement = sprintf(" WHERE `status`='%s'", sqlEscapeString(strtoupper(getRequestElement('status'))));
201 // Exclude other users
202 $whereStatement = runFilterChain('user_exclusion_sql', ' ' . $whereStatement);
203 } elseif (isGetRequestElementSet('do')) {
204 // Choose what we need to list
205 switch (getRequestElement('do')) {
206 case 'norefs': // Users w/o refs
207 if (!empty($whereStatement)) {
209 $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
211 // Add WHERE statement
212 $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
216 case 'random_refid': // Users available for random referral id
217 if (!empty($whereStatement)) {
219 $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
221 // Add WHERE statement
222 $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
226 case 'testers': // Test accounts
227 // Add statement through filter
228 $whereStatement = runFilterChain('user_inclusion_sql', $whereStatement);
231 default: // Invalid list mode
232 reportBug(__FILE__, __LINE__, sprintf('Invalid do %s detected.', sqlEscapeString(getRequestElement('do'))));
236 // If it is not 'testers', add exclusion SQL
237 if (getRequestElement('do') != 'testers') {
238 // Exclude tester users
239 $whereStatement = runFilterChain('user_exclusion_sql', ' ' . $whereStatement);
243 // Generate master query string
244 $sql = sprintf('SELECT
252 `{?_MYSQL_PREFIX?}_user_data`
253 ' . $whereStatement . '
256 getRequestElement('sortby')
259 // Prepare SQL and run it
260 $result_master = sqlQuery($sql, __FILE__, __LINE__);
262 // Is the user limit zero?
263 if (getUserLimit() == '0') {
264 // Then set it to default ...
265 setConfigEntry('user_limit', 100);
267 // ... but output warning
268 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
271 // Calculate page count (0.5 fixes a bug with page count)
272 $numPages = round(sqlNumRows($result_master) / getUserLimit() + 0.5);
274 if (!isGetRequestElementSet('page')) setGetRequestElement('page' , 1);
275 if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getUserLimit());
277 // Add limitation to SQL string and run him again
278 $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
279 $result = sqlQuery($sql, __FILE__, __LINE__);
281 // Are there some entries?
282 if (!ifSqlHasZeroNumRows($result_master)) {
283 // Sorting links and number of pages
284 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
285 $templateContent['num_pages'] = $numPages;
287 // Column with nickname when nickname extension is present
288 // @TODO Rewrite this into a filter
289 $templateContent['nickname_th'] = '';
290 if (isExtensionActive('nickname')) {
291 // Nickname extension found
292 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
297 while ($content = sqlFetchArray($result)) {
298 // Merge more data in
299 $content = merge_array($content, $templateContent);
301 // Get number of unconfirmed mails
302 $content['links'] = getTotalUnconfirmedMails($content['userid']);
303 if ($content['links'] > 0) {
304 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
307 // Set link to sent mails if present
308 if ($content['emails_sent'] > 0) {
309 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
313 $content['click_rate'] = calculatePercentageRate($content['mails_confirmed'], $content['emails_received']);
315 // Transfer data to array
316 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
317 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
318 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', TRUE);
320 // Prepare array for filter
322 'userid' => $content['userid'],
326 // Run the filter chain
327 $data = runFilterChain('get_own_points', $data);
330 $content['own_points'] = $data['points'];
332 // Prepare array for filter again
334 'userid' => $content['userid'],
338 // Run the filter chain
339 $data = runFilterChain('get_locked_points', $data);
342 $content['locked_points'] = $data['points'];
344 // If we have at least one referral, make it clickable to referral list
345 if ($content['refs'] > 0) {
346 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
349 // Is the extension 'country' installed?
350 // @TODO Rewrite this into a filter
351 if (isExtensionActive('country')) {
352 // Then overwrite country information
353 $content['country'] = generateCountryInfo($content['country_code']);
354 } elseif ($content['country'] == '') {
356 $content['country'] = '???';
359 // Load row template and switch colors
360 $OUT .= loadTemplate('admin_list_user_row', TRUE, $content);
364 sqlFreeResult($result);
367 sqlFreeResult($result_master);
370 $content['rows'] = $OUT;
372 // Merge more data again
373 $content = merge_array($content, $templateContent);
375 // Load main template
376 loadTemplate('admin_list_user', FALSE, $content);
378 // No one as registered so far! :-(
379 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
383 sqlFreeResult($result_master);