2 /************************************************************************
3 * MXChange v0.2.1 Start: 06/30/2004 *
4 * ================ Last change: 07/02/2004 *
6 * -------------------------------------------------------------------- *
7 * File: what-config_admins.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Configure admin ACLs *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Admin-ACLs einstellen *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
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 *
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. *
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. *
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, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
48 if (isPostRequestElementSet('sel')) $SEL = countPostSelection();
50 if ((isPostRequestElementSet('edit')) && ($SEL > 0)) {
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);
60 // Prepare data for the row template
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(
69 array('allow', 'deny'),
71 getMessage('ADMINS_ALLOW_MODE'),
72 getMessage('ADMINS_DENY_MODE')
79 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
84 loadTemplate('admin_config_admins_edit', false, $OUT);
85 } elseif ((isPostRequestElementSet('change')) && ($SEL > 0)) {
87 foreach (postRequestElement('sel') as $id => $selected) {
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",
94 postRequestElement('admin', $id),
95 postRequestElement('action_menu', $id),
96 postRequestElement('what_menu', $id),
97 postRequestElement('mode', $id),
99 ),__FILE__, __LINE__);
102 // Update cache when installed
103 if (isExtensionActive('cache')) {
104 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
108 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
109 } elseif ((isPostRequestElementSet('del')) && ($SEL > 0)) {
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);
120 if (empty($action)) $action = '---';
121 if (empty($what)) $what = '---';
124 $mode = getMessage('ADMINS_'.strtoupper($mode).'_MODE');
127 $admin = generateAdminLink($admin);
129 // Prepare data for the row template
139 // Load row template and switch colors
140 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
144 // Load main template
145 loadTemplate('admin_config_admins_del', false, $OUT);
146 } elseif ((isPostRequestElementSet('remove')) && ($SEL > 0)) {
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__);
154 // Update cache when installed
155 if (isExtensionActive('cache')) {
156 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
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')));
165 // Default ACL is false
167 if (isPostRequestElementSet('what_menu')) {
169 $ACL = adminsCheckAdminAcl(getModeAction('admin', postRequestElement('what_menu')), '');
172 if (($mode != postRequestElement('mode')) || ($ACL)) {
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')",
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');
191 // Update cache when installed
192 if (isExtensionActive('cache')) {
193 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
196 // ACL does already exist!
197 $content = getMessage('ADMIN_ADMINS_ACL_ALREADY_ADDED');
201 SQL_FREERESULT($result);
203 // No menu selected makes also no sence...
204 $content = getMessage('ADMIN_ADMINS_SELECT_ACTION_WHAT');
207 // Same mode makes no sence...
208 $content = getMessage('ADMIN_ADMINS_SAME_MODE_SELECTED');
212 loadTemplate('admin_settings_saved', false, $content);
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__);
218 if (SQL_NUMROWS($result_acls) > 0) {
221 while ($content = SQL_FETCHARRAY($result_acls)) {
223 if (empty($content['action_menu'])) $content['action_menu'] = '---';
224 if (empty($content['what_menu'])) $content['what_menu'] = '---';
227 $content['access_mode'] = getMessage('ADMINS_'.strtoupper($content['access_mode']).'_MODE');
229 // Prepare data for the row template
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'],
239 // Load row template and switch colors
240 $OUT .= loadTemplate('admin_config_admins_row', true, $content);
245 SQL_FREERESULT($result);
247 // Load main template
248 loadTemplate('admin_config_admins', false, $OUT);
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(
257 array('allow', 'deny'),
259 getMessage('ADMINS_ALLOW_MODE'),
260 getMessage('ADMINS_DENY_MODE')
264 // Load template for adding new ACL
265 loadTemplate('admin_admins_add_acl', false, $content);