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 `id`, `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 $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']),
66 'mode_options' => generateOptionList(
68 array('allow', 'deny'),
70 '{--ADMINS_ALLOW_MODE--}',
71 '{--ADMINS_DENY_MODE--}'
73 $content['access_mode']
78 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
82 loadTemplate('admin_config_admins_edit', false, $OUT);
83 } elseif ((isFormSent('change')) && (ifPostContainsSelections())) {
85 foreach (postRequestParameter('sel') as $id => $selected) {
90 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",
92 postRequestParameter('admin', $id),
93 postRequestParameter('action_menu', $id),
94 postRequestParameter('what_menu', $id),
95 postRequestParameter('mode', $id),
97 ),__FILE__, __LINE__);
100 // Update cache when installed
101 if (isExtensionActive('cache')) {
102 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
106 loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
107 } elseif ((isFormSent('del')) && (ifPostContainsSelections())) {
110 foreach (postRequestParameter('sel') as $id => $selected) {
111 // Load data for the id
112 $result = SQL_QUERY_ESC("SELECT `id`, `admin_id`, `action_menu`, `what_menu`, `access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
113 array(bigintval($id)), __FILE__, __LINE__);
114 $content = SQL_FETCHARRAY($result);
115 SQL_FREERESULT($result);
118 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
120 // Load row template and switch colors
121 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
124 // Load main template
125 loadTemplate('admin_config_admins_del', false, $OUT);
126 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
128 // @TODO Rewrite this to filter 'run_sqls'
129 foreach (postRequestParameter('sel') as $id => $selected) {
130 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
131 array(bigintval($id)),__FILE__, __LINE__);
134 // Update cache when installed
135 if (isExtensionActive('cache')) {
136 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
140 loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_DELETED--}');
141 } elseif (isFormSent('add')) {
142 // Check if everything is fine...
143 $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
145 // Default ACL is false
147 if (isPostRequestParameterSet('what_menu')) {
149 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
152 if (($mode != postRequestParameter('mode')) || ($ACL)) {
154 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
155 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('what_menu'))) && ($BOTH === false)) {
156 // Main or sub menu selected
157 $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",
158 array(bigintval(postRequestParameter('admin_id')), postRequestParameter('action_menu'), postRequestParameter('what_menu')), __FILE__, __LINE__);
159 if (SQL_HASZERONUMS($result)) {
160 // Finally add the new ACL
161 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
162 VALUES ('%s','%s','%s','%s')",
164 bigintval(postRequestParameter('admin_id')),
165 postRequestParameter('action_menu'),
166 postRequestParameter('what_menu'),
167 postRequestParameter('mode')
168 ), __FILE__, __LINE__);
169 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
171 // Update cache when installed
172 if (isExtensionActive('cache')) {
173 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
176 // ACL does already exist!
177 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
181 SQL_FREERESULT($result);
183 // No menu selected makes also no sence...
184 $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
187 // Same mode makes no sence...
188 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
192 loadTemplate('admin_settings_saved', false, $content);
195 $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__);
198 if (!SQL_HASZERONUMS($result_acls)) {
201 while ($content = SQL_FETCHARRAY($result_acls)) {
202 // Generate mode string
203 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
205 // Load row template and switch colors
206 $OUT .= loadTemplate('admin_config_admins_row', true, $content);
210 SQL_FREERESULT($result);
212 // Load main template
213 loadTemplate('admin_config_admins', false, $OUT);
216 // Prepare some constants for the template
217 $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
218 $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
219 $content['what_selection'] = adminMenuSelectionBox_DEPRECATED('what');
220 $content['mode_options'] = generateOptionList(
222 array('allow', 'deny'),
224 '{--ADMINS_ALLOW_MODE--}',
225 '{--ADMINS_DENY_MODE--}'
229 // Load template for adding new ACL
230 loadTemplate('admin_add_admins_acl', false, $content);