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__);
46 if ((!isExtensionInstalled('user')) || (!isExtensionActive('user'))) {
48 displayMessage(generateExtensionInactiveNotInstalledMessage('user'));
56 // Add nickname if extension is found&active
57 // @TODO Rewrite these if-blocks in a filter
58 if (isExtensionActive('nickname')) {
60 $MORE .= ", `nickname`";
62 $MORE .= ", `userid`";
65 // Add random confirmed if extension version matches
66 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
68 $MORE .= ", `rand_confirmed`";
71 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
73 $MORE .= ", `lock_reason`, UNIX_TIMESTAMP(`lock_timestamp`) AS `lock_timestamp`";
77 // Is the extension 'country' installed?
78 if (isExtensionActive('country')) {
80 $MORE .= ", `country_code`";
83 $MORE .= ", `country`";
87 if (!isGetRequestParameterSet('letter')) { setGetRequestParameter('letter', ''); }
88 if (!isGetRequestParameterSet('sortby')) { setGetRequestParameter('sortby', 'userid'); }
89 if (!isGetRequestParameterSet('page')) { setGetRequestParameter('page' , 1); }
92 $base = '[<a href="{%url=modules.php?module=admin';
94 if (isGetRequestParameterSet('userid')) {
96 $userid = bigintval(getRequestParameter('userid'));
98 // Does the account exists?
99 $result_user = SQL_QUERY_ESC("SELECT
100 `userid`, `gender`, `surname`, `family`, `street_nr`, `zip`, `city`, `country`, `email`, `birth_day`, `birth_month`, `birth_year`, `max_mails`, `receive_mails`, `refid`, `status`, `REMOTE_ADDR`, `last_online`, `last_module`, `ref_clicks`, `total_logins`, `used_points`, `emails_sent`, `joined`, `last_update`, `last_profile_sent`, `notified`, `ref_payout`, `emails_received`, `mails_confirmed`".$MORE."
102 `{?_MYSQL_PREFIX?}_user_data`
106 array($userid), __FILE__, __LINE__);
109 if (SQL_NUMROWS($result_user) == 1) {
111 $content = SQL_FETCHARRAY($result_user);
113 // Get count/sum of refs, selected categories, unconfirmed mails
114 $content['refs'] = countSumTotalData($userid, 'refsystem' , 'counter');
115 $content['cats'] = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
116 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
118 // Add links to the numbers
119 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
120 if (isValidUserId($content['refid'])) $content['refid'] = $base . '&what=list_user&userid=' . $content['refid'] . '%}">'.$content['refid'] . '</a>]';
121 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
122 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">{%pipe,translateComma=' . $content['cats'] . '%}</a>]';
124 // Calculate timestamp for birthday
125 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
127 // Is this above zero?
130 $content['birthday'] = generateDateTime($stamp, 3);
132 // Zero or below so set zero!
133 $content['birthday'] = generateDateTime(0, 3);
136 // Prepare data for template
137 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
138 $content['last_online'] = generateDateTime($content['last_online'], 0);
139 $content['joined'] = generateDateTime($content['joined'], 0);
140 $content['last_update'] = generateDateTime($content['last_update'], 0);
141 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
142 $content['total_points'] = getTotalPoints($content['userid']);
143 $content['locked_points'] = countSumTotalData($userid, 'user_points', 'locked_points') + countSumTotalData($userid, 'user_points', 'locked_order_points');
144 $content['own_points'] = countSumTotalData($userid, 'user_points', 'points') + countSumTotalData($userid, 'user_points', 'order_points');
145 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
146 $content['nickname'] = '{--EXT_NICKNAME_404--}';
148 // Link to email_details if some are sent
149 if ($content['emails_sent'] > 0) {
150 $content['emails_sent'] = $base . '&what=email_details&userid=' . $userid . '%}">}{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
153 // Nickname inclusion?
154 // @TODO Rewrite these to filters
155 if (isExtensionInstalled('nickname')) {
156 $content['nickname'] = getNickname($content['userid']);
160 $content['click_rate'] = '0';
161 if ($content['emails_received'] > 0) {
162 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
165 // Is the extension 'country' installed?
166 if (isExtensionActive('country')) {
167 // Then overwrite country information
168 $content['country'] = generateCountryInfo($content['country_code']);
169 } elseif ($content['country'] == '0') {
171 $content['country'] = '???';
175 $content['userid'] = $userid;
177 // Load user-details template
178 loadTemplate('admin_user_details', false, $content);
180 // Account does not exist!
181 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', $userid));
185 SQL_FREERESULT($result_user);
187 $whereStatement = '';
188 if (isGetRequestParameterSet('letter')) {
189 // List only persons w
190 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
193 // Parse the status or mode parameter
194 if (isGetRequestParameterSet('status')) {
195 // Is a WHERE statement already there?
196 if (!empty($whereStatement)) {
197 // Then append the status column
198 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
201 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
203 } elseif (isGetRequestParameterSet('mode')) {
204 // Choose what we need to list
205 switch (getRequestParameter('mode')) {
206 case 'norefs': // Users w/o refs
207 if (!empty($whereStatement)) {
209 $whereStatement .= " AND `refid`=0";
211 // Add WHERE statement
212 $whereStatement = " WHERE `refid`=0";
216 default: // Invalid list mode
217 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
222 // Generate master query string
223 $sql = sprintf("SELECT `userid`, `gender`, `surname`, `family`, `email`, `REMOTE_ADDR`, `refid`, `status`, `emails_sent`, `mails_confirmed`, `emails_received`" . $MORE . " FROM `{?_MYSQL_PREFIX?}_user_data`" . $whereStatement . " ORDER BY `%s` ASC",
224 getRequestParameter('sortby')
227 // Prepare SQL and run it
228 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
230 // Calculate page count (0.5 fixes a bug with page count)
231 if (getConfig('user_limit') == '0') {
232 setConfigEntry('user_limit', 100);
233 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
236 // Activate the extension please!
237 $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
239 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page' , 1);
240 if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
242 // Add limitation to SQL string and run him again
243 $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
244 $result = SQL_QUERY($sql, __FILE__, __LINE__);
246 // Are there some entries?
247 if (!SQL_HASZERONUMS($result_master)) {
248 // We have some (new?) registrations!
249 $templateContent['colspan2'] = ($colspan + 2);
250 $templateContent['user_count'] = getTotalConfirmedUser();
253 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
254 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
255 $templateContent['page_nav'] = '';
258 $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
261 // Column with nickname when nickname extension is present
262 // @TODO Rewrite this into a filter
263 $templateContent['nickname_th'] = '';
264 if (isExtensionActive('nickname')) {
265 // Nickname extension found
266 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
271 while ($content = SQL_FETCHARRAY($result)) {
272 // Merge more data in
273 $content = merge_array($content, $templateContent);
275 // Get number of unconfirmed mails
276 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
277 if ($content['links'] > 0) {
278 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
281 // Set link to sent mails if present
282 if ($content['emails_sent'] > 0) {
283 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
287 $content['nickname'] = '{--EXT_NICKNAME_404--}';
288 if (isExtensionInstalled('nickname')) {
289 $content['nickname'] = getNickname($content['userid']);
293 $content['rate'] = '0';
294 if ($content['emails_received'] > 0) {
295 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
298 // Transfer data to array
299 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
300 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
301 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
302 $content['own_points'] = countSumTotalData($content['userid'], 'user_points', 'points') + countSumTotalData($content['userid'], 'user_points', 'order_points');
303 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
305 // If we have at least one referal, make it clickable to referal list
306 if ($content['refs'] > 0) {
307 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
310 // Is the extension 'country' installed?
311 // @TODO Rewrite this into a filter
312 if (isExtensionActive('country')) {
313 // Then overwrite country information
314 $content['country'] = generateCountryInfo($content['country_code']);
315 } elseif ($content['country'] == '') {
317 $content['country'] = '???';
320 // Load row template and switch colors
321 $OUT .= loadTemplate('admin_list_user_row', true, $content);
325 SQL_FREERESULT($result);
328 SQL_FREERESULT($result_master);
331 $content['rows'] = $OUT;
333 // Merge more data again
334 $content = merge_array($content, $templateContent);
336 // Load main template
337 loadTemplate('admin_list_user', false, $content);
339 // No one as registered so far! :-(
340 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
344 SQL_FREERESULT($result_master);