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 * Copyright (c) 2009, 2010 by Mailer Developer Team *
22 * For more information visit: http://www.mxchange.org *
24 * This program is free software; you can redistribute it and/or modify *
25 * it under the terms of the GNU General Public License as published by *
26 * the Free Software Foundation; either version 2 of the License, or *
27 * (at your option) any later version. *
29 * This program is distributed in the hope that it will be useful, *
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
32 * GNU General Public License for more details. *
34 * You should have received a copy of the GNU General Public License *
35 * along with this program; if not, write to the Free Software *
36 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
38 ************************************************************************/
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
48 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
51 foreach (postRequestParameter('sel') as $id => $selected) {
52 // Load data for the id
53 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
54 array(bigintval($id)), __FILE__, __LINE__);
55 list($adminId, $action, $what, $mode) = SQL_FETCHROW($result);
56 SQL_FREERESULT($result);
58 // 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 '{--ADMINS_ALLOW_MODE--}',
69 '{--ADMINS_DENY_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) {
88 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",
90 postRequestParameter('admin', $id),
91 postRequestParameter('action_menu', $id),
92 postRequestParameter('what_menu', $id),
93 postRequestParameter('mode', $id),
95 ),__FILE__, __LINE__);
98 // Update cache when installed
99 if (isExtensionActive('cache')) {
100 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
104 loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
105 } elseif ((isFormSent('del')) && (ifPostContainsSelections())) {
108 foreach (postRequestParameter('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'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
118 // Load row template and switch colors
119 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
122 // Load main template
123 loadTemplate('admin_config_admins_del', false, $OUT);
124 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
126 // @TODO Rewrite this to filter 'run_sqls'
127 foreach (postRequestParameter('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 if (isExtensionActive('cache')) {
134 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
138 loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_DELETED--}');
139 } elseif (isFormSent('add')) {
140 // Check if everything is fine...
141 $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
143 // Default ACL is false
145 if (isPostRequestParameterSet('what_menu')) {
147 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
150 if (($mode != postRequestParameter('mode')) || ($ACL)) {
152 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
153 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('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",
156 array(bigintval(postRequestParameter('admin_id')), postRequestParameter('action_menu'), postRequestParameter('what_menu')), __FILE__, __LINE__);
157 if (SQL_HASZERONUMS($result)) {
158 // Finally add the new ACL
159 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
160 VALUES ('%s','%s','%s','%s')",
162 bigintval(postRequestParameter('admin_id')),
163 postRequestParameter('action_menu'),
164 postRequestParameter('what_menu'),
165 postRequestParameter('mode')
166 ), __FILE__, __LINE__);
167 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
169 // Update cache when installed
170 if (isExtensionActive('cache')) {
171 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
174 // ACL does already exist!
175 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
179 SQL_FREERESULT($result);
181 // No menu selected makes also no sence...
182 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
185 // Same mode makes no sence...
186 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
190 loadTemplate('admin_settings_saved', false, $content);
193 $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__);
196 if (!SQL_HASZERONUMS($result_acls)) {
199 while ($content = SQL_FETCHARRAY($result_acls)) {
200 // Generate mode string
201 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
203 // Load row template and switch colors
204 $OUT .= loadTemplate('admin_config_admins_row', true, $content);
208 SQL_FREERESULT($result);
210 // Load main template
211 loadTemplate('admin_config_admins', false, $OUT);
214 // Prepare some constants for the template
215 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
216 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
217 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
218 $content['mode_options'] = generateOptionList(
220 array('allow', 'deny'),
222 'ADMINS_ALLOW_MODE--}',
223 'ADMINS_DENY_MODE--}'
227 // Load template for adding new ACL
228 loadTemplate('admin_admins_add_acl', false, $content);