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['total_points'] = getTotalPoints($content['userid']);
141 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
143 // Prepare array for filter
145 'userid' => $content['userid'],
149 // Run the filter chain
150 $data = runFilterChain('get_own_points', $data);
153 $content['own_points'] = $data['points'];
154 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
156 // Link to email_details if some are sent
157 if ($content['emails_sent'] > 0) {
158 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
162 $content['click_rate'] = '0';
163 if ($content['emails_received'] > 0) {
164 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
167 // Is the extension 'country' installed?
168 if (isExtensionActive('country')) {
169 // Then overwrite country information
170 $content['country'] = generateCountryInfo($content['country_code']);
171 } elseif ($content['country'] == '0') {
173 $content['country'] = '???';
177 $content['userid'] = $userid;
179 // Load user-details template
180 loadTemplate('admin_user_details', false, $content);
182 // Account does not exist!
183 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
187 SQL_FREERESULT($result_user);
189 $whereStatement = '';
190 if (isGetRequestElementSet('letter')) {
191 // List only persons w
192 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
195 // Parse the status or mode parameter
196 if (isGetRequestElementSet('status')) {
197 // Is a WHERE statement already there?
198 if (!empty($whereStatement)) {
199 // Then append the status column
200 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
203 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
205 } elseif (isGetRequestElementSet('do')) {
206 // Choose what we need to list
207 switch (getRequestElement('do')) {
208 case 'norefs': // Users w/o refs
209 if (!empty($whereStatement)) {
211 $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
213 // Add WHERE statement
214 $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
218 case 'random_refid': // Users available for random referral id
219 if (!empty($whereStatement)) {
221 $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
223 // Add WHERE statement
224 $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
228 case 'testers': // Test accounts
229 // Add statement through filter
230 $whereStatement = runFilterChain('user_inclusion_sql', $whereStatement);
233 default: // Invalid list mode
234 reportBug(__FILE__, __LINE__, sprintf("Invalid do %s detected.", SQL_ESCAPE(secureString(getRequestElement('do')))));
238 // If it is not 'testers', add exclusion SQL
239 if (getRequestElement('do') != 'testers') {
240 // Exclude tester users
241 $whereStatement = runFilterChain('user_exclusion_sql', $whereStatement);
245 // Generate master query string
246 $sql = sprintf("SELECT
254 `{?_MYSQL_PREFIX?}_user_data`
255 " . $whereStatement . "
258 getRequestElement('sortby')
261 // Prepare SQL and run it
262 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
264 // Is the user limit zero?
265 if (getUserLimit() == '0') {
266 // Then set it to default ...
267 setConfigEntry('user_limit', 100);
269 // ... but output warning
270 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
273 // Calculate page count (0.5 fixes a bug with page count)
274 $numPages = round(SQL_NUMROWS($result_master) / getUserLimit() + 0.5);
276 if (!isGetRequestElementSet('page')) setGetRequestElement('page' , 1);
277 if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getUserLimit());
279 // Add limitation to SQL string and run him again
280 $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
281 $result = SQL_QUERY($sql, __FILE__, __LINE__);
283 // Are there some entries?
284 if (!SQL_HASZERONUMS($result_master)) {
285 // Sorting links and number of pages
286 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
287 $templateContent['num_pages'] = $numPages;
289 // Column with nickname when nickname extension is present
290 // @TODO Rewrite this into a filter
291 $templateContent['nickname_th'] = '';
292 if (isExtensionActive('nickname')) {
293 // Nickname extension found
294 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
299 while ($content = SQL_FETCHARRAY($result)) {
300 // Merge more data in
301 $content = merge_array($content, $templateContent);
303 // Get number of unconfirmed mails
304 $content['links'] = getTotalUnconfirmedMails($content['userid']);
305 if ($content['links'] > 0) {
306 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
309 // Set link to sent mails if present
310 if ($content['emails_sent'] > 0) {
311 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
315 $content['click_rate'] = '0';
316 if ($content['emails_received'] > 0) {
317 $content['click_rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
320 // Transfer data to array
321 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
322 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
323 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
325 // Prepare array for filter
327 'userid' => $content['userid'],
331 // Run the filter chain
332 $data = runFilterChain('get_own_points', $data);
335 $content['own_points'] = $data['points'];
337 // Prepare array for filter again
339 'userid' => $content['userid'],
343 // Run the filter chain
344 $data = runFilterChain('get_locked_points', $data);
347 $content['locked_points'] = $data['points'];
349 // If we have at least one referral, make it clickable to referral list
350 if ($content['refs'] > 0) {
351 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
354 // Is the extension 'country' installed?
355 // @TODO Rewrite this into a filter
356 if (isExtensionActive('country')) {
357 // Then overwrite country information
358 $content['country'] = generateCountryInfo($content['country_code']);
359 } elseif ($content['country'] == '') {
361 $content['country'] = '???';
364 // Load row template and switch colors
365 $OUT .= loadTemplate('admin_list_user_row', true, $content);
369 SQL_FREERESULT($result);
372 SQL_FREERESULT($result_master);
375 $content['rows'] = $OUT;
377 // Merge more data again
378 $content = merge_array($content, $templateContent);
380 // Load main template
381 loadTemplate('admin_list_user', false, $content);
383 // No one as registered so far! :-(
384 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
388 SQL_FREERESULT($result_master);