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://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_ACCESS_MODE_ALLOW--}',
69 '{--ADMIN_ADMINS_ACCESS_MODE_DENY--}'
71 $content['access_mode']
76 $OUT .= loadTemplate('admin_edit_admins_acls_row', true, $content);
80 loadTemplate('admin_edit_admins_acls', 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_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
128 // Load row template and switch colors
129 $OUT .= loadTemplate('admin_delete_admins_acls_row', true, $content);
132 // Load main template
133 loadTemplate('admin_delete_admins_acls', 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 === true) && (postRequestParameter('mode') == 'deny'))) {
162 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')) && (postRequestParameter('action_menu') != '') && (postRequestParameter('what_menu') != ''));
164 // Check if one has been selected
165 if ((((isPostRequestParameterSet('action_menu')) && (postRequestParameter('action_menu') != '')) || ((isPostRequestParameterSet('what_menu')) && (postRequestParameter('what_menu') != ''))) && ($BOTH === false)) {
166 // Main or sub menu selected
167 $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",
169 bigintval(postRequestParameter('admin_id')),
170 postRequestParameter('action_menu'),
171 postRequestParameter('what_menu')
172 ), __FILE__, __LINE__);
173 if (SQL_HASZERONUMS($result)) {
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(postRequestParameter('admin_id')),
179 postRequestParameter('action_menu'),
180 postRequestParameter('what_menu'),
181 postRequestParameter('mode')
182 ), __FILE__, __LINE__);
183 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
185 // Update cache when installed
186 if (isExtensionActive('cache')) {
187 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
190 // ACL does already exist!
191 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
195 SQL_FREERESULT($result);
197 // No menu selected makes also no sence...
198 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
201 // Same mode makes no sence...
202 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
206 displayMessage($content);
209 $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__);
212 if (!SQL_HASZERONUMS($result)) {
215 while ($content = SQL_FETCHARRAY($result)) {
216 // Generate mode string
217 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
219 // Load row template and switch colors
220 $OUT .= loadTemplate('admin_list_admins_acls_row', true, $content);
224 SQL_FREERESULT($result);
226 // Load main template
227 loadTemplate('admin_list_admins_acls', false, $OUT);
230 // Prepare some constants for the template
231 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
232 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
233 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
234 $content['mode_options'] = generateOptionList(
236 array('allow', 'deny'),
238 '{--ADMIN_ADMINS_ACCESS_MODE_ALLOW--}',
239 '{--ADMIN_ADMINS_ACCESS_MODE_DENY--}'
243 // Load template for adding new ACL
244 loadTemplate('admin_add_admins_acl', false, $content);