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