|
indvdum@0
|
1 |
<?php
|
|
indvdum@0
|
2 |
/**
|
|
indvdum@0
|
3 |
*
|
|
indvdum@0
|
4 |
* @package acp
|
|
indvdum@0
|
5 |
* @version $Id$
|
|
indvdum@0
|
6 |
* @copyright (c) 2005 phpBB Group
|
|
indvdum@0
|
7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
indvdum@0
|
8 |
*
|
|
indvdum@0
|
9 |
*/
|
|
indvdum@0
|
10 |
|
|
indvdum@0
|
11 |
/**
|
|
indvdum@0
|
12 |
* @ignore
|
|
indvdum@0
|
13 |
*/
|
|
indvdum@0
|
14 |
if (!defined('IN_PHPBB'))
|
|
indvdum@0
|
15 |
{
|
|
indvdum@0
|
16 |
exit;
|
|
indvdum@0
|
17 |
}
|
|
indvdum@0
|
18 |
|
|
indvdum@0
|
19 |
/**
|
|
indvdum@0
|
20 |
* @package acp
|
|
indvdum@0
|
21 |
*/
|
|
indvdum@0
|
22 |
class acp_permission_roles
|
|
indvdum@0
|
23 |
{
|
|
indvdum@0
|
24 |
var $u_action;
|
|
indvdum@0
|
25 |
|
|
indvdum@0
|
26 |
function main($id, $mode)
|
|
indvdum@0
|
27 |
{
|
|
indvdum@0
|
28 |
global $db, $user, $auth, $template, $cache;
|
|
indvdum@0
|
29 |
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
|
|
indvdum@0
|
30 |
|
|
indvdum@0
|
31 |
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
|
|
indvdum@0
|
32 |
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
|
|
indvdum@0
|
33 |
|
|
indvdum@0
|
34 |
$auth_admin = new auth_admin();
|
|
indvdum@0
|
35 |
|
|
indvdum@0
|
36 |
$user->add_lang('acp/permissions');
|
|
indvdum@0
|
37 |
add_permission_language();
|
|
indvdum@0
|
38 |
|
|
indvdum@0
|
39 |
$this->tpl_name = 'acp_permission_roles';
|
|
indvdum@0
|
40 |
|
|
indvdum@0
|
41 |
$submit = (isset($_POST['submit'])) ? true : false;
|
|
indvdum@0
|
42 |
$role_id = request_var('role_id', 0);
|
|
indvdum@0
|
43 |
$action = request_var('action', '');
|
|
indvdum@0
|
44 |
$action = (isset($_POST['add'])) ? 'add' : $action;
|
|
indvdum@0
|
45 |
|
|
indvdum@0
|
46 |
$form_name = 'acp_permissions';
|
|
indvdum@0
|
47 |
add_form_key($form_name);
|
|
indvdum@0
|
48 |
|
|
indvdum@0
|
49 |
switch ($mode)
|
|
indvdum@0
|
50 |
{
|
|
indvdum@0
|
51 |
case 'admin_roles':
|
|
indvdum@0
|
52 |
$permission_type = 'a_';
|
|
indvdum@0
|
53 |
$this->page_title = 'ACP_ADMIN_ROLES';
|
|
indvdum@0
|
54 |
break;
|
|
indvdum@0
|
55 |
|
|
indvdum@0
|
56 |
case 'user_roles':
|
|
indvdum@0
|
57 |
$permission_type = 'u_';
|
|
indvdum@0
|
58 |
$this->page_title = 'ACP_USER_ROLES';
|
|
indvdum@0
|
59 |
break;
|
|
indvdum@0
|
60 |
|
|
indvdum@0
|
61 |
case 'mod_roles':
|
|
indvdum@0
|
62 |
$permission_type = 'm_';
|
|
indvdum@0
|
63 |
$this->page_title = 'ACP_MOD_ROLES';
|
|
indvdum@0
|
64 |
break;
|
|
indvdum@0
|
65 |
|
|
indvdum@0
|
66 |
case 'forum_roles':
|
|
indvdum@0
|
67 |
$permission_type = 'f_';
|
|
indvdum@0
|
68 |
$this->page_title = 'ACP_FORUM_ROLES';
|
|
indvdum@0
|
69 |
break;
|
|
indvdum@0
|
70 |
|
|
indvdum@0
|
71 |
default:
|
|
indvdum@0
|
72 |
trigger_error('NO_MODE', E_USER_ERROR);
|
|
indvdum@0
|
73 |
break;
|
|
indvdum@0
|
74 |
}
|
|
indvdum@0
|
75 |
|
|
indvdum@0
|
76 |
$template->assign_vars(array(
|
|
indvdum@0
|
77 |
'L_TITLE' => $user->lang[$this->page_title],
|
|
indvdum@0
|
78 |
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])
|
|
indvdum@0
|
79 |
);
|
|
indvdum@0
|
80 |
|
|
indvdum@0
|
81 |
// Take action... admin submitted something
|
|
indvdum@0
|
82 |
if ($submit || $action == 'remove')
|
|
indvdum@0
|
83 |
{
|
|
indvdum@0
|
84 |
switch ($action)
|
|
indvdum@0
|
85 |
{
|
|
indvdum@0
|
86 |
case 'remove':
|
|
indvdum@0
|
87 |
|
|
indvdum@0
|
88 |
if (!$role_id)
|
|
indvdum@0
|
89 |
{
|
|
indvdum@0
|
90 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
91 |
}
|
|
indvdum@0
|
92 |
|
|
indvdum@0
|
93 |
$sql = 'SELECT *
|
|
indvdum@0
|
94 |
FROM ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
95 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
96 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
97 |
$role_row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
98 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
99 |
|
|
indvdum@0
|
100 |
if (!$role_row)
|
|
indvdum@0
|
101 |
{
|
|
indvdum@0
|
102 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
103 |
}
|
|
indvdum@0
|
104 |
|
|
indvdum@0
|
105 |
if (confirm_box(true))
|
|
indvdum@0
|
106 |
{
|
|
indvdum@0
|
107 |
$this->remove_role($role_id, $permission_type);
|
|
indvdum@0
|
108 |
|
|
indvdum@0
|
109 |
$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
|
|
indvdum@0
|
110 |
add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_REMOVED', $role_name);
|
|
indvdum@0
|
111 |
trigger_error($user->lang['ROLE_DELETED'] . adm_back_link($this->u_action));
|
|
indvdum@0
|
112 |
}
|
|
indvdum@0
|
113 |
else
|
|
indvdum@0
|
114 |
{
|
|
indvdum@0
|
115 |
confirm_box(false, 'DELETE_ROLE', build_hidden_fields(array(
|
|
indvdum@0
|
116 |
'i' => $id,
|
|
indvdum@0
|
117 |
'mode' => $mode,
|
|
indvdum@0
|
118 |
'role_id' => $role_id,
|
|
indvdum@0
|
119 |
'action' => $action,
|
|
indvdum@0
|
120 |
)));
|
|
indvdum@0
|
121 |
}
|
|
indvdum@0
|
122 |
|
|
indvdum@0
|
123 |
break;
|
|
indvdum@0
|
124 |
|
|
indvdum@0
|
125 |
case 'edit':
|
|
indvdum@0
|
126 |
if (!$role_id)
|
|
indvdum@0
|
127 |
{
|
|
indvdum@0
|
128 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
129 |
}
|
|
indvdum@0
|
130 |
|
|
indvdum@0
|
131 |
// Get role we edit
|
|
indvdum@0
|
132 |
$sql = 'SELECT *
|
|
indvdum@0
|
133 |
FROM ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
134 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
135 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
136 |
$role_row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
137 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
138 |
|
|
indvdum@0
|
139 |
if (!$role_row)
|
|
indvdum@0
|
140 |
{
|
|
indvdum@0
|
141 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
142 |
}
|
|
indvdum@0
|
143 |
|
|
indvdum@0
|
144 |
// no break;
|
|
indvdum@0
|
145 |
|
|
indvdum@0
|
146 |
case 'add':
|
|
indvdum@0
|
147 |
|
|
indvdum@0
|
148 |
if (!check_form_key($form_name))
|
|
indvdum@0
|
149 |
{
|
|
indvdum@0
|
150 |
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
151 |
}
|
|
indvdum@0
|
152 |
|
|
indvdum@0
|
153 |
$role_name = utf8_normalize_nfc(request_var('role_name', '', true));
|
|
indvdum@0
|
154 |
$role_description = utf8_normalize_nfc(request_var('role_description', '', true));
|
|
indvdum@0
|
155 |
$auth_settings = request_var('setting', array('' => 0));
|
|
indvdum@0
|
156 |
|
|
indvdum@0
|
157 |
if (!$role_name)
|
|
indvdum@0
|
158 |
{
|
|
indvdum@0
|
159 |
trigger_error($user->lang['NO_ROLE_NAME_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
160 |
}
|
|
indvdum@0
|
161 |
|
|
indvdum@0
|
162 |
if (utf8_strlen($role_description) > 4000)
|
|
indvdum@0
|
163 |
{
|
|
indvdum@0
|
164 |
trigger_error($user->lang['ROLE_DESCRIPTION_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
165 |
}
|
|
indvdum@0
|
166 |
|
|
indvdum@0
|
167 |
// if we add/edit a role we check the name to be unique among the settings...
|
|
indvdum@0
|
168 |
$sql = 'SELECT role_id
|
|
indvdum@0
|
169 |
FROM ' . ACL_ROLES_TABLE . "
|
|
indvdum@0
|
170 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'
|
|
indvdum@0
|
171 |
AND role_name = '" . $db->sql_escape($role_name) . "'";
|
|
indvdum@0
|
172 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
173 |
$row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
174 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
175 |
|
|
indvdum@0
|
176 |
// Make sure we only print out the error if we add the role or change it's name
|
|
indvdum@0
|
177 |
if ($row && ($mode == 'add' || ($mode == 'edit' && $role_row['role_name'] != $role_name)))
|
|
indvdum@0
|
178 |
{
|
|
indvdum@0
|
179 |
trigger_error(sprintf($user->lang['ROLE_NAME_ALREADY_EXIST'], $role_name) . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
180 |
}
|
|
indvdum@0
|
181 |
|
|
indvdum@0
|
182 |
$sql_ary = array(
|
|
indvdum@0
|
183 |
'role_name' => (string) $role_name,
|
|
indvdum@0
|
184 |
'role_description' => (string) $role_description,
|
|
indvdum@0
|
185 |
'role_type' => (string) $permission_type,
|
|
indvdum@0
|
186 |
);
|
|
indvdum@0
|
187 |
|
|
indvdum@0
|
188 |
if ($action == 'edit')
|
|
indvdum@0
|
189 |
{
|
|
indvdum@0
|
190 |
$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
191 |
SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
|
|
indvdum@0
|
192 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
193 |
$db->sql_query($sql);
|
|
indvdum@0
|
194 |
}
|
|
indvdum@0
|
195 |
else
|
|
indvdum@0
|
196 |
{
|
|
indvdum@0
|
197 |
// Get maximum role order for inserting a new role...
|
|
indvdum@0
|
198 |
$sql = 'SELECT MAX(role_order) as max_order
|
|
indvdum@0
|
199 |
FROM ' . ACL_ROLES_TABLE . "
|
|
indvdum@0
|
200 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'";
|
|
indvdum@0
|
201 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
202 |
$max_order = (int) $db->sql_fetchfield('max_order');
|
|
indvdum@0
|
203 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
204 |
|
|
indvdum@0
|
205 |
$sql_ary['role_order'] = $max_order + 1;
|
|
indvdum@0
|
206 |
|
|
indvdum@0
|
207 |
$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
|
|
indvdum@0
|
208 |
$db->sql_query($sql);
|
|
indvdum@0
|
209 |
|
|
indvdum@0
|
210 |
$role_id = $db->sql_nextid();
|
|
indvdum@0
|
211 |
}
|
|
indvdum@0
|
212 |
|
|
indvdum@0
|
213 |
// Now add the auth settings
|
|
indvdum@0
|
214 |
$auth_admin->acl_set_role($role_id, $auth_settings);
|
|
indvdum@0
|
215 |
|
|
indvdum@0
|
216 |
$role_name = (!empty($user->lang[$role_name])) ? $user->lang[$role_name] : $role_name;
|
|
indvdum@0
|
217 |
add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_' . strtoupper($action), $role_name);
|
|
indvdum@0
|
218 |
|
|
indvdum@0
|
219 |
trigger_error($user->lang['ROLE_' . strtoupper($action) . '_SUCCESS'] . adm_back_link($this->u_action));
|
|
indvdum@0
|
220 |
|
|
indvdum@0
|
221 |
break;
|
|
indvdum@0
|
222 |
}
|
|
indvdum@0
|
223 |
}
|
|
indvdum@0
|
224 |
|
|
indvdum@0
|
225 |
// Display screens
|
|
indvdum@0
|
226 |
switch ($action)
|
|
indvdum@0
|
227 |
{
|
|
indvdum@0
|
228 |
case 'add':
|
|
indvdum@0
|
229 |
|
|
indvdum@0
|
230 |
$options_from = request_var('options_from', 0);
|
|
indvdum@0
|
231 |
|
|
indvdum@0
|
232 |
$role_row = array(
|
|
indvdum@0
|
233 |
'role_name' => utf8_normalize_nfc(request_var('role_name', '', true)),
|
|
indvdum@0
|
234 |
'role_description' => utf8_normalize_nfc(request_var('role_description', '', true)),
|
|
indvdum@0
|
235 |
'role_type' => $permission_type,
|
|
indvdum@0
|
236 |
);
|
|
indvdum@0
|
237 |
|
|
indvdum@0
|
238 |
if ($options_from)
|
|
indvdum@0
|
239 |
{
|
|
indvdum@0
|
240 |
$sql = 'SELECT p.auth_option_id, p.auth_setting, o.auth_option
|
|
indvdum@0
|
241 |
FROM ' . ACL_ROLES_DATA_TABLE . ' p, ' . ACL_OPTIONS_TABLE . ' o
|
|
indvdum@0
|
242 |
WHERE o.auth_option_id = p.auth_option_id
|
|
indvdum@0
|
243 |
AND p.role_id = ' . $options_from . '
|
|
indvdum@0
|
244 |
ORDER BY p.auth_option_id';
|
|
indvdum@0
|
245 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
246 |
|
|
indvdum@0
|
247 |
$auth_options = array();
|
|
indvdum@0
|
248 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
249 |
{
|
|
indvdum@0
|
250 |
$auth_options[$row['auth_option']] = $row['auth_setting'];
|
|
indvdum@0
|
251 |
}
|
|
indvdum@0
|
252 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
253 |
}
|
|
indvdum@0
|
254 |
else
|
|
indvdum@0
|
255 |
{
|
|
indvdum@0
|
256 |
$sql = 'SELECT auth_option_id, auth_option
|
|
indvdum@0
|
257 |
FROM ' . ACL_OPTIONS_TABLE . "
|
|
indvdum@0
|
258 |
WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char) . "
|
|
indvdum@0
|
259 |
AND auth_option <> '{$permission_type}'
|
|
indvdum@0
|
260 |
ORDER BY auth_option_id";
|
|
indvdum@0
|
261 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
262 |
|
|
indvdum@0
|
263 |
$auth_options = array();
|
|
indvdum@0
|
264 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
265 |
{
|
|
indvdum@0
|
266 |
$auth_options[$row['auth_option']] = ACL_NO;
|
|
indvdum@0
|
267 |
}
|
|
indvdum@0
|
268 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
269 |
}
|
|
indvdum@0
|
270 |
|
|
indvdum@0
|
271 |
// no break;
|
|
indvdum@0
|
272 |
|
|
indvdum@0
|
273 |
case 'edit':
|
|
indvdum@0
|
274 |
|
|
indvdum@0
|
275 |
if ($action == 'edit')
|
|
indvdum@0
|
276 |
{
|
|
indvdum@0
|
277 |
if (!$role_id)
|
|
indvdum@0
|
278 |
{
|
|
indvdum@0
|
279 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
280 |
}
|
|
indvdum@0
|
281 |
|
|
indvdum@0
|
282 |
$sql = 'SELECT *
|
|
indvdum@0
|
283 |
FROM ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
284 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
285 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
286 |
$role_row = $db->sql_fetchrow($result);
|
|
indvdum@0
|
287 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
288 |
|
|
indvdum@0
|
289 |
$sql = 'SELECT p.auth_option_id, p.auth_setting, o.auth_option
|
|
indvdum@0
|
290 |
FROM ' . ACL_ROLES_DATA_TABLE . ' p, ' . ACL_OPTIONS_TABLE . ' o
|
|
indvdum@0
|
291 |
WHERE o.auth_option_id = p.auth_option_id
|
|
indvdum@0
|
292 |
AND p.role_id = ' . $role_id . '
|
|
indvdum@0
|
293 |
ORDER BY p.auth_option_id';
|
|
indvdum@0
|
294 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
295 |
|
|
indvdum@0
|
296 |
$auth_options = array();
|
|
indvdum@0
|
297 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
298 |
{
|
|
indvdum@0
|
299 |
$auth_options[$row['auth_option']] = $row['auth_setting'];
|
|
indvdum@0
|
300 |
}
|
|
indvdum@0
|
301 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
302 |
}
|
|
indvdum@0
|
303 |
|
|
indvdum@0
|
304 |
if (!$role_row)
|
|
indvdum@0
|
305 |
{
|
|
indvdum@0
|
306 |
trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
|
|
indvdum@0
|
307 |
}
|
|
indvdum@0
|
308 |
|
|
indvdum@0
|
309 |
$template->assign_vars(array(
|
|
indvdum@0
|
310 |
'S_EDIT' => true,
|
|
indvdum@0
|
311 |
|
|
indvdum@0
|
312 |
'U_ACTION' => $this->u_action . "&action={$action}&role_id={$role_id}",
|
|
indvdum@0
|
313 |
'U_BACK' => $this->u_action,
|
|
indvdum@0
|
314 |
|
|
indvdum@0
|
315 |
'ROLE_NAME' => $role_row['role_name'],
|
|
indvdum@0
|
316 |
'ROLE_DESCRIPTION' => $role_row['role_description'],
|
|
indvdum@0
|
317 |
'L_ACL_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)],
|
|
indvdum@0
|
318 |
)
|
|
indvdum@0
|
319 |
);
|
|
indvdum@0
|
320 |
|
|
indvdum@0
|
321 |
// We need to fill the auth options array with ACL_NO options ;)
|
|
indvdum@0
|
322 |
$sql = 'SELECT auth_option_id, auth_option
|
|
indvdum@0
|
323 |
FROM ' . ACL_OPTIONS_TABLE . "
|
|
indvdum@0
|
324 |
WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char) . "
|
|
indvdum@0
|
325 |
AND auth_option <> '{$permission_type}'
|
|
indvdum@0
|
326 |
ORDER BY auth_option_id";
|
|
indvdum@0
|
327 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
328 |
|
|
indvdum@0
|
329 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
330 |
{
|
|
indvdum@0
|
331 |
if (!isset($auth_options[$row['auth_option']]))
|
|
indvdum@0
|
332 |
{
|
|
indvdum@0
|
333 |
$auth_options[$row['auth_option']] = ACL_NO;
|
|
indvdum@0
|
334 |
}
|
|
indvdum@0
|
335 |
}
|
|
indvdum@0
|
336 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
337 |
|
|
indvdum@0
|
338 |
// Unset global permission option
|
|
indvdum@0
|
339 |
unset($auth_options[$permission_type]);
|
|
indvdum@0
|
340 |
|
|
indvdum@0
|
341 |
// Display auth options
|
|
indvdum@0
|
342 |
$this->display_auth_options($auth_options);
|
|
indvdum@0
|
343 |
|
|
indvdum@0
|
344 |
// Get users/groups/forums using this preset...
|
|
indvdum@0
|
345 |
if ($action == 'edit')
|
|
indvdum@0
|
346 |
{
|
|
indvdum@0
|
347 |
$hold_ary = $auth_admin->get_role_mask($role_id);
|
|
indvdum@0
|
348 |
|
|
indvdum@0
|
349 |
if (sizeof($hold_ary))
|
|
indvdum@0
|
350 |
{
|
|
indvdum@0
|
351 |
$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
|
|
indvdum@0
|
352 |
|
|
indvdum@0
|
353 |
$template->assign_vars(array(
|
|
indvdum@0
|
354 |
'S_DISPLAY_ROLE_MASK' => true,
|
|
indvdum@0
|
355 |
'L_ROLE_ASSIGNED_TO' => sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_name))
|
|
indvdum@0
|
356 |
);
|
|
indvdum@0
|
357 |
|
|
indvdum@0
|
358 |
$auth_admin->display_role_mask($hold_ary);
|
|
indvdum@0
|
359 |
}
|
|
indvdum@0
|
360 |
}
|
|
indvdum@0
|
361 |
|
|
indvdum@0
|
362 |
return;
|
|
indvdum@0
|
363 |
break;
|
|
indvdum@0
|
364 |
|
|
indvdum@0
|
365 |
case 'move_up':
|
|
indvdum@0
|
366 |
case 'move_down':
|
|
indvdum@0
|
367 |
|
|
indvdum@0
|
368 |
$order = request_var('order', 0);
|
|
indvdum@0
|
369 |
$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
|
|
indvdum@0
|
370 |
|
|
indvdum@0
|
371 |
$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
372 |
SET role_order = ' . $order_total . " - role_order
|
|
indvdum@0
|
373 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'
|
|
indvdum@0
|
374 |
AND role_order IN ($order, " . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
|
|
indvdum@0
|
375 |
$db->sql_query($sql);
|
|
indvdum@0
|
376 |
|
|
indvdum@0
|
377 |
break;
|
|
indvdum@0
|
378 |
}
|
|
indvdum@0
|
379 |
|
|
indvdum@0
|
380 |
// By default, check that role_order is valid and fix it if necessary
|
|
indvdum@0
|
381 |
$sql = 'SELECT role_id, role_order
|
|
indvdum@0
|
382 |
FROM ' . ACL_ROLES_TABLE . "
|
|
indvdum@0
|
383 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'
|
|
indvdum@0
|
384 |
ORDER BY role_order ASC";
|
|
indvdum@0
|
385 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
386 |
|
|
indvdum@0
|
387 |
if ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
388 |
{
|
|
indvdum@0
|
389 |
$order = 0;
|
|
indvdum@0
|
390 |
do
|
|
indvdum@0
|
391 |
{
|
|
indvdum@0
|
392 |
$order++;
|
|
indvdum@0
|
393 |
if ($row['role_order'] != $order)
|
|
indvdum@0
|
394 |
{
|
|
indvdum@0
|
395 |
$db->sql_query('UPDATE ' . ACL_ROLES_TABLE . " SET role_order = $order WHERE role_id = {$row['role_id']}");
|
|
indvdum@0
|
396 |
}
|
|
indvdum@0
|
397 |
}
|
|
indvdum@0
|
398 |
while ($row = $db->sql_fetchrow($result));
|
|
indvdum@0
|
399 |
}
|
|
indvdum@0
|
400 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
401 |
|
|
indvdum@0
|
402 |
// Display assigned items?
|
|
indvdum@0
|
403 |
$display_item = request_var('display_item', 0);
|
|
indvdum@0
|
404 |
|
|
indvdum@0
|
405 |
// Select existing roles
|
|
indvdum@0
|
406 |
$sql = 'SELECT *
|
|
indvdum@0
|
407 |
FROM ' . ACL_ROLES_TABLE . "
|
|
indvdum@0
|
408 |
WHERE role_type = '" . $db->sql_escape($permission_type) . "'
|
|
indvdum@0
|
409 |
ORDER BY role_order ASC";
|
|
indvdum@0
|
410 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
411 |
|
|
indvdum@0
|
412 |
$s_role_options = '';
|
|
indvdum@0
|
413 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
414 |
{
|
|
indvdum@0
|
415 |
$role_name = (!empty($user->lang[$row['role_name']])) ? $user->lang[$row['role_name']] : $row['role_name'];
|
|
indvdum@0
|
416 |
|
|
indvdum@0
|
417 |
$template->assign_block_vars('roles', array(
|
|
indvdum@0
|
418 |
'ROLE_NAME' => $role_name,
|
|
indvdum@0
|
419 |
'ROLE_DESCRIPTION' => (!empty($user->lang[$row['role_description']])) ? $user->lang[$row['role_description']] : nl2br($row['role_description']),
|
|
indvdum@0
|
420 |
|
|
indvdum@0
|
421 |
'U_EDIT' => $this->u_action . '&action=edit&role_id=' . $row['role_id'],
|
|
indvdum@0
|
422 |
'U_REMOVE' => $this->u_action . '&action=remove&role_id=' . $row['role_id'],
|
|
indvdum@0
|
423 |
'U_MOVE_UP' => $this->u_action . '&action=move_up&order=' . $row['role_order'],
|
|
indvdum@0
|
424 |
'U_MOVE_DOWN' => $this->u_action . '&action=move_down&order=' . $row['role_order'],
|
|
indvdum@0
|
425 |
'U_DISPLAY_ITEMS' => ($row['role_id'] == $display_item) ? '' : $this->u_action . '&display_item=' . $row['role_id'] . '#assigned_to')
|
|
indvdum@0
|
426 |
);
|
|
indvdum@0
|
427 |
|
|
indvdum@0
|
428 |
$s_role_options .= '<option value="' . $row['role_id'] . '">' . $role_name . '</option>';
|
|
indvdum@0
|
429 |
|
|
indvdum@0
|
430 |
if ($display_item == $row['role_id'])
|
|
indvdum@0
|
431 |
{
|
|
indvdum@0
|
432 |
$template->assign_vars(array(
|
|
indvdum@0
|
433 |
'L_ROLE_ASSIGNED_TO' => sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_name))
|
|
indvdum@0
|
434 |
);
|
|
indvdum@0
|
435 |
}
|
|
indvdum@0
|
436 |
}
|
|
indvdum@0
|
437 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
438 |
|
|
indvdum@0
|
439 |
$template->assign_vars(array(
|
|
indvdum@0
|
440 |
'S_ROLE_OPTIONS' => $s_role_options)
|
|
indvdum@0
|
441 |
);
|
|
indvdum@0
|
442 |
|
|
indvdum@0
|
443 |
if ($display_item)
|
|
indvdum@0
|
444 |
{
|
|
indvdum@0
|
445 |
$template->assign_vars(array(
|
|
indvdum@0
|
446 |
'S_DISPLAY_ROLE_MASK' => true)
|
|
indvdum@0
|
447 |
);
|
|
indvdum@0
|
448 |
|
|
indvdum@0
|
449 |
$hold_ary = $auth_admin->get_role_mask($display_item);
|
|
indvdum@0
|
450 |
$auth_admin->display_role_mask($hold_ary);
|
|
indvdum@0
|
451 |
}
|
|
indvdum@0
|
452 |
}
|
|
indvdum@0
|
453 |
|
|
indvdum@0
|
454 |
/**
|
|
indvdum@0
|
455 |
* Display permission settings able to be set
|
|
indvdum@0
|
456 |
*/
|
|
indvdum@0
|
457 |
function display_auth_options($auth_options)
|
|
indvdum@0
|
458 |
{
|
|
indvdum@0
|
459 |
global $template, $user;
|
|
indvdum@0
|
460 |
|
|
indvdum@0
|
461 |
$content_array = $categories = array();
|
|
indvdum@0
|
462 |
$key_sort_array = array(0);
|
|
indvdum@0
|
463 |
$auth_options = array(0 => $auth_options);
|
|
indvdum@0
|
464 |
|
|
indvdum@0
|
465 |
// Making use of auth_admin method here (we do not really want to change two similar code fragments)
|
|
indvdum@0
|
466 |
auth_admin::build_permission_array($auth_options, $content_array, $categories, $key_sort_array);
|
|
indvdum@0
|
467 |
|
|
indvdum@0
|
468 |
$content_array = $content_array[0];
|
|
indvdum@0
|
469 |
|
|
indvdum@0
|
470 |
$template->assign_var('S_NUM_PERM_COLS', sizeof($categories));
|
|
indvdum@0
|
471 |
|
|
indvdum@0
|
472 |
// Assign to template
|
|
indvdum@0
|
473 |
foreach ($content_array as $cat => $cat_array)
|
|
indvdum@0
|
474 |
{
|
|
indvdum@0
|
475 |
$template->assign_block_vars('auth', array(
|
|
indvdum@0
|
476 |
'CAT_NAME' => $user->lang['permission_cat'][$cat],
|
|
indvdum@0
|
477 |
|
|
indvdum@0
|
478 |
'S_YES' => ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,
|
|
indvdum@0
|
479 |
'S_NEVER' => ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
|
|
indvdum@0
|
480 |
'S_NO' => ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false)
|
|
indvdum@0
|
481 |
);
|
|
indvdum@0
|
482 |
|
|
indvdum@0
|
483 |
foreach ($cat_array['permissions'] as $permission => $allowed)
|
|
indvdum@0
|
484 |
{
|
|
indvdum@0
|
485 |
$template->assign_block_vars('auth.mask', array(
|
|
indvdum@0
|
486 |
'S_YES' => ($allowed == ACL_YES) ? true : false,
|
|
indvdum@0
|
487 |
'S_NEVER' => ($allowed == ACL_NEVER) ? true : false,
|
|
indvdum@0
|
488 |
'S_NO' => ($allowed == ACL_NO) ? true : false,
|
|
indvdum@0
|
489 |
|
|
indvdum@0
|
490 |
'FIELD_NAME' => $permission,
|
|
indvdum@0
|
491 |
'PERMISSION' => $user->lang['acl_' . $permission]['lang'])
|
|
indvdum@0
|
492 |
);
|
|
indvdum@0
|
493 |
}
|
|
indvdum@0
|
494 |
}
|
|
indvdum@0
|
495 |
}
|
|
indvdum@0
|
496 |
|
|
indvdum@0
|
497 |
/**
|
|
indvdum@0
|
498 |
* Remove role
|
|
indvdum@0
|
499 |
*/
|
|
indvdum@0
|
500 |
function remove_role($role_id, $permission_type)
|
|
indvdum@0
|
501 |
{
|
|
indvdum@0
|
502 |
global $db;
|
|
indvdum@0
|
503 |
|
|
indvdum@0
|
504 |
$auth_admin = new auth_admin();
|
|
indvdum@0
|
505 |
|
|
indvdum@0
|
506 |
// Get complete auth array
|
|
indvdum@0
|
507 |
$sql = 'SELECT auth_option, auth_option_id
|
|
indvdum@0
|
508 |
FROM ' . ACL_OPTIONS_TABLE . "
|
|
indvdum@0
|
509 |
WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char);
|
|
indvdum@0
|
510 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
511 |
|
|
indvdum@0
|
512 |
$auth_settings = array();
|
|
indvdum@0
|
513 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
514 |
{
|
|
indvdum@0
|
515 |
$auth_settings[$row['auth_option']] = ACL_NO;
|
|
indvdum@0
|
516 |
}
|
|
indvdum@0
|
517 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
518 |
|
|
indvdum@0
|
519 |
// Get the role auth settings we need to re-set...
|
|
indvdum@0
|
520 |
$sql = 'SELECT o.auth_option, r.auth_setting
|
|
indvdum@0
|
521 |
FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
|
|
indvdum@0
|
522 |
WHERE o.auth_option_id = r.auth_option_id
|
|
indvdum@0
|
523 |
AND r.role_id = ' . $role_id;
|
|
indvdum@0
|
524 |
$result = $db->sql_query($sql);
|
|
indvdum@0
|
525 |
|
|
indvdum@0
|
526 |
while ($row = $db->sql_fetchrow($result))
|
|
indvdum@0
|
527 |
{
|
|
indvdum@0
|
528 |
$auth_settings[$row['auth_option']] = $row['auth_setting'];
|
|
indvdum@0
|
529 |
}
|
|
indvdum@0
|
530 |
$db->sql_freeresult($result);
|
|
indvdum@0
|
531 |
|
|
indvdum@0
|
532 |
// Get role assignments
|
|
indvdum@0
|
533 |
$hold_ary = $auth_admin->get_role_mask($role_id);
|
|
indvdum@0
|
534 |
|
|
indvdum@0
|
535 |
// Re-assign permissions
|
|
indvdum@0
|
536 |
foreach ($hold_ary as $forum_id => $forum_ary)
|
|
indvdum@0
|
537 |
{
|
|
indvdum@0
|
538 |
if (isset($forum_ary['users']))
|
|
indvdum@0
|
539 |
{
|
|
indvdum@0
|
540 |
$auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false);
|
|
indvdum@0
|
541 |
}
|
|
indvdum@0
|
542 |
|
|
indvdum@0
|
543 |
if (isset($forum_ary['groups']))
|
|
indvdum@0
|
544 |
{
|
|
indvdum@0
|
545 |
$auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false);
|
|
indvdum@0
|
546 |
}
|
|
indvdum@0
|
547 |
}
|
|
indvdum@0
|
548 |
|
|
indvdum@0
|
549 |
// Remove role from users and groups just to be sure (happens through acl_set)
|
|
indvdum@0
|
550 |
$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|
indvdum@0
|
551 |
WHERE auth_role_id = ' . $role_id;
|
|
indvdum@0
|
552 |
$db->sql_query($sql);
|
|
indvdum@0
|
553 |
|
|
indvdum@0
|
554 |
$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|
indvdum@0
|
555 |
WHERE auth_role_id = ' . $role_id;
|
|
indvdum@0
|
556 |
$db->sql_query($sql);
|
|
indvdum@0
|
557 |
|
|
indvdum@0
|
558 |
// Remove role data and role
|
|
indvdum@0
|
559 |
$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
|
|
indvdum@0
|
560 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
561 |
$db->sql_query($sql);
|
|
indvdum@0
|
562 |
|
|
indvdum@0
|
563 |
$sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '
|
|
indvdum@0
|
564 |
WHERE role_id = ' . $role_id;
|
|
indvdum@0
|
565 |
$db->sql_query($sql);
|
|
indvdum@0
|
566 |
|
|
indvdum@0
|
567 |
$auth_admin->acl_clear_prefetch();
|
|
indvdum@0
|
568 |
}
|
|
indvdum@0
|
569 |
}
|
|
indvdum@0
|
570 |
|
|
indvdum@0
|
571 |
?> |