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://www.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__);
51 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
53 $MORE .= ", UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`";
56 // Is the extension 'country' installed?
57 if (isExtensionActive('country')) {
59 $MORE .= ", `country_code`";
62 $MORE .= ", `country`";
66 if (!isGetRequestParameterSet('letter')) { setGetRequestParameter('letter', ''); }
67 if (!isGetRequestParameterSet('sortby')) { setGetRequestParameter('sortby', 'userid'); }
68 if (!isGetRequestParameterSet('page')) { setGetRequestParameter('page' , 1); }
71 $base = '[<a href="{%url=modules.php?module=admin';
73 if (isGetRequestParameterSet('userid')) {
75 $userid = bigintval(getRequestParameter('userid'));
77 // Does the account exists?
78 $result_user = SQL_QUERY_ESC("SELECT
79 `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."
81 `{?_MYSQL_PREFIX?}_user_data`
85 array($userid), __FILE__, __LINE__);
88 if (SQL_NUMROWS($result_user) == 1) {
90 $content = SQL_FETCHARRAY($result_user);
92 // Get count/sum of refs, selected categories, unconfirmed mails
93 $content['refs'] = countSumTotalData($userid, 'refsystem' , 'counter');
94 $content['cats'] = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
95 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
97 // Add links to the numbers
98 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
99 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
100 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
102 // Calculate timestamp for birthday
103 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
105 // Is this above zero?
108 $content['birthday'] = generateDateTime($stamp, 3);
110 // Zero or below so set zero!
111 $content['birthday'] = generateDateTime(0, 3);
114 // Prepare data for template
115 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
116 $content['last_online'] = generateDateTime($content['last_online'], 0);
117 $content['joined'] = generateDateTime($content['joined'], 0);
118 $content['last_update'] = generateDateTime($content['last_update'], 0);
119 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
120 $content['total_points'] = getTotalPoints($content['userid']);
121 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
123 // Prepare array for filter
125 'userid' => $content['userid'],
129 // Run the filter chain
130 $data = runFilterChain('get_own_points', $data);
133 $content['own_points'] = $data['points'];
134 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
136 // Link to email_details if some are sent
137 if ($content['emails_sent'] > 0) {
138 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
142 $content['click_rate'] = '0';
143 if ($content['emails_received'] > 0) {
144 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
147 // Is the extension 'country' installed?
148 if (isExtensionActive('country')) {
149 // Then overwrite country information
150 $content['country'] = generateCountryInfo($content['country_code']);
151 } elseif ($content['country'] == '0') {
153 $content['country'] = '???';
157 $content['userid'] = $userid;
159 // Load user-details template
160 loadTemplate('admin_user_details', false, $content);
162 // Account does not exist!
163 displayMessage('{%message,ADMIN_MEMBER_404=' . $userid . '%}');
167 SQL_FREERESULT($result_user);
169 $whereStatement = '';
170 if (isGetRequestParameterSet('letter')) {
171 // List only persons w
172 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
175 // Parse the status or mode parameter
176 if (isGetRequestParameterSet('status')) {
177 // Is a WHERE statement already there?
178 if (!empty($whereStatement)) {
179 // Then append the status column
180 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
183 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
185 } elseif (isGetRequestParameterSet('mode')) {
186 // Choose what we need to list
187 switch (getRequestParameter('mode')) {
188 case 'norefs': // Users w/o refs
189 if (!empty($whereStatement)) {
191 $whereStatement .= " AND `refid`=0";
193 // Add WHERE statement
194 $whereStatement = " WHERE `refid`=0";
198 case 'random_refid': // Users available for random referal id
199 if (!empty($whereStatement)) {
201 $whereStatement .= " AND `rand_confirmed` >= {?user_min_confirmed?}";
203 // Add WHERE statement
204 $whereStatement = " WHERE `rand_confirmed` >= {?user_min_confirmed?}";
208 default: // Invalid list mode
209 debug_report_bug(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
214 // Generate master query string
215 $sql = sprintf("SELECT `userid`, `email`, `emails_sent`, `mails_confirmed`, `emails_received`" . $MORE . " FROM `{?_MYSQL_PREFIX?}_user_data`" . $whereStatement . " ORDER BY `%s` ASC",
216 getRequestParameter('sortby')
219 // Prepare SQL and run it
220 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
222 // Calculate page count (0.5 fixes a bug with page count)
223 if (getConfig('user_limit') == '0') {
224 setConfigEntry('user_limit', 100);
225 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
228 // Activate the extension please!
229 $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
231 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page' , 1);
232 if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
234 // Add limitation to SQL string and run him again
235 $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
236 $result = SQL_QUERY($sql, __FILE__, __LINE__);
238 // Are there some entries?
239 if (!SQL_HASZERONUMS($result_master)) {
240 // We have some (new?) registrations!
241 $templateContent['colspan2'] = ($colspan + 2);
242 $templateContent['user_count'] = getTotalConfirmedUser();
245 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
246 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
247 $templateContent['page_nav'] = '';
250 $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
253 // Column with nickname when nickname extension is present
254 // @TODO Rewrite this into a filter
255 $templateContent['nickname_th'] = '';
256 if (isExtensionActive('nickname')) {
257 // Nickname extension found
258 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
263 while ($content = SQL_FETCHARRAY($result)) {
264 // Merge more data in
265 $content = merge_array($content, $templateContent);
267 // Get number of unconfirmed mails
268 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
269 if ($content['links'] > 0) {
270 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
273 // Set link to sent mails if present
274 if ($content['emails_sent'] > 0) {
275 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
279 $content['rate'] = '0';
280 if ($content['emails_received'] > 0) {
281 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
284 // Transfer data to array
285 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
286 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
287 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
288 $content['own_points'] = countSumTotalData($content['userid'], 'user_points', 'points') + countSumTotalData($content['userid'], 'user_points', 'order_points');
289 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
291 // If we have at least one referal, make it clickable to referal list
292 if ($content['refs'] > 0) {
293 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
296 // Is the extension 'country' installed?
297 // @TODO Rewrite this into a filter
298 if (isExtensionActive('country')) {
299 // Then overwrite country information
300 $content['country'] = generateCountryInfo($content['country_code']);
301 } elseif ($content['country'] == '') {
303 $content['country'] = '???';
306 // Load row template and switch colors
307 $OUT .= loadTemplate('admin_list_user_row', true, $content);
311 SQL_FREERESULT($result);
314 SQL_FREERESULT($result_master);
317 $content['rows'] = $OUT;
319 // Merge more data again
320 $content = merge_array($content, $templateContent);
322 // Load main template
323 loadTemplate('admin_list_user', false, $content);
325 // No one as registered so far! :-(
326 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
330 SQL_FREERESULT($result_master);