Lock reason now saved in DB, deleted accounts shall be locked for re-registering...
[mailer.git] / inc / modules / admin / what-list_user.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 08/18/2004 *
5  *                                                                      *
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  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 } elseif ((!EXT_IS_ACTIVE("user")) || (GET_EXT_VERSION("user") == "")) {
39         // Missing extension!
40         ADD_FATAL(sprintf(EXTENSION_PROBLEM_NOT_INSTALLED, "user"));
41         return;
42 }
43
44 // Add description as navigation point
45 ADD_DESCR("admin", __FILE__);
46
47 // Init title with "all accounts"
48 $listHeader = ADMIN_ALL_ACCOUNTS;
49 if (!empty($_GET['mode'])) {
50         // Set title according to the "mode"
51         $listHeader = constant(sprintf("ADMIN_LIST_%s_ACCOUNTS", strtoupper(SQL_ESCAPE($_GET['mode']))));
52 } // END - if
53
54 // Remember it
55 define('__TITLE', $listHeader);
56
57 // Init variables
58 $MORE = ", userid"; $colspan = "4";
59
60 // Add nickname if extension is found&active
61 if (EXT_IS_ACTIVE("nickname")) { $MORE = ", nickname"; }
62
63 // Add random confirmed if extension version matches
64 if (GET_EXT_VERSION("user") >= "0.3.4") {
65         // Add it...
66         $MORE .= ", rand_confirmed";
67
68         // Add lock reason?
69         if (GET_EXT_VERSION("user") >= "0.3.5") {
70                 // Add them...
71                 $MORE .= ", lock_reason, UNIX_TIMESTAMP(`lock_timestamp`) AS lock_timestamp";
72         } // END - if
73 } // END - if
74
75 // Init unset data (bad that we change $_GET here!)
76 if (empty($_GET['letter'])) { $_GET['letter'] = _ALL2;    }
77 if (empty($_GET['sortby'])) { $_GET['sortby'] = "userid"; }
78 if (empty($_GET['page']))   { $_GET['page']   = "1";      }
79
80 // Set base URL
81 $BASE = "[<A href=\"".URL."/modules.php?module=admin";
82
83 if (!empty($_GET['u_id'])) {
84         // Secure the user ID
85         $uid = bigintval($_GET['u_id']);
86
87         // Does the account exists?
88         $result_user = SQL_QUERY_ESC("SELECT 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."
89 FROM "._MYSQL_PREFIX."_user_data
90 WHERE userid=%s
91 LIMIT 1",
92                 array($uid), __FILE__, __LINE__);
93         if (SQL_NUMROWS($result_user) == 1) {
94                 // Account found!
95                 $DATA  = SQL_FETCHARRAY($result_user);
96
97                 // Get count/sum of refs, selected categories, unconfirmed mails
98                 $REFS  = GET_TOTAL_DATA($uid, "refsystem", "counter");
99                 $CATS  = GET_TOTAL_DATA($uid, "user_cats", "id", "userid", true);
100                 $LINKS = GET_TOTAL_DATA($uid, "user_links", "id", "userid", true);
101
102                 // Add links to the numbers
103                 if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;u_id=".$uid."\">".$LINKS."</A>]";
104                 if ($DATA['refid'] > 0) $DATA['refid'] = $BASE."&amp;what=list_user&amp;u_id=".$DATA['refid']."\">".$DATA['refid']."</A>]";
105                 if (empty($DATA['last_module'])) $DATA['last_module'] = "---";
106                 if ($REFS > 0) $REFS = $BASE."&amp;what=list_refs&amp;u_id=".$uid."\">".$REFS."</A>]";
107                 if ($CATS > 0) $CATS = $BASE."&amp;what=list_cats&amp;u_id=".$uid."\">".$CATS."</A>]";
108
109                 // Prepare data for template
110                 define('_BIRTHDAY', MAKE_DATETIME(mktime(0, 0, 0, $DATA['birth_month'], $DATA['birth_day'], $DATA['birth_year']), "3"));
111                 define('_REFS' , $REFS);
112                 define('_CATS' , $CATS);
113                 define('_LINKS', $LINKS);
114                 define('_ADMIN_LINKS', MEMBER_ACTION_LINKS($uid, $DATA['status']));
115                 $DATA['gender']            = TRANSLATE_GENDER($DATA['gender']);
116                 $DATA['email_link']        = CREATE_EMAIL_LINK($DATA['email'], "user_data");
117                 $DATA['status']            = TRANSLATE_STATUS($DATA['status']);
118                 $DATA['last_online']       = MAKE_DATETIME($DATA['last_online'], "0");
119                 $DATA['used_points']       = TRANSLATE_COMMA($DATA['used_points']);
120                 if ($DATA['emails_sent'] > 0) $DATA['emails_sent'] = $BASE."&amp;what=email_details&amp;u_id=".$uid."\">".TRANSLATE_COMMA($DATA['emails_sent'])."</A>]";
121                 $DATA['joined']            = MAKE_DATETIME($DATA['joined'], "0");
122                 $DATA['last_update']       = MAKE_DATETIME($DATA['last_update'], "0");
123                 $DATA['last_profile_sent'] = MAKE_DATETIME($DATA['last_profile_sent'], "0");
124                 $DATA['total']             = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "points"));
125                 $DATA['locked']            = TRANSLATE_COMMA(GET_TOTAL_DATA($uid, "user_points", "locked_points"));
126                 $DATA['lock_timestamp']    = MAKE_DATETIME($DATA['lock_timestamp'], "2");
127
128                 // Nickname inclusion?
129                 if (EXT_IS_ACTIVE("nickname")) {
130                         // Nickname not set or invalid? Then 
131                         if ((empty($DATA['nickname'])) || ($DATA['nickname'] == $uid)) $DATA['nickname'] = "---";
132                 } else {
133                         // Extension not found
134                         $DATA['nickname'] = EXT_NICKNAME_404;
135                 }
136
137                 // Is the user extension newer?
138                 if (GET_EXT_VERSION("user") >= "0.3.4") {
139                         // Then "translate" the number
140                         $DATA['rand_confirmed'] = TRANSLATE_COMMA($DATA['rand_confirmed']);
141                 } // END - if
142
143                 // Clickrate
144                 $DATA['click_rate'] = 0;
145                 if ($DATA['emails_received'] > 0) {
146                         $DATA['click_rate'] = TRANSLATE_COMMA($DATA['mails_confirmed'] / $DATA['emails_received'] * 100);
147                 } // END - if
148
149                 // "Translate" more data
150                 $DATA['mails_confirmed'] = TRANSLATE_COMMA($DATA['mails_confirmed']);
151                 $DATA['emails_received'] = TRANSLATE_COMMA($DATA['emails_received']);
152
153                 // Load user-details template
154                 LOAD_TEMPLATE("admin_user_details", false, $uid);
155         } else {
156                 // Account does not exist!
157                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MEMBER_404_1.$uid.ADMIN_MEMBER_404_2);
158         }
159
160         // Free the result
161         SQL_FREERESULT($result_user);
162 } else {
163         $whereStatement = "";
164         if (($_GET['letter'] != _ALL2) && ($_GET['letter'] != _OTHERS) && (!empty($_GET['letter']))) {
165                 // List only persons w
166                 $whereStatement = " WHERE family LIKE '".$_GET['letter']."%'";
167         } // END - if
168         if ($_GET['sortby'] == "family_name") $_GET['sortby'] = "family";
169
170         // Parse the mode parameter
171         if (isset($_GET['mode'])) {
172                 // Is a WHERE statement already there?
173                 if (!empty($whereStatement)) {
174                         // Then append the status column
175                         $whereStatement .= sprintf(" AND status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['mode']))));
176                 } else {
177                         // Start a new one
178                         $whereStatement = sprintf(" WHERE status='%s'", SQL_ESCAPE(strip_tags(strtoupper($_GET['mode']))));
179                 }
180         } // END - if
181
182         // Prepare SQL and run it
183         $SQL = "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 ".SQL_ESCAPE($_GET['sortby']);
184         $result_master = SQL_QUERY($SQL, __FILE__, __LINE__);
185
186         // Calculate page count (0.5 fixes a bug with page count)
187         if ($_CONFIG['user_limit'] == 0) {
188                 $_CONFIG['user_limit'] = 100;
189                 LOAD_TEMPLATE("admin_settings_saved", false, EXTENSION_WARNING_USER_LIMIT);
190         } // END - if
191
192         // Activate the extension please!
193         $PAGES = round(SQL_NUMROWS($result_master) / $_CONFIG['user_limit'] + 0.5);
194
195         if (empty($_GET['page']))   $_GET['page']   = "1";
196         if (empty($_GET['offset'])) $_GET['offset'] = $_CONFIG['user_limit'];
197
198         // Add limitation to SQL string and run him again
199         $SQL .= " LIMIT ".($_GET['offset'] * $_GET['page'] - $_GET['offset']).", ".$_GET['offset'];
200         $result = SQL_QUERY($SQL, __FILE__, __LINE__);
201
202         $result_user = SQL_QUERY("SELECT emails_sent FROM "._MYSQL_PREFIX."_user_data WHERE status='CONFIRMED'", __FILE__, __LINE__);
203         $user_count = SQL_NUMROWS($result_user);
204         SQL_FREERESULT($result_user);
205
206         if (SQL_NUMROWS($result_master) > 0) {
207                 // Free memory
208                 SQL_FREERESULT($result_master);
209
210                 // We have some (new?) registrations!
211                 define('__COLSPAN1'  , $colspan);
212                 define('__COLSPAN2'  , ($colspan + 2));
213                 define('__USER_CNT'  , $user_count);
214
215                 if ((function_exists('alpha')) && (function_exists('SortLinks'))) {
216                         define('__ALPHA_SORT', alpha($_GET['sortby'], $colspan, true));
217                         define('__SORT_LINKS', SortLinks($_GET['letter'], $_GET['sortby'], $colspan, true));
218                 } else {
219                         define('__ALPHA_SORT', "");
220                         define('__SORT_LINKS', "");
221                 }
222
223                 if ($PAGES > 1) {
224                         define('__PAGE_NAV', ADD_PAGENAV($PAGES, $_CONFIG['user_limit'], true, $colspan, true));
225                 } else {
226                         // No page navigation is required
227                         define('__PAGE_NAV', "");
228                 }
229
230                 // Column with nickname when nickname extension is present
231                 if (EXT_IS_ACTIVE("nickname"))
232                 {
233                         // Nickname extension found
234                         define('__NICKNAME_TH', "  <TD class=\"admin_title bottom2\" align=\"center\">".NICKNAME."</TD>");
235                 }
236                  else
237                 {
238                         // Not found
239                         define('__NICKNAME_TH', "");
240                 }
241
242                 // Load all users
243                 $SW = 2; $OUT = "";
244                 while ($content = SQL_FETCHARRAY($result)) {
245                         // Set refid link
246                         if ($content['refid'] > 0) $content['refid'] = ADMIN_USER_PROFILE_LINK($content['refid']);
247
248                         // Get number of unconfirmed mails
249                         $LINKS = GET_TOTAL_DATA($content['userid'], "user_links", "id", "userid", true);
250                         if ($LINKS > 0) $LINKS = $BASE."&amp;what=list_links&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($LINKS)."</A>]";
251
252                         // Set link to sent mails if present
253                         if ($content['emails_sent'] > 0) $content['emails_sent'] = $BASE."&amp;what=email_details&amp;u_id=".$content['userid']."\">".TRANSLATE_COMMA($content['emails_sent'])."</A>]";
254
255                         // Add nickname
256                         if (empty($content['nickname']) || $content['nickname'] == $content['userid']) $content['nickname'] = "---";
257
258                         // Calculate total points
259                         $pointsTotal = GET_TOTAL_DATA($content['userid'], "user_points", "points")  - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
260
261                         // Clickrate
262                         $clickRate = 0;
263                         if ($content['emails_received'] > 0) {
264                                 $clickRate = $content['mails_confirmed'] / $content['emails_received'] * 100;
265                         } // END - if
266
267                         // Transfer data to array
268                         $content['sw']     = $SW;
269                         $content['uid']    = ADMIN_USER_PROFILE_LINK($content['userid']);
270                         $content['gender'] = TRANSLATE_GENDER($content['gender']);
271                         $content['email']  = "[<A href=\"".CREATE_EMAIL_LINK($content['email'], "user_data")."\">".$content['email']."</A>]";
272                         $content['addr']   = $content['REMOTE_ADDR'];
273                         $content['status'] = TRANSLATE_STATUS($content['status']);
274                         $content['links']  = $LINKS;
275                         $content['alinks'] = MEMBER_ACTION_LINKS($content['userid'], $content['status']);
276                         $content['points'] = TRANSLATE_COMMA($pointsTotal);
277                         $content['rate']   = TRANSLATE_COMMA($clickRate);
278                         $content['locked'] = TRANSLATE_COMMA(GET_TOTAL_DATA($content['userid'], "user_points", "locked_points"));
279                         $content['lock_timestamp'] = MAKE_DATETIME($content['lock_timestamp'], "2");
280
281                         // Load row template and switch colors
282                         $OUT .= LOAD_TEMPLATE("admin_list_user_row", true, $content);
283                         $SW = 3 - $SW;
284                 } // END - while
285
286                 // Free memory
287                 SQL_FREERESULT($result);
288
289                 define('__USER_ROWS', $OUT);
290
291                 // Load main template
292                 LOAD_TEMPLATE("admin_list_user");
293
294                 // Free some memory
295                 SQL_FREERESULT($result_master);
296         } else {
297                 // No one as registered so far! :-(
298                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NO_NONE_REGISTERED);
299         }
300 }
301
302 //
303 ?>