5
* @version $Id: acp_permissions.php,v 1.65 2007/10/05 14:36:32 acydburn Exp $
6
* @copyright (c) 2005 phpBB Group
7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
14
if (!defined('IN_PHPBB'))
25
var $permission_dropdown;
27
function main($id, $mode)
29
global $db, $user, $auth, $template, $cache;
30
global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
32
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
33
include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
35
$auth_admin = new auth_admin();
37
$user->add_lang('acp/permissions');
38
add_permission_language();
40
$this->tpl_name = 'acp_permissions';
42
// Trace has other vars
45
$user_id = request_var('u', 0);
46
$forum_id = request_var('f', 0);
47
$permission = request_var('auth', '');
49
$this->tpl_name = 'permission_trace';
51
if ($user_id && isset($auth_admin->option_ids[$permission]) && $auth->acl_get('a_viewauth'))
53
$this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']);
54
$this->permission_trace($user_id, $forum_id, $permission);
57
trigger_error('NO_MODE', E_USER_ERROR);
61
$action = request_var('action', array('' => 0));
62
$action = key($action);
63
$action = (isset($_POST['psubmit'])) ? 'apply_permissions' : $action;
65
$all_forums = request_var('all_forums', 0);
66
$subforum_id = request_var('subforum_id', 0);
67
$forum_id = request_var('forum_id', array(0));
69
$username = request_var('username', array(''), true);
70
$usernames = request_var('usernames', '', true);
71
$user_id = request_var('user_id', array(0));
73
$group_id = request_var('group_id', array(0));
74
$select_all_groups = request_var('select_all_groups', 0);
76
$form_name = 'acp_permissions';
77
add_form_key($form_name);
79
// If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen)
80
if ($select_all_groups)
82
// Add default groups to selection
83
$sql_and = (!$config['coppa_enable']) ? " AND group_name <> 'REGISTERED_COPPA'" : '';
85
$sql = 'SELECT group_id
86
FROM ' . GROUPS_TABLE . '
87
WHERE group_type = ' . GROUP_SPECIAL . "
89
$result = $db->sql_query($sql);
91
while ($row = $db->sql_fetchrow($result))
93
$group_id[] = $row['group_id'];
95
$db->sql_freeresult($result);
98
// Map usernames to ids and vice versa
101
$username = explode("\n", $usernames);
105
if (sizeof($username) && !sizeof($user_id))
107
user_get_id_name($user_id, $username);
109
if (!sizeof($user_id))
111
trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
116
// Build forum ids (of all forums are checked or subforum listing used)
119
$sql = 'SELECT forum_id
120
FROM ' . FORUMS_TABLE . '
122
$result = $db->sql_query($sql);
125
while ($row = $db->sql_fetchrow($result))
127
$forum_id[] = $row['forum_id'];
129
$db->sql_freeresult($result);
131
else if ($subforum_id)
134
foreach (get_forum_branch($subforum_id, 'children') as $row)
136
$forum_id[] = $row['forum_id'];
140
// Define some common variables for every mode
143
$permission_scope = (strpos($mode, '_global') !== false) ? 'global' : 'local';
145
// Showing introductionary page?
146
if ($mode == 'intro')
148
$this->page_title = 'ACP_PERMISSIONS';
150
$template->assign_vars(array(
159
case 'setting_user_global':
160
case 'setting_group_global':
161
$this->permission_dropdown = array('u_', 'm_', 'a_');
162
$permission_victim = ($mode == 'setting_user_global') ? array('user') : array('group');
163
$this->page_title = ($mode == 'setting_user_global') ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS';
166
case 'setting_user_local':
167
case 'setting_group_local':
168
$this->permission_dropdown = array('f_', 'm_');
169
$permission_victim = ($mode == 'setting_user_local') ? array('user', 'forums') : array('group', 'forums');
170
$this->page_title = ($mode == 'setting_user_local') ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS';
173
case 'setting_admin_global':
174
case 'setting_mod_global':
175
$this->permission_dropdown = (strpos($mode, '_admin_') !== false) ? array('a_') : array('m_');
176
$permission_victim = array('usergroup');
177
$this->page_title = ($mode == 'setting_admin_global') ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS';
180
case 'setting_mod_local':
181
case 'setting_forum_local':
182
$this->permission_dropdown = ($mode == 'setting_mod_local') ? array('m_') : array('f_');
183
$permission_victim = array('forums', 'usergroup');
184
$this->page_title = ($mode == 'setting_mod_local') ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS';
187
case 'view_admin_global':
188
case 'view_user_global':
189
case 'view_mod_global':
190
$this->permission_dropdown = ($mode == 'view_admin_global') ? array('a_') : (($mode == 'view_user_global') ? array('u_') : array('m_'));
191
$permission_victim = array('usergroup_view');
192
$this->page_title = ($mode == 'view_admin_global') ? 'ACP_VIEW_ADMIN_PERMISSIONS' : (($mode == 'view_user_global') ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS');
195
case 'view_mod_local':
196
case 'view_forum_local':
197
$this->permission_dropdown = ($mode == 'view_mod_local') ? array('m_') : array('f_');
198
$permission_victim = array('forums', 'usergroup_view');
199
$this->page_title = ($mode == 'view_mod_local') ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS';
203
trigger_error('NO_MODE', E_USER_ERROR);
207
$template->assign_vars(array(
208
'L_TITLE' => $user->lang[$this->page_title],
209
'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])
212
// Get permission type
213
$permission_type = request_var('type', $this->permission_dropdown[0]);
215
if (!in_array($permission_type, $this->permission_dropdown))
217
trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
222
if (strpos($mode, 'setting_') === 0 && $action)
228
if (!check_form_key($form_name))
230
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
232
// All users/groups selected?
233
$all_users = (isset($_POST['all_users'])) ? true : false;
234
$all_groups = (isset($_POST['all_groups'])) ? true : false;
236
if ($all_users || $all_groups)
238
$items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
240
if ($all_users && sizeof($items['user_ids']))
242
$user_id = $items['user_ids'];
244
else if ($all_groups && sizeof($items['group_ids']))
246
$group_id = $items['group_ids'];
250
if (sizeof($user_id) || sizeof($group_id))
252
$this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id);
256
trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
260
case 'apply_permissions':
261
if (!isset($_POST['setting']))
263
trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
265
if (!check_form_key($form_name))
267
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
270
$this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
273
case 'apply_all_permissions':
274
if (!isset($_POST['setting']))
276
trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
278
if (!check_form_key($form_name))
280
trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
283
$this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
289
// Setting permissions screen
290
$s_hidden_fields = build_hidden_fields(array(
291
'user_id' => $user_id,
292
'group_id' => $group_id,
293
'forum_id' => $forum_id,
294
'type' => $permission_type)
297
// Go through the screens/options needed and present them in correct order
298
foreach ($permission_victim as $victim)
302
case 'forum_dropdown':
304
if (sizeof($forum_id))
306
$this->check_existence('forum', $forum_id);
310
$template->assign_vars(array(
311
'S_SELECT_FORUM' => true,
312
'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))
319
if (sizeof($forum_id))
321
$this->check_existence('forum', $forum_id);
325
$forum_list = make_forum_select(false, false, true, false, false, false, true);
327
// Build forum options
328
$s_forum_options = '';
329
foreach ($forum_list as $f_id => $f_row)
331
$s_forum_options .= '<option value="' . $f_id . '"' . (($f_row['selected']) ? ' selected="selected"' : '') . (($f_row['disabled']) ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>';
334
// Build subforum options
335
$s_subforum_options = $this->build_subforum_options($forum_list);
337
$template->assign_vars(array(
338
'S_SELECT_FORUM' => true,
339
'S_FORUM_OPTIONS' => $s_forum_options,
340
'S_SUBFORUM_OPTIONS' => $s_subforum_options,
341
'S_FORUM_ALL' => true,
342
'S_FORUM_MULTIPLE' => true)
349
if (sizeof($user_id))
351
$this->check_existence('user', $user_id);
355
$template->assign_vars(array(
356
'S_SELECT_USER' => true,
357
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=select_victim&field=username&select_single=true'),
364
if (sizeof($group_id))
366
$this->check_existence('group', $group_id);
370
$template->assign_vars(array(
371
'S_SELECT_GROUP' => true,
372
'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)))
378
case 'usergroup_view':
380
$all_users = (isset($_POST['all_users'])) ? true : false;
381
$all_groups = (isset($_POST['all_groups'])) ? true : false;
383
if ((sizeof($user_id) && !$all_users) || (sizeof($group_id) && !$all_groups))
385
if (sizeof($user_id))
387
$this->check_existence('user', $user_id);
390
if (sizeof($group_id))
392
$this->check_existence('group', $group_id);
398
// Now we check the users... because the "all"-selection is different here (all defined users/groups)
399
$items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
401
if ($all_users && sizeof($items['user_ids']))
403
$user_id = $items['user_ids'];
407
if ($all_groups && sizeof($items['group_ids']))
409
$group_id = $items['group_ids'];
413
$template->assign_vars(array(
414
'S_SELECT_USERGROUP' => ($victim == 'usergroup') ? true : false,
415
'S_SELECT_USERGROUP_VIEW' => ($victim == 'usergroup_view') ? true : false,
416
'S_DEFINED_USER_OPTIONS' => $items['user_ids_options'],
417
'S_DEFINED_GROUP_OPTIONS' => $items['group_ids_options'],
418
'S_ADD_GROUP_OPTIONS' => group_select_options(false, $items['group_ids'], (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
419
'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=add_user&field=username&select_single=true'),
425
// The S_ALLOW_SELECT parameter below is a measure to lower memory usage.
426
// If there are more than 5 forums selected the admin is not able to select all users/groups too.
427
// We need to see if the number of forums can be increased or need to be decreased.
429
$template->assign_vars(array(
430
'U_ACTION' => $this->u_action,
431
'ANONYMOUS_USER_ID' => ANONYMOUS,
433
'S_SELECT_VICTIM' => true,
434
'S_ALLOW_ALL_SELECT' => (sizeof($forum_id) > 5) ? false : true,
435
'S_CAN_SELECT_USER' => ($auth->acl_get('a_authusers')) ? true : false,
436
'S_CAN_SELECT_GROUP' => ($auth->acl_get('a_authgroups')) ? true : false,
437
'S_HIDDEN_FIELDS' => $s_hidden_fields)
440
// Let the forum names being displayed
441
if (sizeof($forum_id))
443
$sql = 'SELECT forum_name
444
FROM ' . FORUMS_TABLE . '
445
WHERE ' . $db->sql_in_set('forum_id', $forum_id) . '
446
ORDER BY left_id ASC';
447
$result = $db->sql_query($sql);
449
$forum_names = array();
450
while ($row = $db->sql_fetchrow($result))
452
$forum_names[] = $row['forum_name'];
454
$db->sql_freeresult($result);
456
$template->assign_vars(array(
457
'S_FORUM_NAMES' => (sizeof($forum_names)) ? true : false,
458
'FORUM_NAMES' => implode(', ', $forum_names))
465
// Do not allow forum_ids being set and no other setting defined (will bog down the server too much)
466
if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id))
468
trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action), E_USER_WARNING);
471
$template->assign_vars(array(
472
'S_PERMISSION_DROPDOWN' => (sizeof($this->permission_dropdown) > 1) ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false,
473
'L_PERMISSION_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)],
475
'U_ACTION' => $this->u_action,
476
'S_HIDDEN_FIELDS' => $s_hidden_fields)
479
if (strpos($mode, 'setting_') === 0)
481
$template->assign_vars(array(
482
'S_SETTING_PERMISSIONS' => true)
485
$hold_ary = $auth_admin->get_mask('set', (sizeof($user_id)) ? $user_id : false, (sizeof($group_id)) ? $group_id : false, (sizeof($forum_id)) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO);
486
$auth_admin->display_mask('set', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
490
$template->assign_vars(array(
491
'S_VIEWING_PERMISSIONS' => true)
494
$hold_ary = $auth_admin->get_mask('view', (sizeof($user_id)) ? $user_id : false, (sizeof($group_id)) ? $group_id : false, (sizeof($forum_id)) ? $forum_id : false, $permission_type, $permission_scope, ACL_NEVER);
495
$auth_admin->display_mask('view', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
500
* Build +subforum options
502
function build_subforum_options($forum_list)
508
$forum_list = array_merge($forum_list);
510
foreach ($forum_list as $key => $row)
512
if ($row['disabled'])
517
$s_options .= '<option value="' . $row['forum_id'] . '"' . (($row['selected']) ? ' selected="selected"' : '') . '>' . $row['padding'] . $row['forum_name'];
519
// We check if a branch is there...
520
$branch_there = false;
522
foreach (array_slice($forum_list, $key + 1) as $temp_row)
524
if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id'])
526
$branch_there = true;
534
$s_options .= ' [' . $user->lang['PLUS_SUBFORUMS'] . ']';
537
$s_options .= '</option>';
544
* Build dropdown field for changing permission types
546
function build_permission_dropdown($options, $default_option, $permission_scope)
550
$s_dropdown_options = '';
551
foreach ($options as $setting)
553
if (!$auth->acl_get('a_' . str_replace('_', '', $setting) . 'auth'))
558
$selected = ($setting == $default_option) ? ' selected="selected"' : '';
559
$l_setting = (isset($user->lang['permission_type'][$permission_scope][$setting])) ? $user->lang['permission_type'][$permission_scope][$setting] : $user->lang['permission_type'][$setting];
560
$s_dropdown_options .= '<option value="' . $setting . '"' . $selected . '>' . $l_setting . '</option>';
563
return $s_dropdown_options;
567
* Check if selected items exist. Remove not found ids and if empty return error.
569
function check_existence($mode, &$ids)
576
$table = USERS_TABLE;
581
$table = GROUPS_TABLE;
582
$sql_id = 'group_id';
586
$table = FORUMS_TABLE;
587
$sql_id = 'forum_id';
593
$sql = "SELECT $sql_id
595
WHERE " . $db->sql_in_set($sql_id, $ids);
596
$result = $db->sql_query($sql);
599
while ($row = $db->sql_fetchrow($result))
601
$ids[] = $row[$sql_id];
603
$db->sql_freeresult($result);
608
trigger_error($user->lang['SELECTED_' . strtoupper($mode) . '_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
615
function set_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
619
$psubmit = request_var('psubmit', array(0 => array(0 => 0)));
621
// User or group to be set?
622
$ug_type = (sizeof($user_id)) ? 'user' : 'group';
624
// Check the permission setting again
625
if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
627
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
630
$ug_id = $forum_id = 0;
632
// We loop through the auth settings defined in our submit
633
list($ug_id, ) = each($psubmit);
634
list($forum_id, ) = each($psubmit[$ug_id]);
636
if (empty($_POST['setting']) || empty($_POST['setting'][$ug_id]) || empty($_POST['setting'][$ug_id][$forum_id]) || !is_array($_POST['setting'][$ug_id][$forum_id]))
638
trigger_error('WRONG_PERMISSION_SETTING_FORMAT', E_USER_WARNING);
641
// We obtain and check $_POST['setting'][$ug_id][$forum_id] directly and not using request_var() because request_var()
642
// currently does not support the amount of dimensions required. ;)
643
// $auth_settings = request_var('setting', array(0 => array(0 => array('' => 0))));
644
$auth_settings = array_map('intval', $_POST['setting'][$ug_id][$forum_id]);
646
// Do we have a role we want to set?
647
$assigned_role = (isset($_POST['role'][$ug_id][$forum_id])) ? (int) $_POST['role'][$ug_id][$forum_id] : 0;
649
// Do the admin want to set these permissions to other items too?
650
$inherit = request_var('inherit', array(0 => array(0)));
652
$ug_id = array($ug_id);
653
$forum_id = array($forum_id);
655
if (sizeof($inherit))
657
foreach ($inherit as $_ug_id => $forum_id_ary)
659
// Inherit users/groups?
660
if (!in_array($_ug_id, $ug_id))
666
$forum_id = array_merge($forum_id, array_keys($forum_id_ary));
670
$forum_id = array_unique($forum_id);
672
// If the auth settings differ from the assigned role, then do not set a role...
675
if (!$this->check_assigned_role($assigned_role, $auth_settings))
681
// Update the permission set...
682
$auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_settings, $assigned_role);
684
// Do we need to recache the moderator lists?
685
if ($permission_type == 'm_')
690
// Remove users who are now moderators or admins from everyones foes list
691
if ($permission_type == 'm_' || $permission_type == 'a_')
693
update_foes($group_id, $user_id);
696
$this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id);
698
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
702
* Apply all permissions
704
function set_all_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
708
// User or group to be set?
709
$ug_type = (sizeof($user_id)) ? 'user' : 'group';
711
// Check the permission setting again
712
if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
714
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
717
$auth_settings = (isset($_POST['setting'])) ? $_POST['setting'] : array();
718
$auth_roles = (isset($_POST['role'])) ? $_POST['role'] : array();
719
$ug_ids = $forum_ids = array();
721
// We need to go through the auth settings
722
foreach ($auth_settings as $ug_id => $forum_auth_row)
724
$ug_id = (int) $ug_id;
727
foreach ($forum_auth_row as $forum_id => $auth_options)
729
$forum_id = (int) $forum_id;
730
$forum_ids[] = $forum_id;
733
$assigned_role = (isset($auth_roles[$ug_id][$forum_id])) ? (int) $auth_roles[$ug_id][$forum_id] : 0;
735
// If the auth settings differ from the assigned role, then do not set a role...
738
if (!$this->check_assigned_role($assigned_role, $auth_options))
744
// Update the permission set...
745
$auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_options, $assigned_role, false);
749
$auth_admin->acl_clear_prefetch();
751
// Do we need to recache the moderator lists?
752
if ($permission_type == 'm_')
757
// Remove users who are now moderators or admins from everyones foes list
758
if ($permission_type == 'm_' || $permission_type == 'a_')
760
update_foes($group_id, $user_id);
763
$this->log_action($mode, 'add', $permission_type, $ug_type, $ug_ids, $forum_ids);
765
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
769
* Compare auth settings with auth settings from role
770
* returns false if they differ, true if they are equal
772
function check_assigned_role($role_id, &$auth_settings)
776
$sql = 'SELECT o.auth_option, r.auth_setting
777
FROM ' . ACL_OPTIONS_TABLE . ' o, ' . ACL_ROLES_DATA_TABLE . ' r
778
WHERE o.auth_option_id = r.auth_option_id
779
AND r.role_id = ' . $role_id;
780
$result = $db->sql_query($sql);
782
$test_auth_settings = array();
783
while ($row = $db->sql_fetchrow($result))
785
$test_auth_settings[$row['auth_option']] = $row['auth_setting'];
787
$db->sql_freeresult($result);
789
// We need to add any ACL_NO setting from auth_settings to compare correctly
790
foreach ($auth_settings as $option => $setting)
792
if ($setting == ACL_NO)
794
$test_auth_settings[$option] = $setting;
798
if (sizeof(array_diff_assoc($auth_settings, $test_auth_settings)))
809
function remove_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id, &$forum_id)
811
global $user, $db, $auth;
813
// User or group to be set?
814
$ug_type = (sizeof($user_id)) ? 'user' : 'group';
816
// Check the permission setting again
817
if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
819
trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
822
$auth_admin->acl_delete($ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : false), $permission_type);
824
// Do we need to recache the moderator lists?
825
if ($permission_type == 'm_')
830
$this->log_action($mode, 'del', $permission_type, $ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : array(0 => 0)));
832
trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
836
* Log permission changes
838
function log_action($mode, $action, $permission_type, $ug_type, $ug_id, $forum_id)
842
if (!is_array($ug_id))
844
$ug_id = array($ug_id);
847
if (!is_array($forum_id))
849
$forum_id = array($forum_id);
852
// Logging ... first grab user or groupnames ...
853
$sql = ($ug_type == 'group') ? 'SELECT group_name as name, group_type FROM ' . GROUPS_TABLE . ' WHERE ' : 'SELECT username as name FROM ' . USERS_TABLE . ' WHERE ';
854
$sql .= $db->sql_in_set(($ug_type == 'group') ? 'group_id' : 'user_id', array_map('intval', $ug_id));
855
$result = $db->sql_query($sql);
858
while ($row = $db->sql_fetchrow($result))
860
$l_ug_list .= (($l_ug_list != '') ? ', ' : '') . ((isset($row['group_type']) && $row['group_type'] == GROUP_SPECIAL) ? '<span class="sep">' . $user->lang['G_' . $row['name']] . '</span>' : $row['name']);
862
$db->sql_freeresult($result);
864
$mode = str_replace('setting_', '', $mode);
866
if ($forum_id[0] == 0)
868
add_log('admin', 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), $l_ug_list);
872
// Grab the forum details if non-zero forum_id
873
$sql = 'SELECT forum_name
874
FROM ' . FORUMS_TABLE . '
875
WHERE ' . $db->sql_in_set('forum_id', $forum_id);
876
$result = $db->sql_query($sql);
879
while ($row = $db->sql_fetchrow($result))
881
$l_forum_list .= (($l_forum_list != '') ? ', ' : '') . $row['forum_name'];
883
$db->sql_freeresult($result);
885
add_log('admin', 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), $l_forum_list, $l_ug_list);
890
* Display a complete trace tree for the selected permission to determine where settings are set/unset
892
function permission_trace($user_id, $forum_id, $permission)
894
global $db, $template, $user, $auth;
896
if ($user_id != $user->data['user_id'])
898
$sql = 'SELECT user_id, username, user_permissions, user_type
899
FROM ' . USERS_TABLE . '
900
WHERE user_id = ' . $user_id;
901
$result = $db->sql_query($sql);
902
$userdata = $db->sql_fetchrow($result);
903
$db->sql_freeresult($result);
907
$userdata = $user->data;
912
trigger_error('NO_USERS', E_USER_ERROR);
919
$sql = 'SELECT forum_name
920
FROM ' . FORUMS_TABLE . "
921
WHERE forum_id = $forum_id";
922
$result = $db->sql_query($sql, 3600);
923
$forum_name = $db->sql_fetchfield('forum_name');
924
$db->sql_freeresult($result);
927
$back = request_var('back', 0);
929
$template->assign_vars(array(
930
'PERMISSION' => $user->lang['acl_' . $permission]['lang'],
931
'PERMISSION_USERNAME' => $userdata['username'],
932
'FORUM_NAME' => $forum_name,
934
'S_GLOBAL_TRACE' => ($forum_id) ? false : true,
936
'U_BACK' => ($back) ? build_url(array('f', 'back')) . "&f=$back" : '')
939
$template->assign_block_vars('trace', array(
940
'WHO' => $user->lang['DEFAULT'],
941
'INFORMATION' => $user->lang['TRACE_DEFAULT'],
943
'S_SETTING_NO' => true,
944
'S_TOTAL_NO' => true)
947
$sql = 'SELECT DISTINCT g.group_name, g.group_id, g.group_type
948
FROM ' . GROUPS_TABLE . ' g
949
LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.group_id = g.group_id)
950
WHERE ug.user_id = ' . $user_id . '
951
AND ug.user_pending = 0
952
ORDER BY g.group_type DESC, g.group_id DESC';
953
$result = $db->sql_query($sql);
956
while ($row = $db->sql_fetchrow($result))
958
$groups[$row['group_id']] = array(
959
'auth_setting' => ACL_NO,
960
'group_name' => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']
963
$db->sql_freeresult($result);
966
$add_key = (($forum_id) ? '_LOCAL' : '');
970
// Get group auth settings
971
$hold_ary = $auth->acl_group_raw_data(array_keys($groups), $permission, $forum_id);
973
foreach ($hold_ary as $group_id => $forum_ary)
975
$groups[$group_id]['auth_setting'] = $hold_ary[$group_id][$forum_id][$permission];
979
foreach ($groups as $id => $row)
981
switch ($row['auth_setting'])
984
$information = $user->lang['TRACE_GROUP_NO' . $add_key];
988
$information = ($total == ACL_YES) ? $user->lang['TRACE_GROUP_YES_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_GROUP_YES_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_GROUP_YES_TOTAL_NO' . $add_key]);
989
$total = ($total == ACL_NO) ? ACL_YES : $total;
993
$information = ($total == ACL_YES) ? $user->lang['TRACE_GROUP_NEVER_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_GROUP_NEVER_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_GROUP_NEVER_TOTAL_NO' . $add_key]);
998
$template->assign_block_vars('trace', array(
999
'WHO' => $row['group_name'],
1000
'INFORMATION' => $information,
1002
'S_SETTING_NO' => ($row['auth_setting'] == ACL_NO) ? true : false,
1003
'S_SETTING_YES' => ($row['auth_setting'] == ACL_YES) ? true : false,
1004
'S_SETTING_NEVER' => ($row['auth_setting'] == ACL_NEVER) ? true : false,
1005
'S_TOTAL_NO' => ($total == ACL_NO) ? true : false,
1006
'S_TOTAL_YES' => ($total == ACL_YES) ? true : false,
1007
'S_TOTAL_NEVER' => ($total == ACL_NEVER) ? true : false)
1012
// Get user specific permission... globally or for this forum
1013
$hold_ary = $auth->acl_user_raw_data($user_id, $permission, $forum_id);
1014
$auth_setting = (!sizeof($hold_ary)) ? ACL_NO : $hold_ary[$user_id][$forum_id][$permission];
1016
switch ($auth_setting)
1019
$information = ($total == ACL_NO) ? $user->lang['TRACE_USER_NO_TOTAL_NO' . $add_key] : $user->lang['TRACE_USER_KEPT' . $add_key];
1020
$total = ($total == ACL_NO) ? ACL_NEVER : $total;
1024
$information = ($total == ACL_YES) ? $user->lang['TRACE_USER_YES_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_USER_YES_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_USER_YES_TOTAL_NO' . $add_key]);
1025
$total = ($total == ACL_NO) ? ACL_YES : $total;
1029
$information = ($total == ACL_YES) ? $user->lang['TRACE_USER_NEVER_TOTAL_YES' . $add_key] : (($total == ACL_NEVER) ? $user->lang['TRACE_USER_NEVER_TOTAL_NEVER' . $add_key] : $user->lang['TRACE_USER_NEVER_TOTAL_NO' . $add_key]);
1034
$template->assign_block_vars('trace', array(
1035
'WHO' => $userdata['username'],
1036
'INFORMATION' => $information,
1038
'S_SETTING_NO' => ($auth_setting == ACL_NO) ? true : false,
1039
'S_SETTING_YES' => ($auth_setting == ACL_YES) ? true : false,
1040
'S_SETTING_NEVER' => ($auth_setting == ACL_NEVER) ? true : false,
1041
'S_TOTAL_NO' => false,
1042
'S_TOTAL_YES' => ($total == ACL_YES) ? true : false,
1043
'S_TOTAL_NEVER' => ($total == ACL_NEVER) ? true : false)
1046
if ($forum_id != 0 && isset($auth->acl_options['global'][$permission]))
1048
if ($user_id != $user->data['user_id'])
1050
$auth2 = new auth();
1051
$auth2->acl($userdata);
1052
$auth_setting = $auth2->acl_get($permission);
1056
$auth_setting = $auth->acl_get($permission);
1061
$information = ($total == ACL_YES) ? $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_YES'] : $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_NEVER'];
1066
$information = $user->lang['TRACE_USER_GLOBAL_NEVER_TOTAL_KEPT'];
1069
// If there is no auth information we do not need to worry the user by showing non-relevant data.
1072
$template->assign_block_vars('trace', array(
1073
'WHO' => sprintf($user->lang['TRACE_GLOBAL_SETTING'], $userdata['username']),
1074
'INFORMATION' => sprintf($information, '<a href="' . $this->u_action . "&u=$user_id&f=0&auth=$permission&back=$forum_id\">", '</a>'),
1076
'S_SETTING_NO' => false,
1077
'S_SETTING_YES' => $auth_setting,
1078
'S_SETTING_NEVER' => !$auth_setting,
1079
'S_TOTAL_NO' => false,
1080
'S_TOTAL_YES' => ($total == ACL_YES) ? true : false,
1081
'S_TOTAL_NEVER' => ($total == ACL_NEVER) ? true : false)
1086
// Take founder status into account, overwriting the default values
1087
if ($userdata['user_type'] == USER_FOUNDER && strpos($permission, 'a_') === 0)
1089
$template->assign_block_vars('trace', array(
1090
'WHO' => $userdata['username'],
1091
'INFORMATION' => $user->lang['TRACE_USER_FOUNDER'],
1093
'S_SETTING_NO' => ($auth_setting == ACL_NO) ? true : false,
1094
'S_SETTING_YES' => ($auth_setting == ACL_YES) ? true : false,
1095
'S_SETTING_NEVER' => ($auth_setting == ACL_NEVER) ? true : false,
1096
'S_TOTAL_NO' => false,
1097
'S_TOTAL_YES' => true,
1098
'S_TOTAL_NEVER' => false)
1105
$template->assign_vars(array(
1106
'S_RESULT_NO' => ($total == ACL_NO) ? true : false,
1107
'S_RESULT_YES' => ($total == ACL_YES) ? true : false,
1108
'S_RESULT_NEVER' => ($total == ACL_NEVER) ? true : false,
1113
* Get already assigned users/groups
1115
function retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type)
1119
$sql_forum_id = ($permission_scope == 'global') ? 'AND a.forum_id = 0' : ((sizeof($forum_id)) ? 'AND ' . $db->sql_in_set('a.forum_id', $forum_id) : 'AND a.forum_id <> 0');
1120
$sql_permission_option = ' AND o.auth_option ' . $db->sql_like_expression($permission_type . $db->any_char);
1122
$sql = $db->sql_build_query('SELECT_DISTINCT', array(
1123
'SELECT' => 'u.username, u.username_clean, u.user_regdate, u.user_id',
1127
ACL_OPTIONS_TABLE => 'o',
1128
ACL_USERS_TABLE => 'a'
1131
'LEFT_JOIN' => array(
1133
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
1134
'ON' => 'a.auth_role_id = r.role_id'
1138
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
1139
$sql_permission_option
1141
AND u.user_id = a.user_id",
1143
'ORDER_BY' => 'u.username_clean, u.user_regdate ASC'
1145
$result = $db->sql_query($sql);
1147
$s_defined_user_options = '';
1148
$defined_user_ids = array();
1149
while ($row = $db->sql_fetchrow($result))
1151
$s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>';
1152
$defined_user_ids[] = $row['user_id'];
1154
$db->sql_freeresult($result);
1156
$sql = $db->sql_build_query('SELECT_DISTINCT', array(
1157
'SELECT' => 'g.group_type, g.group_name, g.group_id',
1160
GROUPS_TABLE => 'g',
1161
ACL_OPTIONS_TABLE => 'o',
1162
ACL_GROUPS_TABLE => 'a'
1165
'LEFT_JOIN' => array(
1167
'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
1168
'ON' => 'a.auth_role_id = r.role_id'
1172
'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
1173
$sql_permission_option
1175
AND g.group_id = a.group_id",
1177
'ORDER_BY' => 'g.group_type DESC, g.group_name ASC'
1179
$result = $db->sql_query($sql);
1181
$s_defined_group_options = '';
1182
$defined_group_ids = array();
1183
while ($row = $db->sql_fetchrow($result))
1185
$s_defined_group_options .= '<option' . (($row['group_type'] == GROUP_SPECIAL) ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>';
1186
$defined_group_ids[] = $row['group_id'];
1188
$db->sql_freeresult($result);
1191
'group_ids' => $defined_group_ids,
1192
'group_ids_options' => $s_defined_group_options,
1193
'user_ids' => $defined_user_ids,
1194
'user_ids_options' => $s_defined_user_options
b'\\ No newline at end of file'