mailer project continued:
[mailer.git] / inc / modules / admin / what-list_admins_acls.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/30/2011 *
4  * ===================                          Last change: 06/30/2011 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_admins_acls.php                        *
8  * -------------------------------------------------------------------- *
9  * Short description : List admin access control lines (ACLs)           *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Auflisten von Zugriffskontrollzeilen (ACLs)      *
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 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://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 (postRequestElement('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
54                 // Load all data
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' => generateOptions('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                 );
67
68                 // Load row template
69                 $OUT .= loadTemplate('admin_edit_admins_acls_row', true, $content);
70         } // END - foreach
71
72         // Load main template
73         loadTemplate('admin_edit_admins_acls', false, $OUT);
74 } elseif ((isFormSent('do_edit')) && (ifPostContainsSelections())) {
75         // Change entries
76         foreach (postRequestElement('sel') as $id => $selected) {
77                 // Secure id
78                 $id = bigintval($id);
79
80                 // Update entries
81                 SQL_QUERY_ESC("UPDATE
82         `{?_MYSQL_PREFIX?}_admins_acls`
83 SET
84         `admin_id`=%s,
85         `action_menu`='%s',
86         `what_menu`='%s',
87         `access_mode`='%s'
88 WHERE
89         `id`=%s
90 LIMIT 1",
91                         array(
92                                 postRequestElement('admin', $id),
93                                 postRequestElement('action_menu', $id),
94                                 postRequestElement('what_menu', $id),
95                                 postRequestElement('access_mode', $id),
96                                 $id
97                         ),__FILE__, __LINE__);
98         } // END - foreach
99
100         // Update cache when installed
101         // @TODO Rewrite this to a filter
102         if (isExtensionActive('cache')) {
103                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
104         } // END - if
105
106         // Entries changed
107         displayMessage('{--ADMIN_ADMINS_ENTRIES_CHANGED--}');
108 } elseif ((isFormSent('delete')) && (ifPostContainsSelections())) {
109         // Delete ACLs
110         $OUT = '';
111         foreach (postRequestElement('sel') as $id => $selected) {
112                 // Load data for the id
113                 $result = SQL_QUERY_ESC("SELECT `id`,`admin_id`,`action_menu`,`what_menu`,`access_mode` FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
114                         array(bigintval($id)), __FILE__, __LINE__);
115                 $content = SQL_FETCHARRAY($result);
116                 SQL_FREERESULT($result);
117
118                 // Get admin mode
119                 $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
120
121                 // Load row template and switch colors
122                 $OUT .= loadTemplate('admin_delete_admins_acls_row', true, $content);
123         } // END - foreach
124
125         // Load main template
126         loadTemplate('admin_delete_admins_acls', false, $OUT);
127 } elseif ((isFormSent('do_delete')) && (ifPostContainsSelections())) {
128         // Remove entries
129         // @TODO Rewrite this to filter 'run_sqls'
130         foreach (postRequestElement('sel') as $id => $selected) {
131                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_admins_acls` WHERE `id`=%s LIMIT 1",
132                         array(bigintval($id)),__FILE__, __LINE__);
133         } // END - foreach
134
135         // Update cache when installed
136         if (isExtensionActive('cache')) {
137                 if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
138         } // END - if
139
140         // Entries deleted
141         displayMessage('{--ADMIN_ADMINS_ENTRIES_DELETED--}');
142 } elseif (isFormSent('add')) {
143         // Check if everything is fine...
144         $mode = getAdminDefaultAcl(bigintval(postRequestElement('admin_id')));
145
146         // Default ACL is false
147         $ACL = false;
148         if (isPostRequestElementSet('what_menu')) {
149                 // Check parent ACL
150                 $ACL = isAdminsAllowedByAcl(getActionFromModuleWhat('admin', postRequestElement('what_menu')), '');
151         } // END - if
152
153         if (($mode != postRequestElement('do')) || (($ACL === true) && (postRequestElement('do') == 'deny'))) {
154                 // Mode is fine
155                 $BOTH = ((isPostRequestElementSet('action_menu')) && (isPostRequestElementSet('what_menu')) && (postRequestElement('action_menu') != '') && (postRequestElement('what_menu') != ''));
156
157                 // Check if one has been selected
158                 if ((((isPostRequestElementSet('action_menu')) && (postRequestElement('action_menu') != '')) || ((isPostRequestElementSet('what_menu')) && (postRequestElement('what_menu') != ''))) && ($BOTH === false)) {
159                         // Main or sub menu selected
160                         $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",
161                                 array(
162                                         bigintval(postRequestElement('admin_id')),
163                                         postRequestElement('action_menu'),
164                                         postRequestElement('what_menu')
165                                 ), __FILE__, __LINE__);
166                         if (SQL_HASZERONUMS($result)) {
167                                 // Finally add the new ACL
168                                 SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_admins_acls` (`admin_id`,`action_menu`,`what_menu`,`access_mode`)
169 VALUES (%s,'%s','%s','%s')",
170                                 array(
171                                         bigintval(postRequestElement('admin_id')),
172                                         postRequestElement('action_menu'),
173                                         postRequestElement('what_menu'),
174                                         postRequestElement('do')
175                                 ), __FILE__, __LINE__);
176                                 $content = '{--ADMIN_ADMINS_ACL_SAVED--}';
177
178                                 // Update cache when installed
179                                 if (isExtensionActive('cache')) {
180                                         if ($GLOBALS['cache_instance']->loadCacheFile('admin_acls')) $GLOBALS['cache_instance']->removeCacheFile();
181                                 } // END - if
182                         } else {
183                                 // ACL does already exist!
184                                 $content = '{--ADMIN_ADMINS_ACL_ALREADY_ADDED--}';
185                         }
186
187                         // Free memory
188                         SQL_FREERESULT($result);
189                 } else {
190                         // No menu selected makes also no sence...
191                         $content = '{--ADMIN_ADMINS_SELECT_ACTION_WHAT--}';
192                 }
193         } else {
194                 // Same mode makes no sence...
195                 $content = '{--ADMIN_ADMINS_SAME_MODE_SELECTED--}';
196         }
197
198         // Display message
199         displayMessage($content);
200 } else {
201         // List all ACLs
202         $result = 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__);
203
204         // Entries found?
205         if (!SQL_HASZERONUMS($result)) {
206                 // List ACLs
207                 $OUT = '';
208                 while ($content = SQL_FETCHARRAY($result)) {
209                         // Generate mode string
210                         $content['access_mode'] = '{--ADMIN_ADMINS_ACCESS_MODE_' . strtoupper($content['access_mode']) . '--}';
211
212                         // Load row template and switch colors
213                         $OUT .= loadTemplate('admin_list_admins_acls_row', true, $content);
214                 } // END - while
215
216                 // Free memory
217                 SQL_FREERESULT($result);
218
219                 // Load main template
220                 loadTemplate('admin_list_admins_acls', false, $OUT);
221         } // END - if
222
223         // Prepare some constants for the template
224         $content['admins_selection'] = generateOptions('admins', 'id', 'login', '', 'default_acl');
225         $content['action_selection'] = adminMenuSelectionBox_DEPRECATED('action');
226         $content['what_selection']   = adminMenuSelectionBox_DEPRECATED('what');
227
228         // Load template for adding new ACL
229         loadTemplate('admin_add_admins_acl', false, $content);
230 }
231
232 // [EOF]
233 ?>