7de92cb2261f1c21438978c732e090095b25f5b6
[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         $isActive = 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')), '{--ADMIN_LOCKED_SUBJECT--}', $message);
75                         } // END - if
76
77                         // Prepare message
78                         $message = getMaskedMessage('ADMIN_USER_ACCOUNT_LOCKED', bigintval(getRequestParameter('userid')));
79                         $isActive = 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')), '{--ADMIN_UNLOCKED_SUBJECT--}', $message);
107                                 if (isExtensionActive('rallye')) {
108                                         addUserToReferalRallye(getRequestParameter('userid'));
109                                 } // END - if
110                         } // END - if
111
112                         // Prepare message
113                         $message = getMaskedMessage('ADMIN_USER_ACCOUNT_UNLOCKED', bigintval(getRequestParameter('userid')));
114                         $isActive = true;
115                 } elseif (isFormSent('del')) {
116                         // Delete the account
117                         $isActive = 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['userid']  = getRequestParameter('userid');
127
128                                 // Realy want to lock?
129                                 switch (getUserData('status')) {
130                                         case 'CONFIRMED': // Yes, lock him down... ;-)
131                                                 $content['ok']     = 'lock';
132                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_LOCK_ACCOUNT', $content['userid']);
133                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_LOCK_ACCOUNT', $content['userid']);
134                                                 break;
135
136                                         case 'LOCKED': // Unlock the user
137                                                 $content['ok']     = 'unlock';
138                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_UNLOCK_ACCOUNT', $content['userid']);
139                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_UNLOCK_ACCOUNT', $content['userid']);
140                                                 break;
141
142                                         case 'UNCONFIRMED': // Unconfirmed accounts cannot be unlocked!
143                                                 $content['ok'] = 'del';
144                                                 $content['header'] = getMaskedMessage('ADMIN_HEADER_DELETE_ACCOUNT', $content['userid']);
145                                                 $content['text']   = getMaskedMessage('ADMIN_TEXT_DELETE_ACCOUNT', $content['userid']);
146                                                 break;
147                                 }
148
149                                 // Output form
150                                 loadTemplate('admin_lock_user', false, $content);
151                         } else {
152                                 // Account does not exists!
153                                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))) . '</div>');
154                         }
155                 }
156
157                 // Is an URL set?
158                 if (!empty($url)) {
159                         // Reload and die...
160                         redirectToUrl($url);
161                 } elseif ($isActive) {
162                         // An action was performed...
163                         if (!empty($message)) {
164                                 loadTemplate('admin_settings_unsaved', false, $message);
165                         } else {
166                                 loadTemplate('admin_settings_saved', false, '{--ADMIN_USER_UPDATED--}');
167                         }
168                 }
169         } else {
170                 // Account does not exists!
171                 loadTemplate('admin_settings_unsaved', false, getMaskedMessage('ADMIN_MEMBER_404', bigintval(getRequestParameter('userid'))));
172         }
173 } else {
174         // List all users
175         addMemberSelectionBox();
176 }
177
178 // [EOF]
179 ?>