New functions introduced, several rewrites:
[mailer.git] / inc / modules / admin / what-lock_user.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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         // Action not performed by default
50         $ACT = false;
51
52         // Load user's data
53         if (fetchUserData(getRequestElement('userid'))) {
54                 // Is a lock reason set?
55                 if ((isPostRequestElementSet('lock')) && (getUserData('status') != 'LOCKED')) {
56                         // Ok, lock the account!
57                         if (getExtensionVersion('user') >= '0.3.5') {
58                                 // Lock with reason
59                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='LOCKED', `lock_reason`='%s', `lock_timestamp`=NOW() WHERE `userid`=%s LIMIT 1",
60                                         array(postRequestElement('reason'), bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
61                         } else {
62                                 // Lock with no lock reason saved
63                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='LOCKED' WHERE `userid`=%s LIMIT 1",
64                                         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
65                         }
66
67                         // Entry updated?
68                         if (SQL_AFFECTEDROWS() == 1) {
69                                 // Send an email to the user! In later version you can optionally switch this feature off
70                                 $message = loadEmailTemplate('lock-user', array('text' => postRequestElement('reason')), bigintval(getRequestElement('userid')));
71
72                                 // Send away...
73                                 sendEmail(bigintval(getRequestElement('userid')), getMessage('ADMIN_LOCKED_SUBJ'), $message);
74                         } // END - if
75
76                         // Prepare message
77                         $message = getMaskedMessage('USER_ACCOUNT_LOCKED', getRequestElement('userid'));
78                         $ACT = true;
79                 } elseif ((isPostRequestElementSet('unlock')) && (getUserData('status') == 'LOCKED')) {
80                         // Ok, unlock the account!
81                         if (getExtensionVersion('user') >= '0.3.5') {
82                                 // Reset lock reason as well
83                                 SQL_QUERY_ESC("UPDATE
84         `{?_MYSQL_PREFIX?}_user_data`
85 SET
86         `status`='CONFIRMED',
87         `lock_reason`='',
88         `lock_timestamp`='0000-00-00 00:00'
89 WHERE
90         `userid`=%s
91 LIMIT 1",
92                                         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
93                         } else {
94                                 // No lock reason to reset
95                                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `status`='CONFIRMED' WHERE `userid`=%s LIMIT 1",
96                                         array(bigintval(getRequestElement('userid'))), __FILE__, __LINE__);
97                         }
98
99                         // Entry updated?
100                         if (SQL_AFFECTEDROWS() == 1) {
101                                 // Send an email to the user! In later version you can optionally switch this feature off
102                                 $message = loadEmailTemplate('unlock-user', array('text' => postRequestElement('reason')), bigintval(getRequestElement('userid')));
103
104                                 // Send away...
105                                 sendEmail(bigintval(getRequestElement('userid')), getMessage('ADMIN_UNLOCKED_SUBJ'), $message);
106                                 if (isExtensionActive('rallye')) {
107                                         addUserToReferalRallye(getRequestElement('userid'));
108                                 } // END - if
109                         } // END - if
110
111                         // Prepare message
112                         $message = getMaskedMessage('USER_ACCOUNT_UNLOCKED', getRequestElement('userid'));
113                         $ACT = true;
114                 } elseif (isPostRequestElementSet('del')) {
115                         // Delete the account
116                         $ACT = true;
117                         loadIncludeOnce('inc/modules/admin/what-del_user.php');
118                 } elseif (isPostRequestElementSet('no')) {
119                         // Do not lock him...
120                         $URL = adminCreateUserLink(getRequestElement('userid'));
121                 } else {
122                         // Load user data we need
123                         if (fetchUserData(getRequestElement('userid'))) {
124                                 // Transfer data to constants for the template
125                                 $content['email']   = generateEmailLink(getUserData('email'), 'user_data');
126                                 $content['surname'] = getUserData('surname');
127                                 $content['family']  = getUserData('family');
128                                 $content['status']  = getUserData('status');
129                                 $content['userid']  = bigintval(getRequestElement('userid'));
130
131                                 // Realy want to lock?
132                                 switch ($content['status']) {
133                                         case 'CONFIRMED': // Yes, lock him down... ;-)
134                                                 $content['ok']     = 'lock';
135                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_LOCK_ACCOUNT', $content['userid']);
136                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_LOCK_ACCOUNT', $content['userid']);
137                                                 break;
138
139                                         case 'LOCKED': // Unlock the user
140                                                 $content['ok']     = 'unlock';
141                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_UNLOCK_ACCOUNT', $content['userid']);
142                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_UNLOCK_ACCOUNT', $content['userid']);
143                                                 break;
144
145                                         case 'UNCONFIRMED': // Unconfirmed accounts cannot be unlocked!
146                                                 $content['ok'] = 'del';
147                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_DEL_ACCOUNT', $content['userid']);
148                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_DEL_ACCOUNT', $content['userid']);
149                                                 break;
150                                 }
151
152                                 // Translate user status
153                                 $content['status'] = translateUserStatus($content['status']);
154
155                                 // Output form
156                                 loadTemplate('admin_lock_user', false, $content);
157                         } else {
158                                 // Account does not exists!
159                                 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . getMaskedMessage('ADMIN_MEMBER_404', getRequestElement('userid')) . '</div>');
160                         }
161                 }
162
163                 // Is an URL set?
164                 if (!empty($URL)) {
165                         // Reload and die...
166                         redirectToUrl($URL);
167                 } elseif ($ACT) {
168                         // An action was performed...
169                         if (!empty($message)) {
170                                 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . $message . '</div>');
171                         } else {
172                                 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . getMessage('ADMIN_USER_UPDATED') . '</div>');
173                         }
174                 }
175         } else {
176                 // Account does not exists!
177                 loadTemplate('admin_settings_saved', false, '<div class="admin_failed">' . getMaskedMessage('ADMIN_MEMBER_404', getRequestElement('userid')) . '</div>');
178         }
179 } else {
180         // List all users
181         addMemberSelectionBox();
182 }
183
184 // [EOF]
185 ?>