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