Array element fixed
[mailer.git] / inc / modules / admin / what-lock_user.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/28/2003 *
4  * ===============                              Last change: 06/10/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-lock_user.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : Lock members                                     *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Mitglieder sperren                               *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 // Is a userid set?
48 if (isGetRequestElementSet('userid')) {
49         // Load user's data
50         $result_user = SQL_QUERY_ESC("SELECT status, gender, surname, family, email FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
51         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
52         $ACT = false;
53         if (SQL_NUMROWS($result_user) == 1) {
54                 // User found
55                 list($status, $gender, $surname, $family, $email) = SQL_FETCHROW($result_user);
56
57                 // Free result
58                 SQL_FREERESULT($result_user);
59
60                 // Is a lock reason set?
61                 if ((isPostRequestElementSet('lock')) && ($status != 'LOCKED')) {
62                         // Ok, lock the account!
63                         if (getExtensionVersion('user') >= '0.3.5') {
64                                 // Lock with reason
65                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='LOCKED',lock_reason='%s',lock_timestamp=NOW() WHERE `userid`=%s LIMIT 1",
66                                 array(postRequestElement('reason'), bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
67                         } else {
68                                 // Lock with no lock reason saved
69                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='LOCKED' WHERE `userid`=%s LIMIT 1",
70                                 array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
71                         }
72
73                         // Entry updated?
74                         if (SQL_AFFECTEDROWS() == 1) {
75                                 // Send an email to the user! In later version you can optionally switch this feature off
76                                 $message = loadEmailTemplate('lock-user', array('text' => postRequestElement('reason')), bigintval(getRequestElement('userid')));
77
78                                 // Send away...
79                                 sendEmail(bigintval(getRequestElement('userid')), ADMIN_LOCKED_SUBJ, $message);
80                         } // END - if
81
82                         // Prepare message
83                         $message = sprintf(getMessage('USER_ACCOUNT_LOCKED'), getRequestElement('userid'));
84                         $ACT = true;
85                 } elseif ((isPostRequestElementSet(('unlock'))) && ($status == 'LOCKED')) {
86                         // Ok, unlock the account!
87                         if (getExtensionVersion('user') >= '0.3.5') {
88                                 // Reset lock reason as well
89                                 SQL_QUERY_ESC("UPDATE
90         `{?_MYSQL_PREFIX?}_user_data`
91 SET
92         `status`='CONFIRMED',
93         `lock_reason`='',
94         `lock_timestamp`='0000-00-00 00:00'
95 WHERE
96         `userid`=%s
97 LIMIT 1",
98                                         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
99                         } else {
100                                 // No lock reason to reset
101                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='CONFIRMED' WHERE `userid`=%s LIMIT 1",
102                                         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
103                         }
104
105                         // Entry updated?
106                         if (SQL_AFFECTEDROWS() == 1) {
107                                 // Send an email to the user! In later version you can optionally switch this feature off
108                                 $message = loadEmailTemplate('unlock-user', array('text' => postRequestElement('reason')), bigintval(getRequestElement('userid')));
109
110                                 // Send away...
111                                 sendEmail(bigintval(getRequestElement('userid')), getMessage('ADMIN_UNLOCKED_SUBJ'), $message);
112                                 if (isExtensionActive('rallye')) {
113                                         addUserToReferalRallye(getRequestElement('userid'));
114                                 } // END - if
115                         } // END - if
116
117                         // Prepare message
118                         $message = sprintf(getMessage('USER_ACCOUNT_UNLOCKED'), getRequestElement('userid'));
119                         $ACT = true;
120                 } elseif (isPostRequestElementSet('del')) {
121                         // Delete the account
122                         $ACT = true;
123                         loadIncludeOnce('inc/modules/admin/what-del_user.php');
124                 } elseif (isPostRequestElementSet('no')) {
125                         // Do not lock him...
126                         $URL = adminCreateUserLink(getRequestElement('userid'));
127                 } else {
128                         // Load user data we need
129                         $result = SQL_QUERY_ESC("SELECT `email`, `surname`, `family` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `userid`=%s LIMIT 1",
130                                 array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
131
132                         // Entry found?
133                         if (SQL_NUMROWS($result) == 1) {
134                                 // Load data
135                                 $DATA = SQL_FETCHARRAY($result);
136
137                                 // Transfer data to constants for the template
138                                 // @TODO Rewrite these all constants
139                                 $content['email']   = generateEmailLink($DATA['email'], 'user_data');
140                                 $content['surname'] = $DATA['surname'];
141                                 $content['family']  = $DATA['family'];
142                                 $content['userid']  = bigintval(getRequestElement('userid'));
143
144                                 // Realy want to lock?
145                                 switch ($status) {
146                                         case 'CONFIRMED': // Yes, lock him down... ;-)
147                                                 $content['ok']     = 'lock';
148                                                 $content['header'] = sprintf(getMessage('ADMIN_HEADER_LOCK_ACCOUNT'), $content['userid']);
149                                                 $content['text']   = sprintf(getMessage('ADMIN_TEXT_LOCK_ACCOUNT'), $content['userid']);
150                                                 break;
151
152                                         case 'LOCKED': // Unlock the user
153                                                 $content['ok']     = $lock;
154                                                 $content['header'] = sprintf(getMessage('ADMIN_HEADER_UNLOCK_ACCOUNT'), $content['userid']);
155                                                 $content['text']   = sprintf(getMessage('ADMIN_TEXT_UNLOCK_ACCOUNT'), $content['userid']);
156                                                 break;
157
158                                         case 'UNCONFIRMED': // Unconfirmed accounts cannot be unlocked!
159                                                 $content['ok'] = 'del';
160                                                 $content['header'] = sprintf(getMessage('ADMIN_HEADER_DEL_ACCOUNT'), $content['userid']);
161                                                 $content['text']   = sprintf(getMessage('ADMIN_TEXT_DEL_ACCOUNT'), $content['userid']);
162                                                 break;
163                                 }
164
165                                 // Output form
166                                 loadTemplate('admin_lock_user', false, $content);
167                         } else {
168                                 // Account does not exists!
169                                 loadTemplate('admin_settings_saved', false, "<div class=\"admin_failed\">".sprintf(getMessage('ADMIN_MEMBER_404'), getRequestElement('userid'))."</div>");
170                         }
171
172                         // Free result
173                         SQL_FREERESULT($result);
174                 }
175
176                 // Is an URL set?
177                 if (!empty($URL)) {
178                         // Reload and die...
179                         redirectToUrl($URL);
180                 } elseif ($ACT) {
181                         // An action was performed...
182                         if (!empty($message)) {
183                                 loadTemplate('admin_settings_saved', false, "<div class=\"admin_green\">".$message."</div>");
184                         } else {
185                                 loadTemplate('admin_settings_saved', false, "<div class=\"admin_green\">".getMessage('ADMIN_USER_UPDATED')."</div>");
186                         }
187                 }
188         } else {
189                 // Account does not exists!
190                 loadTemplate('admin_settings_saved', false, "<div class=\"admin_failed\">".sprintf(getMessage('ADMIN_MEMBER_404'), getRequestElement('userid'))."</div>");
191         }
192 } else {
193         // List all users
194         addMemberSelectionBox();
195 }
196
197 //
198 ?>