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 - 2011 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
78 `userid`,`country`,`email`,`birth_day`,`birth_month`,`birth_year`,`last_online`,`used_points`,`emails_sent`,`joined`,`last_update`,`last_profile_sent`,`notified`,`emails_received`,`mails_confirmed`".$MORE."
80 `{?_MYSQL_PREFIX?}_user_data`
84 array($userid), __FILE__, __LINE__);
87 if (SQL_NUMROWS($result_user) == 1) {
89 $content = SQL_FETCHARRAY($result_user);
91 // Get count/sum of refs, selected categories, unconfirmed mails
92 $content['refs'] = countSumTotalData($userid, 'refsystem', 'counter');
93 $content['cats'] = countSumTotalData($userid, 'user_cats', 'id', 'userid', true);
94 $content['links'] = getTotalUnconfirmedMails($userid);
96 // Add links to the numbers
97 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
98 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
99 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
101 // Calculate timestamp for birthday
102 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
104 // Is this above zero?
107 $content['birthday'] = generateDateTime($stamp, '2');
109 // Zero or below so set zero!
110 $content['birthday'] = generateDateTime(0, '2');
113 // Prepare data for template
114 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
115 $content['last_online'] = generateDateTime($content['last_online'], '2');
116 $content['joined'] = generateDateTime($content['joined'], '2');
117 $content['last_update'] = generateDateTime($content['last_update'], '2');
118 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], '2');
119 $content['total_points'] = getTotalPoints($content['userid']);
120 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
122 // Prepare array for filter
124 'userid' => $content['userid'],
128 // Run the filter chain
129 $data = runFilterChain('get_own_points', $data);
132 $content['own_points'] = $data['points'];
133 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
135 // Link to email_details if some are sent
136 if ($content['emails_sent'] > 0) {
137 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
141 $content['click_rate'] = '0';
142 if ($content['emails_received'] > 0) {
143 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
146 // Is the extension 'country' installed?
147 if (isExtensionActive('country')) {
148 // Then overwrite country information
149 $content['country'] = generateCountryInfo($content['country_code']);
150 } elseif ($content['country'] == '0') {
152 $content['country'] = '???';
156 $content['userid'] = $userid;
158 // Load user-details template
159 loadTemplate('admin_user_details', false, $content);
161 // Account does not exist!
162 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
166 SQL_FREERESULT($result_user);
168 $whereStatement = '';
169 if (isGetRequestElementSet('letter')) {
170 // List only persons w
171 $whereStatement = " WHERE `family` LIKE '".getRequestElement('letter') . "%%'";
174 // Parse the status or mode parameter
175 if (isGetRequestElementSet('status')) {
176 // Is a WHERE statement already there?
177 if (!empty($whereStatement)) {
178 // Then append the status column
179 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
182 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestElement('status')))));
184 } elseif (isGetRequestElementSet('mode')) {
185 // Choose what we need to list
186 switch (getRequestElement('mode')) {
187 case 'norefs': // Users w/o refs
188 if (!empty($whereStatement)) {
190 $whereStatement .= ' AND (`refid`=0 OR `refid` IS NULL)';
192 // Add WHERE statement
193 $whereStatement = ' WHERE (`refid`=0 OR `refid` IS NULL)';
197 case 'random_refid': // Users available for random referral id
198 if (!empty($whereStatement)) {
200 $whereStatement .= ' AND `rand_confirmed` >= {?user_min_confirmed?}';
202 // Add WHERE statement
203 $whereStatement = ' WHERE `rand_confirmed` >= {?user_min_confirmed?}';
207 default: // Invalid list mode
208 debug_report_bug(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestElement('mode')));
213 // Generate master query string
214 $sql = sprintf("SELECT `userid`,`email`,`emails_sent`,`mails_confirmed`,`emails_received`" . $MORE . " FROM `{?_MYSQL_PREFIX?}_user_data`" . $whereStatement . " ORDER BY `%s` ASC",
215 getRequestElement('sortby')
218 // Prepare SQL and run it
219 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
221 // Calculate page count (0.5 fixes a bug with page count)
222 if (getConfig('user_limit') == '0') {
223 setConfigEntry('user_limit', 100);
224 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
227 // Activate the extension please!
228 $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
230 if (!isGetRequestElementSet('page')) setGetRequestElement('page' , 1);
231 if (!isGetRequestElementSet('offset')) setGetRequestElement('offset', getConfig('user_limit'));
233 // Add limitation to SQL string and run him again
234 $sql .= ' LIMIT ' . (getRequestElement('offset') * getRequestElement('page') - getRequestElement('offset')) . ', ' . getRequestElement('offset');
235 $result = SQL_QUERY($sql, __FILE__, __LINE__);
237 // Are there some entries?
238 if (!SQL_HASZERONUMS($result_master)) {
239 // We have some (new?) registrations!
240 $templateContent['user_count'] = getTotalConfirmedUser();
242 // Sorting links and number of pages
243 $templateContent['sort_links'] = addSortLinks(getRequestElement('letter'), getRequestElement('sortby'));
244 $templateContent['num_pages'] = $numPages;
246 // Column with nickname when nickname extension is present
247 // @TODO Rewrite this into a filter
248 $templateContent['nickname_th'] = '';
249 if (isExtensionActive('nickname')) {
250 // Nickname extension found
251 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
256 while ($content = SQL_FETCHARRAY($result)) {
257 // Merge more data in
258 $content = merge_array($content, $templateContent);
260 // Get number of unconfirmed mails
261 $content['links'] = getTotalUnconfirmedMails($content['userid']);
262 if ($content['links'] > 0) {
263 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
266 // Set link to sent mails if present
267 if ($content['emails_sent'] > 0) {
268 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
272 $content['click_rate'] = '0';
273 if ($content['emails_received'] > 0) {
274 $content['click_rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
277 // Transfer data to array
278 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
279 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], '2');
280 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
281 $content['own_points'] = countSumTotalData($content['userid'], 'user_points', 'points') + countSumTotalData($content['userid'], 'user_points', 'order_points');
282 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
284 // If we have at least one referral, make it clickable to referral list
285 if ($content['refs'] > 0) {
286 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
289 // Is the extension 'country' installed?
290 // @TODO Rewrite this into a filter
291 if (isExtensionActive('country')) {
292 // Then overwrite country information
293 $content['country'] = generateCountryInfo($content['country_code']);
294 } elseif ($content['country'] == '') {
296 $content['country'] = '???';
299 // Load row template and switch colors
300 $OUT .= loadTemplate('admin_list_user_row', true, $content);
304 SQL_FREERESULT($result);
307 SQL_FREERESULT($result_master);
310 $content['rows'] = $OUT;
312 // Merge more data again
313 $content = merge_array($content, $templateContent);
315 // Load main template
316 loadTemplate('admin_list_user', false, $content);
318 // No one as registered so far! :-(
319 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
323 SQL_FREERESULT($result_master);