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 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Add description as navigation point
41 ADD_DESCR("admin", __FILE__);
44 if (!empty($_POST['sel'])) $SEL = SELECTION_COUNT($_POST['sel']);
46 if ((isset($_POST['edit'])) && ($SEL > 0)) {
49 foreach ($_POST['sel'] as $id => $sel) {
50 // Load data for the ID
51 $result = SQL_QUERY_ESC("SELECT 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 list($aid, $act, $wht, $mode) = SQL_FETCHROW($result);
54 SQL_FREERESULT($result);
56 // Prepare data for the row template
60 'admins_selection' => ADD_OPTION_LINES("admins", "id", "login", $aid, "default_acl"),
61 'action_selection' => ADMIN_MENU_SELECTION("action", $act, $id),
62 'what_selection' => ADMIN_MENU_SELECTION("what", $wht, $id),
63 'mode_options' => ADD_OPTION_LINES(
65 array("allow", "deny"),
66 array(constant('ADMINS_ALLOW_MODE'), constant('ADMINS_DENY_MODE')),
72 $OUT .= LOAD_TEMPLATE("admin_config_admins_edit_row", true, $content);
75 define('__ACL_ROWS', $OUT);
78 LOAD_TEMPLATE("admin_config_admins_edit");
79 } elseif ((isset($_POST['change'])) && ($SEL > 0)) {
81 foreach ($_POST['sel'] as $id => $sel) {
86 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",
87 array($_POST['admin'][$id], $_POST['action_menu'][$id], $_POST['what_menu'][$id], $_POST['mode'][$id], $id),__FILE__, __LINE__);
90 // Update cache when installed
91 if (EXT_IS_ACTIVE("cache")) {
92 if ($cacheInstance->loadCacheFile("admins_acls")) $cacheInstance->destroyCacheFile();
95 CACHE_PURGE_ADMIN_MENU($_POST['admin'][$id]);
99 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
100 } elseif ((isset($_POST['del'])) && ($SEL > 0)) {
103 foreach ($_POST['sel'] as $id => $sel) {
104 // Load data for the ID
105 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{!_MYSQL_PREFIX!}_admins_acls` WHERE id=%s LIMIT 1",
106 array(bigintval($id)), __FILE__, __LINE__);
107 list($admin, $act, $wht, $mode) = SQL_FETCHROW($result);
108 SQL_FREERESULT($result);
111 if (empty($act)) $act = "---";
112 if (empty($wht)) $wht = "---";
115 $mode = constant('ADMINS_'.strtoupper($mode).'_MODE');
118 $admin = GENERATE_AID_LINK($admin);
120 // Prepare data for the row template
130 // Load row template and switch colors
131 $OUT .= LOAD_TEMPLATE("admin_config_admins_del_row", true, $content);
134 define('__ACL_ROWS', $OUT);
136 // Load main template
137 LOAD_TEMPLATE("admin_config_admins_del");
138 } elseif ((isset($_POST['remove'])) && ($SEL > 0)) {
140 foreach ($_POST['sel'] as $id => $sel) {
141 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_admins_acls` WHERE id=%s LIMIT 1",
142 array(bigintval($id)),__FILE__, __LINE__);
145 // Update cache when installed
146 if (EXT_IS_ACTIVE("cache")) {
147 if ($cacheInstance->loadCacheFile("admins_acls")) $cacheInstance->destroyCacheFile();
149 // @TODO This causes the whole (!) menu cache being rebuild
150 CACHE_PURGE_ADMIN_MENU();
154 LOAD_TEMPLATE("admin_settings_saved", false, getMessage('ADMIN_ADMINS_ENTRIES_DELETED'));
155 } elseif (isset($_POST['add'])) {
156 // Check if everything is fine...
157 $mode = GET_ADMIN_DEFAULT_ACL(bigintval($_POST['admin_id']));
159 // Default ACL is false
161 if (!empty($_POST['what_menu'])) {
163 $ACL = ADMINS_CHECK_ACL(GET_ACTION("admin", $_POST['what_menu']), "");
166 if ($mode != $_POST['mode'] || ($ACL)) {
168 $BOTH = ((!empty($_POST['action_menu'])) && (!empty($_POST['what_menu'])));
169 if (((!empty($_POST['action_menu'])) || (!empty($_POST['what_menu']))) && (!$BOTH)) {
170 // Main or sub menu selected
171 $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",
172 array(bigintval($_POST['admin_id']), $_POST['action_menu'], $_POST['what_menu']), __FILE__, __LINE__);
173 if (SQL_NUMROWS($result) == 0) {
174 // Finally add the new ACL
175 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
176 VALUES ('%s','%s','%s','%s')",
178 bigintval($_POST['admin_id']),
179 $_POST['action_menu'],
182 ), __FILE__, __LINE__);
183 $content = ADMIN_ADMINS_ACL_SAVED;
185 // Update cache when installed
186 if (EXT_IS_ACTIVE("cache")) {
187 if ($cacheInstance->loadCacheFile("admins_acls")) $cacheInstance->destroyCacheFile();
190 CACHE_PURGE_ADMIN_MENU($_POST['admin_id'], $_POST['action_menu'], $_POST['what_menu']);
193 // ACL does already exist!
194 $content = ADMIN_ADMINS_ACL_ALREADY_ADDED;
198 SQL_FREERESULT($result);
200 // No menu selected makes also no sence...
201 $content = ADMIN_ADMINS_SELECT_ACTION_WHAT;
204 // Same mode makes no sence...
205 $content = ADMIN_ADMINS_SAME_MODE_SELECTED;
209 LOAD_TEMPLATE("admin_settings_saved", false, $content);
212 $result_acls = SQL_QUERY("SELECT id, admin_id, action_menu, what_menu, access_mode FROM `{!_MYSQL_PREFIX!}_admins_acls` ORDER BY admin_id, id", __FILE__, __LINE__);
213 if (SQL_NUMROWS($result_acls) > 0)
217 while (list($id, $admin, $act, $wht, $mode) = SQL_FETCHROW($result_acls))
220 if (empty($act)) $act = "---";
221 if (empty($wht)) $wht = "---";
224 $mode = constant('ADMINS_'.strtoupper($mode).'_MODE');
226 // Prepare data for the row template
230 'admin' => GENERATE_AID_LINK($admin),
236 // Load row template and switch colors
237 $OUT .= LOAD_TEMPLATE("admin_config_admins_row", true, $content);
242 SQL_FREERESULT($result);
243 define('__ACL_ROWS', $OUT);
245 // Load main template
246 LOAD_TEMPLATE("admin_config_admins");
249 // Prepare some constants for the template
250 define('_ADMINS_SELECTION', ADD_OPTION_LINES("admins", "id", "login", "", "default_acl"));
251 define('_ACTION_SELECTION', ADMIN_MENU_SELECTION("action"));
252 define('_WHAT_SELECTION' , ADMIN_MENU_SELECTION("what"));
253 define('_MODE_OPTIONS' , ADD_OPTION_LINES("/ARRAY/", array("allow", "deny"), array(ADMINS_ALLOW_MODE, ADMINS_DENY_MODE)));
255 // Load template for adding new ACL
256 LOAD_TEMPLATE("admin_admins_add_acl");