Performance hacks, encapsulation and more EL code usage:
[mailer.git] / inc / modules / admin / what-config_admins.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/30/2004 *
4  * ===================                          Last change: 07/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File: what-config_admins.php                                         *
8  * -------------------------------------------------------------------- *
9  * Short description : Configure admin ACLs                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Admin-ACLs einstellen                            *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
20  * For more information visit: http://www.mxchange.org                  *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
47         // Edit ACLs
48         $OUT = '';
49         foreach (postRequestParameter('sel') as $id => $selected) {
50                 // Load data for the id
51                 $result = SQL_QUERY_ESC("SELECT `id`, `admin_id`, `action_menu, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
52                         array(bigintval($id)), __FILE__, __LINE__);
53                 $content = SQL_FETCHARRAY($result);
54
55                 // Free result
56                 SQL_FREERESULT($result);
57
58                 // Prepare data for the row template
59                 $content = array(
60                         'id'               => $content['id'],
61                         'admins_selection' => generateOptionList('admins', 'id', 'login', $content['admin_id'], 'default_acl'),
62                         'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $content['action_menu'], $content['id']),
63                         'what_selection'   => adminMenuSelectionBox_DEPRECATED('what', $content['what_menu'], $content['id']),
64                         'mode_options'     => generateOptionList(
65                                 '/ARRAY/',
66                                 array('allow', 'deny'),
67                                 array(
68                                         '{--ADMINS_ALLOW_MODE--}',
69                                         '{--ADMINS_DENY_MODE--}'
70                                 ),
71                                 $content['access_mode']
72                         ),
73                 );
74
75                 // Load row template
76                 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
77         } // END - foreach
78
79         // Load main template
80         loadTemplate('admin_config_admins_edit', false, $OUT);
81 } elseif ((isFormSent('change')) && (ifPostContainsSelections())) {
82         // Change entries
83         foreach (postRequestParameter('sel') as $id => $selected) {
84                 // Secure id
85                 $id = bigintval($id);
86
87                 // Update entries
88                 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_admins_acls` SET admin_id=%s, action_menu='%s', what_menu='%s', access_mode='%s' WHERE `id`=%s LIMIT 1",
89                 array(
90                         postRequestParameter('admin', $id),
91                         postRequestParameter('action_menu', $id),
92                         postRequestParameter('what_menu', $id),
93                         postRequestParameter('mode', $id),
94                         $id
95                 ),__FILE__, __LINE__);
96         } // END - foreach
97
98         // Update cache when installed
99         if (isExtensionActive('cache')) {
100                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
101         } // END - if
102
103         // Entries changed
104         loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
105 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
106         // Delete ACLs
107         $OUT = '';
108         foreach (postRequestParameter('sel') as $id => $selected) {
109                 // Load data for the id
110                 $result = SQL_QUERY_ESC("SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
111                         array(bigintval($id)), __FILE__, __LINE__);
112                 $content = SQL_FETCHARRAY($result);
113                 SQL_FREERESULT($result);
114
115                 // Get admin mode
116                 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
117
118                 // Load row template and switch colors
119                 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
120         } // END - foreach
121
122         // Load main template
123         loadTemplate('admin_config_admins_del', false, $OUT);
124 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
125         // Remove entries
126         // @TODO Rewrite this to filter 'run_sqls'
127         foreach (postRequestParameter('sel') as $id => $selected) {
128                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
129                         array(bigintval($id)),__FILE__, __LINE__);
130         } // END - foreach
131
132         // Update cache when installed
133         if (isExtensionActive('cache')) {
134                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
135         } // END - if
136
137         // Entries deleted
138         loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_DELETED--}');
139 } elseif (isFormSent('add')) {
140         // Check if everything is fine...
141         $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
142
143         // Default ACL is false
144         $ACL = false;
145         if (isPostRequestParameterSet('what_menu')) {
146                 // Check parent ACL
147                 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
148         } // END - if
149
150         if (($mode != postRequestParameter('mode')) || ($ACL)) {
151                 // Mode is fine
152                 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
153                 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('what_menu'))) && ($BOTH === false)) {
154                         // Main or sub menu selected
155                         $result = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `admin_id`=%s AND `action_menu`='%s' AND `what_menu`='%s' LIMIT 1",
156                                 array(
157                                         bigintval(postRequestParameter('admin_id')),
158                                         postRequestParameter('action_menu'),
159                                         postRequestParameter('what_menu')
160                                 ), __FILE__, __LINE__);
161                         if (SQL_HASZERONUMS($result)) {
162                                 // Finally add the new ACL
163                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (`admin_id`, `action_menu`, `what_menu`, `access_mode`)
164 VALUES ('%s','%s','%s','%s')",
165                                 array(
166                                         bigintval(postRequestParameter('admin_id')),
167                                         postRequestParameter('action_menu'),
168                                         postRequestParameter('what_menu'),
169                                         postRequestParameter('mode')
170                                 ), __FILE__, __LINE__);
171                                 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
172
173                                 // Update cache when installed
174                                 if (isExtensionActive('cache')) {
175                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
176                                 } // END - if
177                         } else {
178                                 // ACL does already exist!
179                                 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
180                         }
181
182                         // Free memory
183                         SQL_FREERESULT($result);
184                 } else {
185                         // No menu selected makes also no sence...
186                         $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
187                 }
188         } else {
189                 // Same mode makes no sence...
190                 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
191         }
192
193         // Display message
194         loadTemplate('admin_settings_saved', false, $content);
195 } else {
196         // List all ACLs
197         $result_acls = SQL_QUERY('SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` ORDER BY `admin_id` ASC, `id` ASC', __FILE__, __LINE__);
198
199         // Entries found?
200         if (!SQL_HASZERONUMS($result_acls)) {
201                 // List ACLs
202                 $OUT = '';
203                 while ($content = SQL_FETCHARRAY($result_acls)) {
204                         // Generate mode string
205                         $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
206
207                         // Load row template and switch colors
208                         $OUT .= loadTemplate('admin_config_admins_row', true, $content);
209                 } // END - while
210
211                 // Free memory
212                 SQL_FREERESULT($result);
213
214                 // Load main template
215                 loadTemplate('admin_config_admins', false, $OUT);
216         } // END - if
217
218         // Prepare some constants for the template
219         $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
220         $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
221         $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
222         $content['mode_options']     = generateOptionList(
223                 '/ARRAY/',
224                 array('allow', 'deny'),
225                 array(
226                         '{--ADMINS_ALLOW_MODE--}',
227                         '{--ADMINS_DENY_MODE--}'
228                 )
229         );
230
231         // Load template for adding new ACL
232         loadTemplate('admin_add_admins_acl', false, $content);
233 }
234
235 // [EOF]
236 ?>