2 /************************************************************************
3 * Mailer v0.2.1-FINAL Start: 06/30/2011 *
4 * =================== Last change: 06/30/2011 *
6 * -------------------------------------------------------------------- *
7 * File : what-list_admins_acls.php *
8 * -------------------------------------------------------------------- *
9 * Short description : List admin access control lines (ACLs) *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Auflisten von Zugriffskontrollzeilen (ACLs) *
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://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 (postRequestElement('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__);
55 $content = SQL_FETCHARRAY($result);
58 SQL_FREERESULT($result);
60 // Prepare data for the row template
62 'id' => $content['id'],
63 'admins_selection' => generateOptionList('admins', 'id', 'login', $content['admin_id'], 'default_acl'),
64 'action_selection' => adminMenuSelectionBox_DEPRECATED('action', $content['action_menu'], $content['id']),
65 'what_selection' => adminMenuSelectionBox_DEPRECATED('what', $content['what_menu'], $content['id']),
69 $OUT .= loadTemplate('admin_edit_admins_acls_row', true, $content);
73 loadTemplate('admin_edit_admins_acls', false, $OUT);
74 } elseif ((isFormSent('do_edit')) && (ifPostContainsSelections())) {
76 foreach (postRequestElement('sel') as $id => $selected) {
82 `{?_MYSQL_PREFIX?}_admins_acls`
92 postRequestElement('admin', $id),
93 postRequestElement('action_menu', $id),
94 postRequestElement('what_menu', $id),
95 postRequestElement('mode', $id),
97 ),__FILE__, __LINE__);
100 // Update cache when installed
101 // @TODO Rewrite this to a filter
102 if (isExtensionActive('cache')) {
103 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
107 displayMessage('{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
108 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
111 foreach (postRequestElement('sel') as $id => $selected) {
112 // Load data for the id
113 $result = SQL_QUERY_ESC("SELECT `id`,`admin_id`,`action_menu`,`what_menu`,`access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
114 array(bigintval($id)), __FILE__, __LINE__);
115 $content = SQL_FETCHARRAY($result);
116 SQL_FREERESULT($result);
119 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
121 // Load row template and switch colors
122 $OUT .= loadTemplate('admin_delete_admins_acls_row', true, $content);
125 // Load main template
126 loadTemplate('admin_delete_admins_acls', false, $OUT);
127 } elseif ((isFormSent('do_delete')) && (ifPostContainsSelections())) {
129 // @TODO Rewrite this to filter 'run_sqls'
130 foreach (postRequestElement('sel') as $id => $selected) {
131 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
132 array(bigintval($id)),__FILE__, __LINE__);
135 // Update cache when installed
136 if (isExtensionActive('cache')) {
137 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
141 displayMessage('{--ADMIN_ADMINS_ENTRIES_DELETED--}');
142 } elseif (isFormSent('add')) {
143 // Check if everything is fine...
144 $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
146 // Default ACL is false
148 if (isPostRequestElementSet('what_menu')) {
150 $ACL = isAdminsAllowedByAcl(getActionFromModuleWhat('admin', postRequestElement('what_menu')), '');
153 if (($mode != postRequestElement('mode')) || (($ACL === true) && (postRequestElement('mode') == 'deny'))) {
155 $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')) && (postRequestElement('action_menu') != '') && (postRequestElement('what_menu') != ''));
157 // Check if one has been selected
158 if ((((isPostRequestElementSet('action_menu')) && (postRequestElement('action_menu') != '')) || ((isPostRequestElementSet('what_menu')) && (postRequestElement('what_menu') != ''))) && ($BOTH === false)) {
159 // Main or sub menu selected
160 $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",
162 bigintval(postRequestElement('admin_id')),
163 postRequestElement('action_menu'),
164 postRequestElement('what_menu')
165 ), __FILE__, __LINE__);
166 if (SQL_HASZERONUMS($result)) {
167 // Finally add the new ACL
168 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (`admin_id`,`action_menu`,`what_menu`,`access_mode`)
169 VALUES (%s,'%s','%s','%s')",
171 bigintval(postRequestElement('admin_id')),
172 postRequestElement('action_menu'),
173 postRequestElement('what_menu'),
174 postRequestElement('mode')
175 ), __FILE__, __LINE__);
176 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
178 // Update cache when installed
179 if (isExtensionActive('cache')) {
180 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
183 // ACL does already exist!
184 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
188 SQL_FREERESULT($result);
190 // No menu selected makes also no sence...
191 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
194 // Same mode makes no sence...
195 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
199 displayMessage($content);
202 $result = 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__);
205 if (!SQL_HASZERONUMS($result)) {
208 while ($content = SQL_FETCHARRAY($result)) {
209 // Generate mode string
210 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
212 // Load row template and switch colors
213 $OUT .= loadTemplate('admin_list_admins_acls_row', true, $content);
217 SQL_FREERESULT($result);
219 // Load main template
220 loadTemplate('admin_list_admins_acls', false, $OUT);
223 // Prepare some constants for the template
224 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
225 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
226 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
228 // Load template for adding new ACL
229 loadTemplate('admin_add_admins_acl', false, $content);