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 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2011 by Mailer Developer Team *
20 * For more information visit: http://www.mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
46 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
49 foreach (postRequestParameter('sel') as $id => $selected) {
50 // Load data for the id
51 $result = SQL_QUERY_ESC("SELECT `id`, `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 $content = SQL_FETCHARRAY($result);
56 SQL_FREERESULT($result);
58 // Prepare data for the row template
60 'id' => $content['id'],
61 'admins_selection' => generateOptionList('admins', 'id', 'login', $content['admin_id'], 'default_acl'),
62 'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $content['action_menu'], $content['id']),
63 'what_selection' => adminMenuSelectionBox_DEPRECATED('what', $content['what_menu'], $content['id']),
64 'mode_options' => generateOptionList(
66 array('allow', 'deny'),
68 '{--ADMIN_ADMINS_MODE_ALLOW--}',
69 '{--ADMIN_ADMINS_MODE_DENY--}'
71 $content['access_mode']
76 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
80 loadTemplate('admin_config_admins_edit', false, $OUT);
81 } elseif ((isFormSent('change')) && (ifPostContainsSelections())) {
83 foreach (postRequestParameter('sel') as $id => $selected) {
89 `{?_MYSQL_PREFIX?}_admins_acls`
99 postRequestParameter('admin', $id),
100 postRequestParameter('action_menu', $id),
101 postRequestParameter('what_menu', $id),
102 postRequestParameter('mode', $id),
104 ),__FILE__, __LINE__);
107 // Update cache when installed
108 // @TODO Rewrite this to a filter
109 if (isExtensionActive('cache')) {
110 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
114 displayMessage('{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
115 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
118 foreach (postRequestParameter('sel') as $id => $selected) {
119 // Load data for the id
120 $result = SQL_QUERY_ESC("SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
121 array(bigintval($id)), __FILE__, __LINE__);
122 $content = SQL_FETCHARRAY($result);
123 SQL_FREERESULT($result);
126 $content['access_mode'] = '{--ADMIN_ADMINS_MODE_' . strtoupper($content['access_mode']) . '--}';
128 // Load row template and switch colors
129 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
132 // Load main template
133 loadTemplate('admin_config_admins_del', false, $OUT);
134 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
136 // @TODO Rewrite this to filter 'run_sqls'
137 foreach (postRequestParameter('sel') as $id => $selected) {
138 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
139 array(bigintval($id)),__FILE__, __LINE__);
142 // Update cache when installed
143 if (isExtensionActive('cache')) {
144 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
148 displayMessage('{--ADMIN_ADMINS_ENTRIES_DELETED--}');
149 } elseif (isFormSent('add')) {
150 // Check if everything is fine...
151 $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
153 // Default ACL is false
155 if (isPostRequestParameterSet('what_menu')) {
157 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
160 if (($mode != postRequestParameter('mode')) || ($ACL)) {
162 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
163 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('what_menu'))) && ($BOTH === false)) {
164 // Main or sub menu selected
165 $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",
167 bigintval(postRequestParameter('admin_id')),
168 postRequestParameter('action_menu'),
169 postRequestParameter('what_menu')
170 ), __FILE__, __LINE__);
171 if (SQL_HASZERONUMS($result)) {
172 // Finally add the new ACL
173 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (`admin_id`, `action_menu`, `what_menu`, `access_mode`)
174 VALUES ('%s','%s','%s','%s')",
176 bigintval(postRequestParameter('admin_id')),
177 postRequestParameter('action_menu'),
178 postRequestParameter('what_menu'),
179 postRequestParameter('mode')
180 ), __FILE__, __LINE__);
181 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
183 // Update cache when installed
184 if (isExtensionActive('cache')) {
185 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
188 // ACL does already exist!
189 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
193 SQL_FREERESULT($result);
195 // No menu selected makes also no sence...
196 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
199 // Same mode makes no sence...
200 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
204 displayMessage($content);
207 $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__);
210 if (!SQL_HASZERONUMS($result_acls)) {
213 while ($content = SQL_FETCHARRAY($result_acls)) {
214 // Generate mode string
215 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
217 // Load row template and switch colors
218 $OUT .= loadTemplate('admin_config_admins_row', true, $content);
222 SQL_FREERESULT($result);
224 // Load main template
225 loadTemplate('admin_config_admins', false, $OUT);
228 // Prepare some constants for the template
229 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
230 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
231 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
232 $content['mode_options'] = generateOptionList(
234 array('allow', 'deny'),
236 '{--ADMIN_ADMINS_MODE_ALLOW--}',
237 '{--ADMIN_ADMINS_MODE_DENY--}'
241 // Load template for adding new ACL
242 loadTemplate('admin_add_admins_acl', false, $content);