2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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__);
47 if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
50 foreach (postRequestElement('sel') as $id => $selected) {
51 // Load data for the id
52 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
53 array(bigintval($id)), __FILE__, __LINE__);
54 list($adminId, $action, $what, $mode) = SQL_FETCHROW($result);
55 SQL_FREERESULT($result);
57 // Prepare data for the row template
61 'admins_selection' => generateOptionList('admins', 'id', 'login', $adminId, 'default_acl'),
62 'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $action, $id),
63 'what_selection' => adminMenuSelectionBox_DEPRECATED('what', $what, $id),
64 'mode_options' => generateOptionList(
66 array('allow', 'deny'),
68 getMessage('ADMINS_ALLOW_MODE'),
69 getMessage('ADMINS_DENY_MODE')
76 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
81 loadTemplate('admin_config_admins_edit', false, $OUT);
82 } elseif ((isPostRequestElementSet('change')) && (countPostSelection() > 0)) {
84 foreach (postRequestElement('sel') as $id => $selected) {
89 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 postRequestElement('admin', $id),
92 postRequestElement('action_menu', $id),
93 postRequestElement('what_menu', $id),
94 postRequestElement('mode', $id),
96 ),__FILE__, __LINE__);
99 // Update cache when installed
100 if (isExtensionActive('cache')) {
101 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
105 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
106 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
109 foreach (postRequestElement('sel') as $id => $selected) {
110 // Load data for the id
111 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
112 array(bigintval($id)), __FILE__, __LINE__);
113 list($admin, $action, $what, $mode) = SQL_FETCHROW($result);
114 SQL_FREERESULT($result);
117 if (empty($action)) $action = '---';
118 if (empty($what)) $what = '---';
121 $mode = getMessage('ADMINS_'.strtoupper($mode).'_MODE');
124 $admin = generateAdminLink($admin);
126 // Prepare data for the row template
136 // Load row template and switch colors
137 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
141 // Load main template
142 loadTemplate('admin_config_admins_del', false, $OUT);
143 } elseif ((isPostRequestElementSet('remove')) && (countPostSelection() > 0)) {
145 // @TODO Rewrite this to filter 'run_sqls'
146 foreach (postRequestElement('sel') as $id => $selected) {
147 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
148 array(bigintval($id)),__FILE__, __LINE__);
151 // Update cache when installed
152 if (isExtensionActive('cache')) {
153 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
157 loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_DELETED'));
158 } elseif (isPostRequestElementSet('add')) {
159 // Check if everything is fine...
160 $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
162 // Default ACL is false
164 if (isPostRequestElementSet('what_menu')) {
166 $ACL = adminsCheckAdminAcl(getModeAction('admin', postRequestElement('what_menu')), '');
169 if (($mode != postRequestElement('mode')) || ($ACL)) {
171 $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')));
172 if (((isPostRequestElementSet('action_menu')) || (isPostRequestElementSet('what_menu'))) && ($BOTH === false)) {
173 // Main or sub menu selected
174 $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",
175 array(bigintval(postRequestElement('admin_id')), postRequestElement('action_menu'), postRequestElement('what_menu')), __FILE__, __LINE__);
176 if (SQL_NUMROWS($result) == '0') {
177 // Finally add the new ACL
178 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
179 VALUES ('%s','%s','%s','%s')",
181 bigintval(postRequestElement('admin_id')),
182 postRequestElement('action_menu'),
183 postRequestElement('what_menu'),
184 postRequestElement('mode')
185 ), __FILE__, __LINE__);
186 $content = getMessage('ADMIN_ADMINS_ACL_SAVED');
188 // Update cache when installed
189 if (isExtensionActive('cache')) {
190 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
193 // ACL does already exist!
194 $content = getMessage('ADMIN_ADMINS_ACL_ALREADY_ADDED');
198 SQL_FREERESULT($result);
200 // No menu selected makes also no sence...
201 $content = getMessage('ADMIN_ADMINS_SELECT_ACTION_WHAT');
204 // Same mode makes no sence...
205 $content = getMessage('ADMIN_ADMINS_SAME_MODE_SELECTED');
209 loadTemplate('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` ASC, `id` ASC', __FILE__, __LINE__);
215 if (SQL_NUMROWS($result_acls) > 0) {
218 while ($content = SQL_FETCHARRAY($result_acls)) {
220 if (empty($content['action_menu'])) $content['action_menu'] = '---';
221 if (empty($content['what_menu'])) $content['what_menu'] = '---';
224 $content['access_mode'] = getMessage('ADMINS_'.strtoupper($content['access_mode']).'_MODE');
226 // Prepare data for the row template
229 'id' => $content['id'],
230 'admin' => generateAdminLink($content['admin_id']),
231 'action' => $content['action_menu'],
232 'what' => $content['what_menu'],
233 'mode' => $content['access_mode'],
236 // Load row template and switch colors
237 $OUT .= loadTemplate('admin_config_admins_row', true, $content);
242 SQL_FREERESULT($result);
244 // Load main template
245 loadTemplate('admin_config_admins', false, $OUT);
248 // Prepare some constants for the template
249 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
250 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
251 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
252 $content['mode_options'] = generateOptionList(
254 array('allow', 'deny'),
256 getMessage('ADMINS_ALLOW_MODE'),
257 getMessage('ADMINS_DENY_MODE')
261 // Load template for adding new ACL
262 loadTemplate('admin_admins_add_acl', false, $content);