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 - 2012 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' => generateOptions('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('access_mode', $id),
97 ),__FILE__, __LINE__);
100 // Update cache when installed
101 rebuildCache('admin_acls', 'admin_acls');
104 displayMessage('{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
105 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
108 foreach (postRequestElement('sel') as $id => $selected) {
109 // Load data for the id
110 $result = SQL_QUERY_ESC("SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
111 array(bigintval($id)), __FILE__, __LINE__);
112 $content = SQL_FETCHARRAY($result);
113 SQL_FREERESULT($result);
116 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
118 // Load row template and switch colors
119 $OUT .= loadTemplate('admin_delete_admins_acls_row', TRUE, $content);
122 // Load main template
123 loadTemplate('admin_delete_admins_acls', FALSE, $OUT);
124 } elseif ((isFormSent('do_delete')) && (ifPostContainsSelections())) {
126 // @TODO Rewrite this to filter 'run_sqls'
127 foreach (postRequestElement('sel') as $id => $selected) {
128 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
129 array(bigintval($id)),__FILE__, __LINE__);
132 // Update cache when installed
133 rebuildCache('admin_acls', 'admin_acls');
136 displayMessage('{--ADMIN_ADMINS_ENTRIES_DELETED--}');
137 } elseif (isFormSent('add')) {
138 // Check if everything is fine...
139 $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
141 // Default ACL is false
143 if (isPostRequestElementSet('what_menu')) {
145 $ACL = isAdminsAllowedByAcl(getActionFromModuleWhat('admin', postRequestElement('what_menu')), '');
148 if (($mode != postRequestElement('do')) || (($ACL === TRUE) && (postRequestElement('do') == 'deny'))) {
150 $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')) && (postRequestElement('action_menu') != '') && (postRequestElement('what_menu') != ''));
152 // Check if one has been selected
153 if ((((isPostRequestElementSet('action_menu')) && (postRequestElement('action_menu') != '')) || ((isPostRequestElementSet('what_menu')) && (postRequestElement('what_menu') != ''))) && ($BOTH === FALSE)) {
154 // Main or sub menu selected
155 $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",
157 bigintval(postRequestElement('admin_id')),
158 postRequestElement('action_menu'),
159 postRequestElement('what_menu')
160 ), __FILE__, __LINE__);
161 if (SQL_HASZERONUMS($result)) {
162 // Finally add the new ACL
163 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (
175 bigintval(postRequestElement('admin_id')),
176 postRequestElement('action_menu'),
177 postRequestElement('what_menu'),
178 postRequestElement('do')
179 ), __FILE__, __LINE__);
180 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
182 // Update cache when installed
183 rebuildCache('admin_acls', 'admin_acls');
185 // ACL does already exist!
186 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
190 SQL_FREERESULT($result);
192 // No menu selected makes also no sence...
193 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
196 // Same mode makes no sence...
197 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
201 displayMessage($content);
204 $result = SQL_QUERY('SELECT
211 `{?_MYSQL_PREFIX?}_admins_acls`
214 `id` ASC', __FILE__, __LINE__);
217 if (!SQL_HASZERONUMS($result)) {
220 while ($content = SQL_FETCHARRAY($result)) {
221 // Generate mode string
222 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
224 // Load row template and switch colors
225 $OUT .= loadTemplate('admin_list_admins_acls_row', TRUE, $content);
229 SQL_FREERESULT($result);
231 // Load main template
232 loadTemplate('admin_list_admins_acls', FALSE, $OUT);
235 // Prepare some constants for the template
236 $content['admins_selection'] = generateOptions('admins', 'id', 'login', '', 'default_acl');
237 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
238 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
240 // Load template for adding new ACL
241 loadTemplate('admin_add_admins_acl', FALSE, $content);