A lot CSS classes rewritten, please update all your themes.
[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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
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.                                  *
28  *                                                                      *
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.                         *
33  *                                                                      *
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,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 }
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if ((isFormSent('edit')) && (ifPostContainsSelections())) {
49         // Edit ACLs
50         $OUT = '';
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);
56
57                 // Free result
58                 SQL_FREERESULT($result);
59
60                 // Prepare data for the row template
61                 $content = array(
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(
67                                 '/ARRAY/',
68                                 array('allow', 'deny'),
69                                 array(
70                                         '{--ADMINS_ALLOW_MODE--}',
71                                         '{--ADMINS_DENY_MODE--}'
72                                 ),
73                                 $content['access_mode']
74                         ),
75                 );
76
77                 // Load row template
78                 $OUT .= loadTemplate('admin_config_admins_edit_row', true, $content);
79         } // END - foreach
80
81         // Load main template
82         loadTemplate('admin_config_admins_edit', false, $OUT);
83 } elseif ((isFormSent('change')) && (ifPostContainsSelections())) {
84         // Change entries
85         foreach (postRequestParameter('sel') as $id => $selected) {
86                 // Secure id
87                 $id = bigintval($id);
88
89                 // Update entries
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",
91                 array(
92                         postRequestParameter('admin', $id),
93                         postRequestParameter('action_menu', $id),
94                         postRequestParameter('what_menu', $id),
95                         postRequestParameter('mode', $id),
96                         $id
97                 ),__FILE__, __LINE__);
98         } // END - foreach
99
100         // Update cache when installed
101         if (isExtensionActive('cache')) {
102                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
103         } // END - if
104
105         // Entries changed
106         loadTemplate('admin_settings_saved', false, '{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
107 } elseif ((isFormSent('del')) && (ifPostContainsSelections())) {
108         // Delete ACLs
109         $OUT = '';
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);
116
117                 // Get admin mode
118                 $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
119
120                 // Load row template and switch colors
121                 $OUT .= loadTemplate('admin_config_admins_del_row', true, $content);
122         } // END - foreach
123
124         // Load main template
125         loadTemplate('admin_config_admins_del', false, $OUT);
126 } elseif ((isFormSent('remove')) && (ifPostContainsSelections())) {
127         // Remove entries
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__);
132         } // END - foreach
133
134         // Update cache when installed
135         if (isExtensionActive('cache')) {
136                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
137         } // END - if
138
139         // Entries deleted
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')));
144
145         // Default ACL is false
146         $ACL = false;
147         if (isPostRequestParameterSet('what_menu')) {
148                 // Check parent ACL
149                 $ACL = adminsCheckAdminAcl(getActionFromModuleWhat('admin', postRequestParameter('what_menu')), '');
150         } // END - if
151
152         if (($mode != postRequestParameter('mode')) || ($ACL)) {
153                 // Mode is fine
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')",
163                                 array(
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--}';
170
171                                 // Update cache when installed
172                                 if (isExtensionActive('cache')) {
173                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
174                                 } // END - if
175                         } else {
176                                 // ACL does already exist!
177                                 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
178                         }
179
180                         // Free memory
181                         SQL_FREERESULT($result);
182                 } else {
183                         // No menu selected makes also no sence...
184                         $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
185                 }
186         } else {
187                 // Same mode makes no sence...
188                 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
189         }
190
191         // Display message
192         loadTemplate('admin_settings_saved', false, $content);
193 } else {
194         // List all ACLs
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__);
196
197         // Entries found?
198         if (!SQL_HASZERONUMS($result_acls)) {
199                 // List ACLs
200                 $OUT = '';
201                 while ($content = SQL_FETCHARRAY($result_acls)) {
202                         // Generate mode string
203                         $content['access_mode'] = '{--ADMINS_' . strtoupper($content['access_mode']) . '_MODE--}';
204
205                         // Load row template and switch colors
206                         $OUT .= loadTemplate('admin_config_admins_row', true, $content);
207                 } // END - while
208
209                 // Free memory
210                 SQL_FREERESULT($result);
211
212                 // Load main template
213                 loadTemplate('admin_config_admins', false, $OUT);
214         } // END - if
215
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(
221                 '/ARRAY/',
222                 array('allow', 'deny'),
223                 array(
224                         '{--ADMINS_ALLOW_MODE--}',
225                         '{--ADMINS_DENY_MODE--}'
226                 )
227         );
228
229         // Load template for adding new ACL
230         loadTemplate('admin_add_admins_acl', false, $content);
231 }
232
233 // [EOF]
234 ?>