f98b503e9ee917c5bd6c1999337234943a257961
[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  * -------------------------------------------------------------------- *
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                  *
21  *                                                                      *
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.                                  *
26  *                                                                      *
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.                         *
31  *                                                                      *
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,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
40         die();
41 } // END - if
42
43 // Add description as navigation point
44 addYouAreHereLink('admin', __FILE__);
45
46 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
47         // Edit ACLs
48         $OUT = '';
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);
54
55                 // Free result
56                 SQL_FREERESULT($result);
57
58                 // Prepare data for the row template
59                 $content = array(
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(
65                                 '/ARRAY/',
66                                 array('allow', 'deny'),
67                                 array(
68                                         '{--ADMIN_ADMINS_MODE_ALLOW--}',
69                                         '{--ADMIN_ADMINS_MODE_DENY--}'
70                                 ),
71                                 $content['access_mode']
72                         ),
73                 );
74
75                 // Load row template
76                 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
77         } // END - foreach
78
79         // Load main template
80         loadTemplate('admin_config_admins_edit', false, $OUT);
81 } elseif ((isFormSent('change')) && (ifPostContainsSelections())) {
82         // Change entries
83         foreach (postRequestParameter('sel') as $id => $selected) {
84                 // Secure id
85                 $id = bigintval($id);
86
87                 // Update entries
88                 SQL_QUERY_ESC("UPDATE
89         `{?_MYSQL_PREFIX?}_admins_acls`
90 SET
91         `admin_id`=%s,
92         `action_menu`='%s',
93         `what_menu`='%s',
94         `access_mode`='%s'
95 WHERE
96         `id`=%s
97 LIMIT 1",
98                         array(
99                                 postRequestParameter('admin', $id),
100                                 postRequestParameter('action_menu', $id),
101                                 postRequestParameter('what_menu', $id),
102                                 postRequestParameter('mode', $id),
103                                 $id
104                         ),__FILE__, __LINE__);
105         } // END - foreach
106
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();
111         } // END - if
112
113         // Entries changed
114         displayMessage('{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
115 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
116         // Delete ACLs
117         $OUT = '';
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);
124
125                 // Get admin mode
126                 $content['access_mode'] = '{--ADMIN_ADMINS_MODE_' . strtoupper($content['access_mode']) . '--}';
127
128                 // Load row template and switch colors
129                 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
130         } // END - foreach
131
132         // Load main template
133         loadTemplate('admin_config_admins_del', false, $OUT);
134 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
135         // Remove entries
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__);
140         } // END - foreach
141
142         // Update cache when installed
143         if (isExtensionActive('cache')) {
144                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
145         } // END - if
146
147         // Entries deleted
148         displayMessage('{--ADMIN_ADMINS_ENTRIES_DELETED--}');
149 } elseif (isFormSent('add')) {
150         // Check if everything is fine...
151         $mode = getAdminDefaultAcl(bigintval(postRequestParameter('admin_id')));
152
153         // Default ACL is false
154         $ACL = false;
155         if (isPostRequestParameterSet('what_menu')) {
156                 // Check parent ACL
157                 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
158         } // END - if
159
160         if (($mode != postRequestParameter('mode')) || ($ACL)) {
161                 // Mode is fine
162                 $BOTH = ((isPostRequestParameterSet('action_menu')) && (isPostRequestParameterSet('what_menu')));
163                 if (((isPostRequestParameterSet('action_menu')) || (isPostRequestParameterSet('what_menu'))) && ($BOTH === false)) {
164                         // Main or sub menu selected
165                         $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",
166                                 array(
167                                         bigintval(postRequestParameter('admin_id')),
168                                         postRequestParameter('action_menu'),
169                                         postRequestParameter('what_menu')
170                                 ), __FILE__, __LINE__);
171                         if (SQL_HASZERONUMS($result)) {
172                                 // Finally add the new ACL
173                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (`admin_id`, `action_menu`, `what_menu`, `access_mode`)
174 VALUES ('%s','%s','%s','%s')",
175                                 array(
176                                         bigintval(postRequestParameter('admin_id')),
177                                         postRequestParameter('action_menu'),
178                                         postRequestParameter('what_menu'),
179                                         postRequestParameter('mode')
180                                 ), __FILE__, __LINE__);
181                                 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
182
183                                 // Update cache when installed
184                                 if (isExtensionActive('cache')) {
185                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
186                                 } // END - if
187                         } else {
188                                 // ACL does already exist!
189                                 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
190                         }
191
192                         // Free memory
193                         SQL_FREERESULT($result);
194                 } else {
195                         // No menu selected makes also no sence...
196                         $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
197                 }
198         } else {
199                 // Same mode makes no sence...
200                 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
201         }
202
203         // Display message
204         displayMessage($content);
205 } else {
206         // List all ACLs
207         $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__);
208
209         // Entries found?
210         if (!SQL_HASZERONUMS($result_acls)) {
211                 // List ACLs
212                 $OUT = '';
213                 while ($content = SQL_FETCHARRAY($result_acls)) {
214                         // Generate mode string
215                         $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
216
217                         // Load row template and switch colors
218                         $OUT .= loadTemplate('admin_config_admins_row', true, $content);
219                 } // END - while
220
221                 // Free memory
222                 SQL_FREERESULT($result);
223
224                 // Load main template
225                 loadTemplate('admin_config_admins', false, $OUT);
226         } // END - if
227
228         // Prepare some constants for the template
229         $content['admins_selection'] = generateOptionList('admins', 'id', 'login', '', 'default_acl');
230         $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
231         $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
232         $content['mode_options']     = generateOptionList(
233                 '/ARRAY/',
234                 array('allow', 'deny'),
235                 array(
236                         '{--ADMIN_ADMINS_MODE_ALLOW--}',
237                         '{--ADMIN_ADMINS_MODE_DENY--}'
238                 )
239         );
240
241         // Load template for adding new ACL
242         loadTemplate('admin_add_admins_acl', false, $content);
243 }
244
245 // [EOF]
246 ?>