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($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
145 // Prepare array for filter
147 'userid' => $content['userid'],
151 // Run the filter chain
152 $data = runFilterChain('get_own_points', $data);
155 $content['own_points'] = $data['points'];
156 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
157 $content['nickname'] = '{--EXT_NICKNAME_404--}';
159 // Link to email_details if some are sent
160 if ($content['emails_sent'] > 0) {
161 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">}{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
164 // Nickname inclusion?
165 // @TODO Rewrite these to filters
166 if (isExtensionInstalled('nickname')) {
167 $content['nickname'] = getNickname($content['userid']);
171 $content['click_rate'] = '0';
172 if ($content['emails_received'] > 0) {
173 $content['click_rate'] = ($content['mails_confirmed'] / $content['emails_received'] * 100);
176 // Is the extension 'country' installed?
177 if (isExtensionActive('country')) {
178 // Then overwrite country information
179 $content['country'] = generateCountryInfo($content['country_code']);
180 } elseif ($content['country'] == '0') {
182 $content['country'] = '???';
186 $content['userid'] = $userid;
188 // Load user-details template
189 loadTemplate('admin_user_details', false, $content);
191 // Account does not exist!
192 displayMessage(getMaskedMessage('ADMIN_MEMBER_404', $userid));
196 SQL_FREERESULT($result_user);
198 $whereStatement = '';
199 if (isGetRequestParameterSet('letter')) {
200 // List only persons w
201 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%%'";
204 // Parse the status or mode parameter
205 if (isGetRequestParameterSet('status')) {
206 // Is a WHERE statement already there?
207 if (!empty($whereStatement)) {
208 // Then append the status column
209 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
212 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
214 } elseif (isGetRequestParameterSet('mode')) {
215 // Choose what we need to list
216 switch (getRequestParameter('mode')) {
217 case 'norefs': // Users w/o refs
218 if (!empty($whereStatement)) {
220 $whereStatement .= " AND `refid`=0";
222 // Add WHERE statement
223 $whereStatement = " WHERE `refid`=0";
227 default: // Invalid list mode
228 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
233 // Generate master query string
234 $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",
235 getRequestParameter('sortby')
238 // Prepare SQL and run it
239 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
241 // Calculate page count (0.5 fixes a bug with page count)
242 if (getConfig('user_limit') == '0') {
243 setConfigEntry('user_limit', 100);
244 displayMessage('{--EXTENSION_WARNING_USER_LIMIT--}');
247 // Activate the extension please!
248 $numPages = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
250 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page' , 1);
251 if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
253 // Add limitation to SQL string and run him again
254 $sql .= ' LIMIT ' . (getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')) . ', ' . getRequestParameter('offset');
255 $result = SQL_QUERY($sql, __FILE__, __LINE__);
257 // Are there some entries?
258 if (!SQL_HASZERONUMS($result_master)) {
259 // We have some (new?) registrations!
260 $templateContent['colspan2'] = ($colspan + 2);
261 $templateContent['user_count'] = getTotalConfirmedUser();
264 $templateContent['alpha_sort'] = alpha(getRequestParameter('sortby'), ($colspan + 1), true);
265 $templateContent['sort_links'] = addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), ($colspan + 1), true);
266 $templateContent['page_nav'] = '';
269 $templateContent['page_nav'] = addPageNavigation($numPages, getConfig('user_limit'), true, $colspan, true);
272 // Column with nickname when nickname extension is present
273 // @TODO Rewrite this into a filter
274 $templateContent['nickname_th'] = '';
275 if (isExtensionActive('nickname')) {
276 // Nickname extension found
277 $templateContent['nickname_th'] = '<td class="header_column bottom" align="center">{--NICKNAME--}</td>';
282 while ($content = SQL_FETCHARRAY($result)) {
283 // Merge more data in
284 $content = merge_array($content, $templateContent);
286 // Get number of unconfirmed mails
287 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
288 if ($content['links'] > 0) {
289 $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['links'] . '%}</a>]';
292 // Set link to sent mails if present
293 if ($content['emails_sent'] > 0) {
294 $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['emails_sent'] . '%}</a>]';
298 $content['nickname'] = '{--EXT_NICKNAME_404--}';
299 if (isExtensionInstalled('nickname')) {
300 $content['nickname'] = getNickname($content['userid']);
304 $content['rate'] = '0';
305 if ($content['emails_received'] > 0) {
306 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
309 // Transfer data to array
310 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
311 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
312 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
313 $content['own_points'] = countSumTotalData($content['userid'], 'user_points', 'points') + countSumTotalData($content['userid'], 'user_points', 'order_points');
314 $content['locked_points'] = countSumTotalData($content['userid'], 'user_points', 'locked_points') + countSumTotalData($content['userid'], 'user_points', 'locked_order_points');
316 // If we have at least one referal, make it clickable to referal list
317 if ($content['refs'] > 0) {
318 $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">{%pipe,translateComma=' . $content['refs'] . '%}</a>]';
321 // Is the extension 'country' installed?
322 // @TODO Rewrite this into a filter
323 if (isExtensionActive('country')) {
324 // Then overwrite country information
325 $content['country'] = generateCountryInfo($content['country_code']);
326 } elseif ($content['country'] == '') {
328 $content['country'] = '???';
331 // Load row template and switch colors
332 $OUT .= loadTemplate('admin_list_user_row', true, $content);
336 SQL_FREERESULT($result);
339 SQL_FREERESULT($result_master);
342 $content['rows'] = $OUT;
344 // Merge more data again
345 $content = merge_array($content, $templateContent);
347 // Load main template
348 loadTemplate('admin_list_user', false, $content);
350 // No one as registered so far! :-(
351 displayMessage('{--ADMIN_NO_NONE_REGISTERED--}');
355 SQL_FREERESULT($result_master);