Missing SVN properties set
[mailer.git] / inc / modules / admin / what-config_admins.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/30/2004 *
4  * ===================                          Last change: 07/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File: what-config_admins.php                                         *
8  * -------------------------------------------------------------------- *
9  * Short description : Configure admin ACLs                             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Admin-ACLs einstellen                            *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
23  * This program is free software; you can redistribute it and/or modify *
24  * it under the terms of the GNU General Public License as published by *
25  * the Free Software Foundation; either version 2 of the License, or    *
26  * (at your option) any later version.                                  *
27  *                                                                      *
28  * This program is distributed in the hope that it will be useful,      *
29  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
30  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
31  * GNU General Public License for more details.                         *
32  *                                                                      *
33  * You should have received a copy of the GNU General Public License    *
34  * along with this program; if not, write to the Free Software          *
35  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 }
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if ((isPostRequestElementSet('edit')) && (countPostSelection() > 0)) {
48         // Edit ACLs
49         $OUT = ''; $SW = 2;
50         foreach (postRequestElement('sel') as $id => $selected) {
51                 // Load data for the id
52                 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
53                         array(bigintval($id)), __FILE__, __LINE__);
54                 list($adminId, $action, $what, $mode) = SQL_FETCHROW($result);
55                 SQL_FREERESULT($result);
56
57                 // Prepare data for the row template
58                 $content = array(
59                         'sw'               => $SW,
60                         'id'               => $id,
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(
65                                 '/ARRAY/',
66                                 array('allow', 'deny'),
67                                 array(
68                                         getMessage('ADMINS_ALLOW_MODE'),
69                                         getMessage('ADMINS_DENY_MODE')
70                                 ),
71                                 $mode
72                         ),
73                 );
74
75                 // Load row template
76                 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
77                 $SW = 3 - $SW;
78         }
79
80         // Load main template
81         loadTemplate('admin_config_admins_edit', false, $OUT);
82 } elseif ((isPostRequestElementSet('change')) && (countPostSelection() > 0)) {
83         // Change entries
84         foreach (postRequestElement('sel') as $id => $selected) {
85                 // Secure id
86                 $id = bigintval($id);
87
88                 // Update entries
89                 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                 array(
91                         postRequestElement('admin', $id),
92                         postRequestElement('action_menu', $id),
93                         postRequestElement('what_menu', $id),
94                         postRequestElement('mode', $id),
95                         $id
96                 ),__FILE__, __LINE__);
97         } // END - foreach
98
99         // Update cache when installed
100         if (isExtensionActive('cache')) {
101                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
102         } // END - if
103
104         // Entries changed
105         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_CHANGED'));
106 } elseif ((isPostRequestElementSet('del')) && (countPostSelection() > 0)) {
107         // Delete ACLs
108         $OUT = ''; $SW = 2;
109         foreach (postRequestElement('sel') as $id => $selected) {
110                 // Load data for the id
111                 $result = SQL_QUERY_ESC("SELECT admin_id, action_menu, what_menu, access_mode FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
112                         array(bigintval($id)), __FILE__, __LINE__);
113                 list($admin, $action, $what, $mode) = SQL_FETCHROW($result);
114                 SQL_FREERESULT($result);
115
116                 // Prepare variables
117                 if (empty($action)) $action = '---';
118                 if (empty($what)) $what = '---';
119
120                 // Get admin mode
121                 $mode = getMessage('ADMINS_'.strtoupper($mode).'_MODE');
122
123                 // Generate link
124                 $admin = generateAdminLink($admin);
125
126                 // Prepare data for the row template
127                 $content = array(
128                         'sw'     => $SW,
129                         'id'     => $id,
130                         'admin'  => $admin,
131                         'action' => $action,
132                         'what'   => $what,
133                         'mode'   => $mode,
134                 );
135
136                 // Load row template and switch colors
137                 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
138                 $SW = 3 - $SW;
139         } // END - foreach
140
141         // Load main template
142         loadTemplate('admin_config_admins_del', false, $OUT);
143 } elseif ((isPostRequestElementSet('remove')) && (countPostSelection() > 0)) {
144         // Remove entries
145         // @TODO Rewrite this to filter 'run_sqls'
146         foreach (postRequestElement('sel') as $id => $selected) {
147                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
148                         array(bigintval($id)),__FILE__, __LINE__);
149         } // END - foreach
150
151         // Update cache when installed
152         if (isExtensionActive('cache')) {
153                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
154         } // END - if
155
156         // Entries deleted
157         loadTemplate('admin_settings_saved', false, getMessage('ADMIN_ADMINS_ENTRIES_DELETED'));
158 } elseif (isPostRequestElementSet('add')) {
159         // Check if everything is fine...
160         $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
161
162         // Default ACL is false
163         $ACL = false;
164         if (isPostRequestElementSet('what_menu')) {
165                 // Check parent ACL
166                 $ACL = adminsCheckAdminAcl(getModeAction('admin', postRequestElement('what_menu')), '');
167         } // END - if
168
169         if (($mode != postRequestElement('mode')) || ($ACL)) {
170                 // Mode is fine
171                 $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')));
172                 if (((isPostRequestElementSet('action_menu')) || (isPostRequestElementSet('what_menu'))) && ($BOTH === false)) {
173                         // Main or sub menu selected
174                         $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",
175                                 array(bigintval(postRequestElement('admin_id')), postRequestElement('action_menu'), postRequestElement('what_menu')), __FILE__, __LINE__);
176                         if (SQL_NUMROWS($result) == '0') {
177                                 // Finally add the new ACL
178                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (admin_id, action_menu, what_menu, access_mode)
179 VALUES ('%s','%s','%s','%s')",
180                                 array(
181                                         bigintval(postRequestElement('admin_id')),
182                                         postRequestElement('action_menu'),
183                                         postRequestElement('what_menu'),
184                                         postRequestElement('mode')
185                                 ), __FILE__, __LINE__);
186                                 $content = getMessage('ADMIN_ADMINS_ACL_SAVED');
187
188                                 // Update cache when installed
189                                 if (isExtensionActive('cache')) {
190                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
191                                 } // END - if
192                         } else {
193                                 // ACL does already exist!
194                                 $content = getMessage('ADMIN_ADMINS_ACL_ALREADY_ADDED');
195                         }
196
197                         // Free memory
198                         SQL_FREERESULT($result);
199                 } else {
200                         // No menu selected makes also no sence...
201                         $content = getMessage('ADMIN_ADMINS_SELECT_ACTION_WHAT');
202                 }
203         } else {
204                 // Same mode makes no sence...
205                 $content = getMessage('ADMIN_ADMINS_SAME_MODE_SELECTED');
206         }
207
208         // Display message
209         loadTemplate('admin_settings_saved', false, $content);
210 } else {
211         // List all ACLs
212         $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__);
213
214         // Entries found?
215         if (SQL_NUMROWS($result_acls) > 0) {
216                 // List ACLs
217                 $OUT = ''; $SW = 2;
218                 while ($content = SQL_FETCHARRAY($result_acls)) {
219                         // Prepare variables
220                         if (empty($content['action_menu'])) $content['action_menu'] = '---';
221                         if (empty($content['what_menu']))   $content['what_menu']   = '---';
222
223                         // Get mode
224                         $content['access_mode'] = getMessage('ADMINS_'.strtoupper($content['access_mode']).'_MODE');
225
226                         // Prepare data for the row template
227                         $content = array(
228                                 'sw'     => $SW,
229                                 'id'     => $content['id'],
230                                 'admin'  => generateAdminLink($content['admin_id']),
231                                 'action' => $content['action_menu'],
232                                 'what'   => $content['what_menu'],
233                                 'mode'   => $content['access_mode'],
234                         );
235
236                         // Load row template and switch colors
237                         $OUT .= loadTemplate('admin_config_admins_row', true, $content);
238                         $SW = 3 - $SW;
239                 } // END - while
240
241                 // Free memory
242                 SQL_FREERESULT($result);
243
244                 // Load main template
245                 loadTemplate('admin_config_admins', false, $OUT);
246         } // END - if
247
248         // Prepare some constants for the template
249         $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
250         $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
251         $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
252         $content['mode_options']     = generateOptionList(
253                 '/ARRAY/',
254                 array('allow', 'deny'),
255                 array(
256                         getMessage('ADMINS_ALLOW_MODE'),
257                         getMessage('ADMINS_DENY_MODE')
258                 )
259         );
260
261         // Load template for adding new ACL
262         loadTemplate('admin_admins_add_acl', false, $content);
263 }
264
265 //
266 ?>