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 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2009 by Roland Haeder *
21 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 if ((!isExtensionInstalled('user')) || (!isExtensionActive('user'))) {
50 loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('user'));
58 // Add nickname if extension is found&active
59 // @TODO Rewrite these if-blocks in a filter
60 if (isExtensionActive('nickname')) {
62 $MORE .= ", `nickname`";
64 $MORE .= ", `userid`";
67 // Add random confirmed if extension version matches
68 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
70 $MORE .= ", `rand_confirmed`";
73 if (isExtensionInstalledAndNewer('user', '0.3.5')) {
75 $MORE .= ", `lock_reason`, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
79 // Is the extension 'country' installed?
80 if (isExtensionActive('country')) {
82 $MORE .= ", `country_code`";
85 $MORE .= ", `country`";
89 if (!isGetRequestParameterSet('letter')) { setGetRequestParameter('letter', getMessage('_ALL2')); }
90 if (!isGetRequestParameterSet('sortby')) { setGetRequestParameter('sortby', 'userid'); }
91 if (!isGetRequestParameterSet('page')) { setGetRequestParameter('page' , 1); }
94 $base = '[<a href="{%url=modules.php?module=admin';
96 if (isGetRequestParameterSet('userid')) {
98 $userid = bigintval(getRequestParameter('userid'));
100 // Does the account exists?
101 $result_user = SQL_QUERY_ESC("SELECT
102 `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."
104 `{?_MYSQL_PREFIX?}_user_data`
108 array($userid), __FILE__, __LINE__);
111 if (SQL_NUMROWS($result_user) == 1) {
113 $content = SQL_FETCHARRAY($result_user);
115 // Get count/sum of refs, selected categories, unconfirmed mails
116 $content['refs'] = countSumTotalData($userid, 'refsystem' , 'counter');
117 $content['cats'] = countSumTotalData($userid, 'user_cats' , 'id', 'userid', true);
118 $content['links'] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
120 // Add links to the numbers
121 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $userid . '%}">' . $content['links'] . '</a>]';
122 if ($content['refid'] > 0) $content['refid'] = $base . '&what=list_user&userid=' . $content['refid'] . '%}">'.$content['refid'] . '</a>]';
123 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $userid . '%}">' . $content['refs'] . '</a>]';
124 if ($content['cats'] > 0) $content['cats'] = $base . '&what=list_cats&userid=' . $userid . '%}">' . $content['cats'] . '</a>]';
127 if (empty($content['last_module'])) $content['last_module'] = '---';
129 // Calculate timestamp for birthday
130 $stamp = mktime(0, 0, 0, $content['birth_month'], $content['birth_day'], $content['birth_year']);
132 // Is this above zero?
135 $content['birthday'] = generateDateTime($stamp, 3);
137 // Zero or below so set zero!
138 $content['birthday'] = generateDateTime(0, 3);
141 // Prepare data for template
142 $content['admin_links'] = generateMemberAdminActionLinks($userid, $content['status']);
143 $content['gender'] = translateGender($content['gender']);
144 $content['email_link'] = generateEmailLink($content['email'], 'user_data');
145 $content['status'] = translateUserStatus($content['status']);
146 $content['last_online'] = generateDateTime($content['last_online'], 0);
147 $content['used_points'] = translateComma($content['used_points']);
148 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $userid . '%}">' . translateComma($content['emails_sent']) . '</a>]';
149 $content['joined'] = generateDateTime($content['joined'], 0);
150 $content['last_update'] = generateDateTime($content['last_update'], 0);
151 $content['last_profile_sent'] = generateDateTime($content['last_profile_sent'], 0);
152 $content['total'] = translateComma(countSumTotalData($userid, 'user_points', 'points'));
153 $content['locked'] = translateComma(countSumTotalData($userid, 'user_points', 'locked_points'));
154 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
156 // Is the lock reason not set?
157 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
159 // Nickname inclusion?
160 // @TODO Rewrite these to filters
161 if (isExtensionActive('nickname')) {
162 // Nickname not set or invalid? Then
163 if ((empty($content['nickname'])) || ($content['nickname'] == $userid)) $content['nickname'] = '---';
165 // Extension not found
166 $content['nickname'] = getMessage('EXT_NICKNAME_404');
169 // Is the user extension newer?
170 if (isExtensionInstalledAndNewer('user', '0.3.4')) {
171 // Then "translate" the number
172 $content['rand_confirmed'] = translateComma($content['rand_confirmed']);
176 $content['click_rate'] = '0';
177 if ($content['emails_received'] > 0) {
178 $content['click_rate'] = translateComma($content['mails_confirmed'] / $content['emails_received'] * 100);
181 // "Translate" more data
182 $content['mails_confirmed'] = translateComma($content['mails_confirmed']);
183 $content['emails_received'] = translateComma($content['emails_received']);
185 // Is the extension 'country' installed?
186 if (isExtensionActive('country')) {
187 // Then overwrite country information
188 $content['country'] = generateCountryInfo($content['country_code']);
189 } elseif ($content['country'] == '0') {
191 $content['country'] = '???';
195 $content['userid'] = $userid;
197 // Load user-details template
198 loadTemplate('admin_user_details', false, $content);
200 // Account does not exist!
201 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_MEMBER_404', $userid));
205 SQL_FREERESULT($result_user);
207 $whereStatement = '';
208 if ((getRequestParameter('letter') != getMessage('_ALL2')) && (getRequestParameter('letter') != getMessage('_OTHERS')) && (isGetRequestParameterSet('letter'))) {
209 // List only persons w
210 $whereStatement = " WHERE `family` LIKE '".getRequestParameter('letter') . "%'";
213 // Parse the status or mode parameter
214 if (isGetRequestParameterSet(('status'))) {
215 // Is a WHERE statement already there?
216 if (!empty($whereStatement)) {
217 // Then append the status column
218 $whereStatement .= sprintf(" AND `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
221 $whereStatement = sprintf(" WHERE `status`='%s'", SQL_ESCAPE(secureString(strtoupper(getRequestParameter('status')))));
223 } elseif (isGetRequestParameterSet('mode')) {
224 // Choose what we need to list
225 switch (getRequestParameter('mode')) {
226 case 'norefs': // Users w/o refs
227 if (!empty($whereStatement)) {
229 $whereStatement .= " AND `refid`=0";
231 // Add WHERE statement
232 $whereStatement = " WHERE `refid`=0";
236 default: // Invalid list mode
237 logDebugMessage(__FILE__, __LINE__, sprintf("Invalid list mode %s detected.", getRequestParameter('mode')));
242 // Generate master query string
243 $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",
244 getRequestParameter('sortby')
247 // Prepare SQL and run it
248 $result_master = SQL_QUERY($sql, __FILE__, __LINE__);
250 // Calculate page count (0.5 fixes a bug with page count)
251 if (getConfig('user_limit') == '0') {
252 setConfigEntry('user_limit', 100);
253 loadTemplate('admin_settings_saved', false, getMessage('EXTENSION_WARNING_USER_LIMIT'));
256 // Activate the extension please!
257 $PAGES = round(SQL_NUMROWS($result_master) / getConfig('user_limit') + 0.5);
259 if (!isGetRequestParameterSet('page')) setGetRequestParameter('page' , 1);
260 if (!isGetRequestParameterSet('offset')) setGetRequestParameter('offset', getConfig('user_limit'));
262 // Add limitation to SQL string and run him again
263 $sql .= " LIMIT ".(getRequestParameter('offset') * getRequestParameter('page') - getRequestParameter('offset')).", ".getRequestParameter('offset');
264 $result = SQL_QUERY($sql, __FILE__, __LINE__);
266 // Count all confirmed users
267 $user_count = countSumTotalData('CONFIRMED','user_data','userid','status',true);
269 // Are there some entries?
270 if (SQL_NUMROWS($result_master) > 0) {
271 // We have some (new?) registrations!
272 define('__COLSPAN2' , ($colspan + 2));
273 define('__USER_CNT' , $user_count);
276 define('__ALPHA_SORT', alpha(getRequestParameter('sortby'), $colspan, true));
277 define('__SORT_LINKS', addSortLinks(getRequestParameter('letter'), getRequestParameter('sortby'), $colspan, true));
280 define('__PAGE_NAV', addPageNavigation($PAGES, getConfig('user_limit'), true, $colspan, true));
282 // No page navigation is required
283 define('__PAGE_NAV', '');
286 // Column with nickname when nickname extension is present
287 // @TODO Rewrite this into a filter
288 if (isExtensionActive('nickname')) {
289 // Nickname extension found
290 define('__NICKNAME_TH', " <td class=\"header_column bottom\" align=\"center\">{--NICKNAME--}</td>");
293 define('__NICKNAME_TH', '');
298 while ($content = SQL_FETCHARRAY($result)) {
300 if ($content['refid'] > 0) $content['refid'] = generateUserProfileLink($content['refid']);
302 // Get number of unconfirmed mails
303 $content['links'] = countSumTotalData($content['userid'], 'user_links', 'id', 'userid', true);
304 if ($content['links'] > 0) $content['links'] = $base . '&what=list_links&userid=' . $content['userid'] . '%}">' . translateComma($content['links']) . '</a>]';
306 // Set link to sent mails if present
307 if ($content['emails_sent'] > 0) $content['emails_sent'] = $base . '&what=email_details&userid=' . $content['userid'] . '%}">' . translateComma($content['emails_sent']) . '</a>]';
310 if ((empty($content['nickname'])) || ($content['nickname'] == $content['userid'])) $content['nickname'] = '---';
312 // Calculate total points
313 $content['points'] = countSumTotalData($content['userid'], 'user_points', 'points') - countSumTotalData($content['userid'], 'user_data', 'used_points');
316 $content['rate'] = '0';
317 if ($content['emails_received'] > 0) {
318 $content['rate'] = $content['mails_confirmed'] / $content['emails_received'] * 100;
321 // Transfer data to array
322 $content['sw'] = $SW;
323 $content['userid_link'] = generateUserProfileLink($content['userid']);
324 $content['gender'] = translateGender($content['gender']);
325 $content['email'] = '[<a href="' . generateEmailLink($content['email'], 'user_data') . '">' . $content['email'] . '</a>]';
326 $content['alinks'] = generateMemberAdminActionLinks($content['userid'], $content['status']);
327 $content['points'] = translateComma($content['points']);
328 $content['rate'] = translateComma($content['rate']);
329 $content['locked'] = translateComma(countSumTotalData($content['userid'], 'user_points', 'locked_points'));
330 $content['lock_timestamp'] = generateDateTime($content['lock_timestamp'], 2);
331 $content['status'] = translateUserStatus($content['status']);
332 $content['refs'] = countSumTotalData($content['userid'], 'user_refs', 'id', 'userid', true);
334 // If we have at least one referal, make it clickable to referal list
335 if ($content['refs'] > 0) $content['refs'] = $base . '&what=list_refs&userid=' . $content['userid'] . '%}">' . $content['refs'] . '</a>]';
337 // Is the lock reason not set?
338 if (!isset($content['lock_reason'])) $content['lock_reason'] = '---';
340 // Is the extension 'country' installed?
341 // @TODO Rewrite this into a filter
342 if (isExtensionActive('country')) {
343 // Then overwrite country information
344 $content['country'] = generateCountryInfo($content['country_code']);
345 } elseif ($content['country'] == '') {
347 $content['country'] = '???';
350 // Load row template and switch colors
351 $OUT .= loadTemplate('admin_list_user_row', true, $content);
356 SQL_FREERESULT($result);
359 SQL_FREERESULT($result_master);
362 $content['rows'] = $OUT;
364 // Init title with "all accounts"
365 $content['title'] = getMessage('ADMIN_ALL_ACCOUNTS');
366 if (isGetRequestParameterSet(('status'))) {
367 // Set title according to the 'status'
368 $content['title'] = getMessage(sprintf("ADMIN_LIST_STATUS_%s_ACCOUNTS", strtoupper(getRequestParameter(('status')))));
369 } elseif (isGetRequestParameterSet('mode')) {
370 // Set title according to the "mode"
371 $content['title'] = getMessage(sprintf("ADMIN_LIST_MODE_%s_ACCOUNTS", strtoupper(getRequestParameter('mode'))));
374 // Load main template
375 loadTemplate('admin_list_user', false, $content);
377 // No one as registered so far! :-(
378 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_NO_NONE_REGISTERED'));
382 SQL_FREERESULT($result_master);