New extension added, more EL-rewrites, naming-convention applied:
[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  * 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 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if ((isFormSent('edit')) && (countPostSelection() > 0)) {
49         // Edit ACLs
50         $OUT = ''; $SW = 2;
51         foreach (postRequestParameter('sel') as $id => $selected) {
52                 // Load data for the id
53                 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
54                         array(bigintval($id)), __FILE__, __LINE__);
55                 list($adminId, $action, $what, $mode) = SQL_FETCHROW($result);
56                 SQL_FREERESULT($result);
57
58                 // Prepare data for the row template
59                 $content = array(
60                         'sw'               => $SW,
61                         'id'               => $id,
62                         'admins_selection' => generateOptionList('admins', 'id', 'login', $adminId, 'default_acl'),
63                         'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $action, $id),
64                         'what_selection'   => adminMenuSelectionBox_DEPRECATED('what', $what, $id),
65                         'mode_options'     => generateOptionList(
66                                 '/ARRAY/',
67                                 array('allow', 'deny'),
68                                 array(
69                                         getMessage('ADMINS_ALLOW_MODE'),
70                                         getMessage('ADMINS_DENY_MODE')
71                                 ),
72                                 $mode
73                         ),
74                 );
75
76                 // Load row template
77                 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
78                 $SW = 3 - $SW;
79         }
80
81         // Load main template
82         loadTemplate('admin_config_admins_edit', false, $OUT);
83 } elseif ((isFormSent('change')) && (countPostSelection() > 0)) {
84         // Change entries
85         foreach (postRequestParameter('sel') as $id => $selected) {
86                 // Secure id
87                 $id = bigintval($id);
88
89                 // Update entries
90                 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",
91                 array(
92                         postRequestParameter('admin', $id),
93                         postRequestParameter('action_menu', $id),
94                         postRequestParameter('what_menu', $id),
95                         postRequestParameter('mode', $id),
96                         $id
97                 ),__FILE__, __LINE__);
98         } // END - foreach
99
100         // Update cache when installed
101         if (isExtensionActive('cache')) {
102                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
103         } // END - if
104
105         // Entries changed
106         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
107 } elseif ((isFormSent('del')) && (countPostSelection() > 0)) {
108         // Delete ACLs
109         $OUT = ''; $SW = 2;
110         foreach (postRequestParameter('sel') as $id => $selected) {
111                 // Load data for the id
112                 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
113                         array(bigintval($id)), __FILE__, __LINE__);
114                 list($admin, $action, $what, $mode) = SQL_FETCHROW($result);
115                 SQL_FREERESULT($result);
116
117                 // Prepare variables
118                 if (empty($action)) $action = '---';
119                 if (empty($what)) $what = '---';
120
121                 // Get admin mode
122                 $mode = getMessage('ADMINS_'.strtoupper($mode).'_MODE');
123
124                 // Generate link
125                 $admin = generateAdminLink($admin);
126
127                 // Prepare data for the row template
128                 $content = array(
129                         'sw'     => $SW,
130                         'id'     => $id,
131                         'admin'  => $admin,
132                         'action' => $action,
133                         'what'   => $what,
134                         'mode'   => $mode,
135                 );
136
137                 // Load row template and switch colors
138                 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
139                 $SW = 3 - $SW;
140         } // END - foreach
141
142         // Load main template
143         loadTemplate('admin_config_admins_del', false, $OUT);
144 } elseif ((isFormSent('remove')) && (countPostSelection() > 0)) {
145         // Remove entries
146         // @TODO Rewrite this to filter 'run_sqls'
147         foreach (postRequestParameter('sel') as $id => $selected) {
148                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
149                         array(bigintval($id)),__FILE__, __LINE__);
150         } // END - foreach
151
152         // Update cache when installed
153         if (isExtensionActive('cache')) {
154                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
155         } // END - if
156
157         // Entries deleted
158         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_DELETED'));
159 } elseif (isFormSent('add')) {
160         // Check if everything is fine...
161         $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
162
163         // Default ACL is false
164         $ACL = false;
165         if (isPostRequestParameterSet('what_menu')) {
166                 // Check parent ACL
167                 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
168         } // END - if
169
170         if (($mode != postRequestParameter('mode')) || ($ACL)) {
171                 // Mode is fine
172                 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
173                 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('what_menu'))) && ($BOTH === false)) {
174                         // Main or sub menu selected
175                         $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",
176                                 array(bigintval(postRequestParameter('admin_id')), postRequestParameter('action_menu'), postRequestParameter('what_menu')), __FILE__, __LINE__);
177                         if (SQL_HASZERONUMS($result)) {
178                                 // Finally add the new ACL
179                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
180 VALUES ('%s','%s','%s','%s')",
181                                 array(
182                                         bigintval(postRequestParameter('admin_id')),
183                                         postRequestParameter('action_menu'),
184                                         postRequestParameter('what_menu'),
185                                         postRequestParameter('mode')
186                                 ), __FILE__, __LINE__);
187                                 $content = getMessage('ADMIN_ADMINS_ACL_SAVED');
188
189                                 // Update cache when installed
190                                 if (isExtensionActive('cache')) {
191                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
192                                 } // END - if
193                         } else {
194                                 // ACL does already exist!
195                                 $content = getMessage('ADMIN_ADMINS_ACL_ALREADY_ADDED');
196                         }
197
198                         // Free memory
199                         SQL_FREERESULT($result);
200                 } else {
201                         // No menu selected makes also no sence...
202                         $content = getMessage('ADMIN_ADMINS_SELECT_ACTION_WHAT');
203                 }
204         } else {
205                 // Same mode makes no sence...
206                 $content = getMessage('ADMIN_ADMINS_SAME_MODE_SELECTED');
207         }
208
209         // Display message
210         loadTemplate('admin_settings_saved', false, $content);
211 } else {
212         // List all ACLs
213         $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__);
214
215         // Entries found?
216         if (SQL_NUMROWS($result_acls) > 0) {
217                 // List ACLs
218                 $OUT = ''; $SW = 2;
219                 while ($content = SQL_FETCHARRAY($result_acls)) {
220                         // Prepare variables
221                         if (empty($content['action_menu'])) $content['action_menu'] = '---';
222                         if (empty($content['what_menu']))   $content['what_menu']   = '---';
223
224                         // Get mode
225                         $content['access_mode'] = getMessage('ADMINS_'.strtoupper($content['access_mode']).'_MODE');
226
227                         // Prepare data for the row template
228                         $content = array(
229                                 'sw'     => $SW,
230                                 'id'     => $content['id'],
231                                 'admin'  => generateAdminLink($content['admin_id']),
232                                 'action' => $content['action_menu'],
233                                 'what'   => $content['what_menu'],
234                                 'mode'   => $content['access_mode'],
235                         );
236
237                         // Load row template and switch colors
238                         $OUT .= loadTemplate('admin_config_admins_row', true, $content);
239                         $SW = 3 - $SW;
240                 } // END - while
241
242                 // Free memory
243                 SQL_FREERESULT($result);
244
245                 // Load main template
246                 loadTemplate('admin_config_admins', false, $OUT);
247         } // END - if
248
249         // Prepare some constants for the template
250         $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
251         $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
252         $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
253         $content['mode_options']     = generateOptionList(
254                 '/ARRAY/',
255                 array('allow', 'deny'),
256                 array(
257                         getMessage('ADMINS_ALLOW_MODE'),
258                         getMessage('ADMINS_DENY_MODE')
259                 )
260         );
261
262         // Load template for adding new ACL
263         loadTemplate('admin_admins_add_acl', false, $content);
264 }
265
266 //
267 ?>