Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
acp_permissions.php
0001 <?php
0002 /**
0003 *
0004 * @package acp
0005 * @version $Id$
0006 * @copyright (c) 2005 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 /**
0012 * @ignore
0013 */
0014 if (!defined('IN_PHPBB'))
0015 {
0016 exit;
0017 }
0018
0019 /**
0020 * @package acp
0021 */
0022 class acp_permissions
0023 {
0024 var $u_action;
0025 var $permission_dropdown;
0026
0027 function main($id, $mode)
0028 {
0029 global $db, $user, $auth, $template, $cache;
0030 global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
0031
0032 include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
0033 include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
0034
0035 $auth_admin = new auth_admin();
0036
0037 $user->add_lang('acp/permissions');
0038 add_permission_language();
0039
0040 $this->tpl_name = 'acp_permissions';
0041
0042 // Trace has other vars
0043 if ($mode == 'trace')
0044 {
0045 $user_id = request_var('u', 0);
0046 $forum_id = request_var('f', 0);
0047 $permission = request_var('auth', '');
0048
0049 $this->tpl_name = 'permission_trace';
0050
0051 if ($user_id && isset($auth_admin->option_ids[$permission]) && $auth->acl_get('a_viewauth'))
0052 {
0053 $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']);
0054 $this->permission_trace($user_id, $forum_id, $permission);
0055 return;
0056 }
0057 trigger_error('NO_MODE', E_USER_ERROR);
0058 }
0059
0060 // Set some vars
0061 $action = request_var('action', array('' => 0));
0062 $action = key($action);
0063 $action = (isset($_POST['psubmit'])) ? 'apply_permissions' : $action;
0064
0065 $all_forums = request_var('all_forums', 0);
0066 $subforum_id = request_var('subforum_id', 0);
0067 $forum_id = request_var('forum_id', array(0));
0068
0069 $username = request_var('username', array(''), true);
0070 $usernames = request_var('usernames', '', true);
0071 $user_id = request_var('user_id', array(0));
0072
0073 $group_id = request_var('group_id', array(0));
0074 $select_all_groups = request_var('select_all_groups', 0);
0075
0076 $form_name = 'acp_permissions';
0077 add_form_key($form_name);
0078
0079 // 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)
0080 if ($select_all_groups)
0081 {
0082 // Add default groups to selection
0083 $sql_and = (!$config['coppa_enable']) ? " AND group_name <> 'REGISTERED_COPPA'" : '';
0084
0085 $sql = 'SELECT group_id
0086 FROM ' . GROUPS_TABLE . '
0087 WHERE group_type = ' . GROUP_SPECIAL . "
0088 $sql_and";
0089 $result = $db->sql_query($sql);
0090
0091 while ($row = $db->sql_fetchrow($result))
0092 {
0093 $group_id[] = $row['group_id'];
0094 }
0095 $db->sql_freeresult($result);
0096 }
0097
0098 // Map usernames to ids and vice versa
0099 if ($usernames)
0100 {
0101 $username = explode("\n", $usernames);
0102 }
0103 unset($usernames);
0104
0105 if (sizeof($username) && !sizeof($user_id))
0106 {
0107 user_get_id_name($user_id, $username);
0108
0109 if (!sizeof($user_id))
0110 {
0111 trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
0112 }
0113 }
0114 unset($username);
0115
0116 // Build forum ids (of all forums are checked or subforum listing used)
0117 if ($all_forums)
0118 {
0119 $sql = 'SELECT forum_id
0120 FROM ' . FORUMS_TABLE . '
0121 ORDER BY left_id';
0122 $result = $db->sql_query($sql);
0123
0124 $forum_id = array();
0125 while ($row = $db->sql_fetchrow($result))
0126 {
0127 $forum_id[] = $row['forum_id'];
0128 }
0129 $db->sql_freeresult($result);
0130 }
0131 else if ($subforum_id)
0132 {
0133 $forum_id = array();
0134 foreach (get_forum_branch($subforum_id, 'children') as $row)
0135 {
0136 $forum_id[] = $row['forum_id'];
0137 }
0138 }
0139
0140 // Define some common variables for every mode
0141 $error = array();
0142
0143 $permission_scope = (strpos($mode, '_global') !== false) ? 'global' : 'local';
0144
0145 // Showing introductionary page?
0146 if ($mode == 'intro')
0147 {
0148 $this->page_title = 'ACP_PERMISSIONS';
0149
0150 $template->assign_vars(array(
0151 'S_INTRO' => true)
0152 );
0153
0154 return;
0155 }
0156
0157 switch ($mode)
0158 {
0159 case 'setting_user_global':
0160 case 'setting_group_global':
0161 $this->permission_dropdown = array('u_', 'm_', 'a_');
0162 $permission_victim = ($mode == 'setting_user_global') ? array('user') : array('group');
0163 $this->page_title = ($mode == 'setting_user_global') ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS';
0164 break;
0165
0166 case 'setting_user_local':
0167 case 'setting_group_local':
0168 $this->permission_dropdown = array('f_', 'm_');
0169 $permission_victim = ($mode == 'setting_user_local') ? array('user', 'forums') : array('group', 'forums');
0170 $this->page_title = ($mode == 'setting_user_local') ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS';
0171 break;
0172
0173 case 'setting_admin_global':
0174 case 'setting_mod_global':
0175 $this->permission_dropdown = (strpos($mode, '_admin_') !== false) ? array('a_') : array('m_');
0176 $permission_victim = array('usergroup');
0177 $this->page_title = ($mode == 'setting_admin_global') ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS';
0178 break;
0179
0180 case 'setting_mod_local':
0181 case 'setting_forum_local':
0182 $this->permission_dropdown = ($mode == 'setting_mod_local') ? array('m_') : array('f_');
0183 $permission_victim = array('forums', 'usergroup');
0184 $this->page_title = ($mode == 'setting_mod_local') ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS';
0185 break;
0186
0187 case 'view_admin_global':
0188 case 'view_user_global':
0189 case 'view_mod_global':
0190 $this->permission_dropdown = ($mode == 'view_admin_global') ? array('a_') : (($mode == 'view_user_global') ? array('u_') : array('m_'));
0191 $permission_victim = array('usergroup_view');
0192 $this->page_title = ($mode == 'view_admin_global') ? 'ACP_VIEW_ADMIN_PERMISSIONS' : (($mode == 'view_user_global') ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS');
0193 break;
0194
0195 case 'view_mod_local':
0196 case 'view_forum_local':
0197 $this->permission_dropdown = ($mode == 'view_mod_local') ? array('m_') : array('f_');
0198 $permission_victim = array('forums', 'usergroup_view');
0199 $this->page_title = ($mode == 'view_mod_local') ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS';
0200 break;
0201
0202 default:
0203 trigger_error('NO_MODE', E_USER_ERROR);
0204 break;
0205 }
0206
0207 $template->assign_vars(array(
0208 'L_TITLE' => $user->lang[$this->page_title],
0209 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])
0210 );
0211
0212 // Get permission type
0213 $permission_type = request_var('type', $this->permission_dropdown[0]);
0214
0215 if (!in_array($permission_type, $this->permission_dropdown))
0216 {
0217 trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING);
0218 }
0219
0220
0221 // Handle actions
0222 if (strpos($mode, 'setting_') === 0 && $action)
0223 {
0224 switch ($action)
0225 {
0226 case 'delete':
0227
0228 if (!check_form_key($form_name))
0229 {
0230 trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0231 }
0232 // All users/groups selected?
0233 $all_users = (isset($_POST['all_users'])) ? true : false;
0234 $all_groups = (isset($_POST['all_groups'])) ? true : false;
0235
0236 if ($all_users || $all_groups)
0237 {
0238 $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
0239
0240 if ($all_users && sizeof($items['user_ids']))
0241 {
0242 $user_id = $items['user_ids'];
0243 }
0244 else if ($all_groups && sizeof($items['group_ids']))
0245 {
0246 $group_id = $items['group_ids'];
0247 }
0248 }
0249
0250 if (sizeof($user_id) || sizeof($group_id))
0251 {
0252 $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id);
0253 }
0254 else
0255 {
0256 trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
0257 }
0258 break;
0259
0260 case 'apply_permissions':
0261 if (!isset($_POST['setting']))
0262 {
0263 trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
0264 }
0265 if (!check_form_key($form_name))
0266 {
0267 trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0268 }
0269
0270 $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
0271 break;
0272
0273 case 'apply_all_permissions':
0274 if (!isset($_POST['setting']))
0275 {
0276 trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING);
0277 }
0278 if (!check_form_key($form_name))
0279 {
0280 trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
0281 }
0282
0283 $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id);
0284 break;
0285 }
0286 }
0287
0288
0289 // Setting permissions screen
0290 $s_hidden_fields = build_hidden_fields(array(
0291 'user_id' => $user_id,
0292 'group_id' => $group_id,
0293 'forum_id' => $forum_id,
0294 'type' => $permission_type)
0295 );
0296
0297 // Go through the screens/options needed and present them in correct order
0298 foreach ($permission_victim as $victim)
0299 {
0300 switch ($victim)
0301 {
0302 case 'forum_dropdown':
0303
0304 if (sizeof($forum_id))
0305 {
0306 $this->check_existence('forum', $forum_id);
0307 continue 2;
0308 }
0309
0310 $template->assign_vars(array(
0311 'S_SELECT_FORUM' => true,
0312 'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))
0313 );
0314
0315 break;
0316
0317 case 'forums':
0318
0319 if (sizeof($forum_id))
0320 {
0321 $this->check_existence('forum', $forum_id);
0322 continue 2;
0323 }
0324
0325 $forum_list = make_forum_select(false, false, true, false, false, false, true);
0326
0327 // Build forum options
0328 $s_forum_options = '';
0329 foreach ($forum_list as $f_id => $f_row)
0330 {
0331 $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>';
0332 }
0333
0334 // Build subforum options
0335 $s_subforum_options = $this->build_subforum_options($forum_list);
0336
0337 $template->assign_vars(array(
0338 'S_SELECT_FORUM' => true,
0339 'S_FORUM_OPTIONS' => $s_forum_options,
0340 'S_SUBFORUM_OPTIONS' => $s_subforum_options,
0341 'S_FORUM_ALL' => true,
0342 'S_FORUM_MULTIPLE' => true)
0343 );
0344
0345 break;
0346
0347 case 'user':
0348
0349 if (sizeof($user_id))
0350 {
0351 $this->check_existence('user', $user_id);
0352 continue 2;
0353 }
0354
0355 $template->assign_vars(array(
0356 'S_SELECT_USER' => true,
0357 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=select_victim&field=username&select_single=true'),
0358 ));
0359
0360 break;
0361
0362 case 'group':
0363
0364 if (sizeof($group_id))
0365 {
0366 $this->check_existence('group', $group_id);
0367 continue 2;
0368 }
0369
0370 $template->assign_vars(array(
0371 'S_SELECT_GROUP' => true,
0372 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)))
0373 );
0374
0375 break;
0376
0377 case 'usergroup':
0378 case 'usergroup_view':
0379
0380 $all_users = (isset($_POST['all_users'])) ? true : false;
0381 $all_groups = (isset($_POST['all_groups'])) ? true : false;
0382
0383 if ((sizeof($user_id) && !$all_users) || (sizeof($group_id) && !$all_groups))
0384 {
0385 if (sizeof($user_id))
0386 {
0387 $this->check_existence('user', $user_id);
0388 }
0389
0390 if (sizeof($group_id))
0391 {
0392 $this->check_existence('group', $group_id);
0393 }
0394
0395 continue 2;
0396 }
0397
0398 // Now we check the users... because the "all"-selection is different here (all defined users/groups)
0399 $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type);
0400
0401 if ($all_users && sizeof($items['user_ids']))
0402 {
0403 $user_id = $items['user_ids'];
0404 continue 2;
0405 }
0406
0407 if ($all_groups && sizeof($items['group_ids']))
0408 {
0409 $group_id = $items['group_ids'];
0410 continue 2;
0411 }
0412
0413 $template->assign_vars(array(
0414 'S_SELECT_USERGROUP' => ($victim == 'usergroup') ? true : false,
0415 'S_SELECT_USERGROUP_VIEW' => ($victim == 'usergroup_view') ? true : false,
0416 'S_DEFINED_USER_OPTIONS' => $items['user_ids_options'],
0417 'S_DEFINED_GROUP_OPTIONS' => $items['group_ids_options'],
0418 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $items['group_ids'], (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
0419 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=add_user&field=username&select_single=true'),
0420 ));
0421
0422 break;
0423 }
0424
0425 // The S_ALLOW_SELECT parameter below is a measure to lower memory usage.
0426 // If there are more than 5 forums selected the admin is not able to select all users/groups too.
0427 // We need to see if the number of forums can be increased or need to be decreased.
0428
0429 $template->assign_vars(array(
0430 'U_ACTION' => $this->u_action,
0431 'ANONYMOUS_USER_ID' => ANONYMOUS,
0432
0433 'S_SELECT_VICTIM' => true,
0434 'S_ALLOW_ALL_SELECT' => (sizeof($forum_id) > 5) ? false : true,
0435 'S_CAN_SELECT_USER' => ($auth->acl_get('a_authusers')) ? true : false,
0436 'S_CAN_SELECT_GROUP' => ($auth->acl_get('a_authgroups')) ? true : false,
0437 'S_HIDDEN_FIELDS' => $s_hidden_fields)
0438 );
0439
0440 // Let the forum names being displayed
0441 if (sizeof($forum_id))
0442 {
0443 $sql = 'SELECT forum_name
0444 FROM ' . FORUMS_TABLE . '
0445 WHERE ' . $db->sql_in_set('forum_id', $forum_id) . '
0446 ORDER BY left_id ASC';
0447 $result = $db->sql_query($sql);
0448
0449 $forum_names = array();
0450 while ($row = $db->sql_fetchrow($result))
0451 {
0452 $forum_names[] = $row['forum_name'];
0453 }
0454 $db->sql_freeresult($result);
0455
0456 $template->assign_vars(array(
0457 'S_FORUM_NAMES' => (sizeof($forum_names)) ? true : false,
0458 'FORUM_NAMES' => implode(', ', $forum_names))
0459 );
0460 }
0461
0462 return;
0463 }
0464
0465 // Do not allow forum_ids being set and no other setting defined (will bog down the server too much)
0466 if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id))
0467 {
0468 trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action), E_USER_WARNING);
0469 }
0470
0471 $template->assign_vars(array(
0472 'S_PERMISSION_DROPDOWN' => (sizeof($this->permission_dropdown) > 1) ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false,
0473 'L_PERMISSION_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)],
0474
0475 'U_ACTION' => $this->u_action,
0476 'S_HIDDEN_FIELDS' => $s_hidden_fields)
0477 );
0478
0479 if (strpos($mode, 'setting_') === 0)
0480 {
0481 $template->assign_vars(array(
0482 'S_SETTING_PERMISSIONS' => true)
0483 );
0484
0485 $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);
0486 $auth_admin->display_mask('set', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
0487 }
0488 else
0489 {
0490 $template->assign_vars(array(
0491 'S_VIEWING_PERMISSIONS' => true)
0492 );
0493
0494 $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);
0495 $auth_admin->display_mask('view', $permission_type, $hold_ary, ((sizeof($user_id)) ? 'user' : 'group'), (($permission_scope == 'local') ? true : false));
0496 }
0497 }
0498
0499 /**
0500 * Build +subforum options
0501 */
0502 function build_subforum_options($forum_list)
0503 {
0504 global $user;
0505
0506 $s_options = '';
0507
0508 $forum_list = array_merge($forum_list);
0509
0510 foreach ($forum_list as $key => $row)
0511 {
0512 if ($row['disabled'])
0513 {
0514 continue;
0515 }
0516
0517 $s_options .= '<option value="' . $row['forum_id'] . '"' . (($row['selected']) ? ' selected="selected"' : '') . '>' . $row['padding'] . $row['forum_name'];
0518
0519 // We check if a branch is there...
0520 $branch_there = false;
0521
0522 foreach (array_slice($forum_list, $key + 1) as $temp_row)
0523 {
0524 if ($temp_row['left_id'] > $row['left_id'] && $temp_row['left_id'] < $row['right_id'])
0525 {
0526 $branch_there = true;
0527 break;
0528 }
0529 continue;
0530 }
0531
0532 if ($branch_there)
0533 {
0534 $s_options .= ' [' . $user->lang['PLUS_SUBFORUMS'] . ']';
0535 }
0536
0537 $s_options .= '</option>';
0538 }
0539
0540 return $s_options;
0541 }
0542
0543 /**
0544 * Build dropdown field for changing permission types
0545 */
0546 function build_permission_dropdown($options, $default_option, $permission_scope)
0547 {
0548 global $user, $auth;
0549
0550 $s_dropdown_options = '';
0551 foreach ($options as $setting)
0552 {
0553 if (!$auth->acl_get('a_' . str_replace('_', '', $setting) . 'auth'))
0554 {
0555 continue;
0556 }
0557
0558 $selected = ($setting == $default_option) ? ' selected="selected"' : '';
0559 $l_setting = (isset($user->lang['permission_type'][$permission_scope][$setting])) ? $user->lang['permission_type'][$permission_scope][$setting] : $user->lang['permission_type'][$setting];
0560 $s_dropdown_options .= '<option value="' . $setting . '"' . $selected . '>' . $l_setting . '</option>';
0561 }
0562
0563 return $s_dropdown_options;
0564 }
0565
0566 /**
0567 * Check if selected items exist. Remove not found ids and if empty return error.
0568 */
0569 function check_existence($mode, &$ids)
0570 {
0571 global $db, $user;
0572
0573 switch ($mode)
0574 {
0575 case 'user':
0576 $table = USERS_TABLE;
0577 $sql_id = 'user_id';
0578 break;
0579
0580 case 'group':
0581 $table = GROUPS_TABLE;
0582 $sql_id = 'group_id';
0583 break;
0584
0585 case 'forum':
0586 $table = FORUMS_TABLE;
0587 $sql_id = 'forum_id';
0588 break;
0589 }
0590
0591 if (sizeof($ids))
0592 {
0593 $sql = "SELECT $sql_id
0594 FROM $table
0595 WHERE " . $db->sql_in_set($sql_id, $ids);
0596 $result = $db->sql_query($sql);
0597
0598 $ids = array();
0599 while ($row = $db->sql_fetchrow($result))
0600 {
0601 $ids[] = $row[$sql_id];
0602 }
0603 $db->sql_freeresult($result);
0604 }
0605
0606 if (!sizeof($ids))
0607 {
0608 trigger_error($user->lang['SELECTED_' . strtoupper($mode) . '_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING);
0609 }
0610 }
0611
0612 /**
0613 * Apply permissions
0614 */
0615 function set_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
0616 {
0617 global $user, $auth;
0618
0619 $psubmit = request_var('psubmit', array(0 => array(0 => 0)));
0620
0621 // User or group to be set?
0622 $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0623
0624 // Check the permission setting again
0625 if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0626 {
0627 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0628 }
0629
0630 $ug_id = $forum_id = 0;
0631
0632 // We loop through the auth settings defined in our submit
0633 list($ug_id, ) = each($psubmit);
0634 list($forum_id, ) = each($psubmit[$ug_id]);
0635
0636 if (empty($_POST['setting']) || empty($_POST['setting'][$ug_id]) || empty($_POST['setting'][$ug_id][$forum_id]) || !is_array($_POST['setting'][$ug_id][$forum_id]))
0637 {
0638 trigger_error('WRONG_PERMISSION_SETTING_FORMAT', E_USER_WARNING);
0639 }
0640
0641 // We obtain and check $_POST['setting'][$ug_id][$forum_id] directly and not using request_var() because request_var()
0642 // currently does not support the amount of dimensions required. ;)
0643 // $auth_settings = request_var('setting', array(0 => array(0 => array('' => 0))));
0644 $auth_settings = array_map('intval', $_POST['setting'][$ug_id][$forum_id]);
0645
0646 // Do we have a role we want to set?
0647 $assigned_role = (isset($_POST['role'][$ug_id][$forum_id])) ? (int) $_POST['role'][$ug_id][$forum_id] : 0;
0648
0649 // Do the admin want to set these permissions to other items too?
0650 $inherit = request_var('inherit', array(0 => array(0)));
0651
0652 $ug_id = array($ug_id);
0653 $forum_id = array($forum_id);
0654
0655 if (sizeof($inherit))
0656 {
0657 foreach ($inherit as $_ug_id => $forum_id_ary)
0658 {
0659 // Inherit users/groups?
0660 if (!in_array($_ug_id, $ug_id))
0661 {
0662 $ug_id[] = $_ug_id;
0663 }
0664
0665 // Inherit forums?
0666 $forum_id = array_merge($forum_id, array_keys($forum_id_ary));
0667 }
0668 }
0669
0670 $forum_id = array_unique($forum_id);
0671
0672 // If the auth settings differ from the assigned role, then do not set a role...
0673 if ($assigned_role)
0674 {
0675 if (!$this->check_assigned_role($assigned_role, $auth_settings))
0676 {
0677 $assigned_role = 0;
0678 }
0679 }
0680
0681 // Update the permission set...
0682 $auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_settings, $assigned_role);
0683
0684 // Do we need to recache the moderator lists?
0685 if ($permission_type == 'm_')
0686 {
0687 cache_moderators();
0688 }
0689
0690 // Remove users who are now moderators or admins from everyones foes list
0691 if ($permission_type == 'm_' || $permission_type == 'a_')
0692 {
0693 update_foes($group_id, $user_id);
0694 }
0695
0696 $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_id, $forum_id);
0697
0698 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0699 }
0700
0701 /**
0702 * Apply all permissions
0703 */
0704 function set_all_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id)
0705 {
0706 global $user, $auth;
0707
0708 // User or group to be set?
0709 $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0710
0711 // Check the permission setting again
0712 if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0713 {
0714 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0715 }
0716
0717 $auth_settings = (isset($_POST['setting'])) ? $_POST['setting'] : array();
0718 $auth_roles = (isset($_POST['role'])) ? $_POST['role'] : array();
0719 $ug_ids = $forum_ids = array();
0720
0721 // We need to go through the auth settings
0722 foreach ($auth_settings as $ug_id => $forum_auth_row)
0723 {
0724 $ug_id = (int) $ug_id;
0725 $ug_ids[] = $ug_id;
0726
0727 foreach ($forum_auth_row as $forum_id => $auth_options)
0728 {
0729 $forum_id = (int) $forum_id;
0730 $forum_ids[] = $forum_id;
0731
0732 // Check role...
0733 $assigned_role = (isset($auth_roles[$ug_id][$forum_id])) ? (int) $auth_roles[$ug_id][$forum_id] : 0;
0734
0735 // If the auth settings differ from the assigned role, then do not set a role...
0736 if ($assigned_role)
0737 {
0738 if (!$this->check_assigned_role($assigned_role, $auth_options))
0739 {
0740 $assigned_role = 0;
0741 }
0742 }
0743
0744 // Update the permission set...
0745 $auth_admin->acl_set($ug_type, $forum_id, $ug_id, $auth_options, $assigned_role, false);
0746 }
0747 }
0748
0749 $auth_admin->acl_clear_prefetch();
0750
0751 // Do we need to recache the moderator lists?
0752 if ($permission_type == 'm_')
0753 {
0754 cache_moderators();
0755 }
0756
0757 // Remove users who are now moderators or admins from everyones foes list
0758 if ($permission_type == 'm_' || $permission_type == 'a_')
0759 {
0760 update_foes($group_id, $user_id);
0761 }
0762
0763 $this->log_action($mode, 'add', $permission_type, $ug_type, $ug_ids, $forum_ids);
0764
0765 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0766 }
0767
0768 /**
0769 * Compare auth settings with auth settings from role
0770 * returns false if they differ, true if they are equal
0771 */
0772 function check_assigned_role($role_id, &$auth_settings)
0773 {
0774 global $db;
0775
0776 $sql = 'SELECT o.auth_option, r.auth_setting
0777 FROM ' . ACL_OPTIONS_TABLE . ' o, ' . ACL_ROLES_DATA_TABLE . ' r
0778 WHERE o.auth_option_id = r.auth_option_id
0779 AND r.role_id = ' . $role_id;
0780 $result = $db->sql_query($sql);
0781
0782 $test_auth_settings = array();
0783 while ($row = $db->sql_fetchrow($result))
0784 {
0785 $test_auth_settings[$row['auth_option']] = $row['auth_setting'];
0786 }
0787 $db->sql_freeresult($result);
0788
0789 // We need to add any ACL_NO setting from auth_settings to compare correctly
0790 foreach ($auth_settings as $option => $setting)
0791 {
0792 if ($setting == ACL_NO)
0793 {
0794 $test_auth_settings[$option] = $setting;
0795 }
0796 }
0797
0798 if (sizeof(array_diff_assoc($auth_settings, $test_auth_settings)))
0799 {
0800 return false;
0801 }
0802
0803 return true;
0804 }
0805
0806 /**
0807 * Remove permissions
0808 */
0809 function remove_permissions($mode, $permission_type, &$auth_admin, &$user_id, &$group_id, &$forum_id)
0810 {
0811 global $user, $db, $auth;
0812
0813 // User or group to be set?
0814 $ug_type = (sizeof($user_id)) ? 'user' : 'group';
0815
0816 // Check the permission setting again
0817 if (!$auth->acl_get('a_' . str_replace('_', '', $permission_type) . 'auth') || !$auth->acl_get('a_auth' . $ug_type . 's'))
0818 {
0819 trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
0820 }
0821
0822 $auth_admin->acl_delete($ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : false), $permission_type);
0823
0824 // Do we need to recache the moderator lists?
0825 if ($permission_type == 'm_')
0826 {
0827 cache_moderators();
0828 }
0829
0830 $this->log_action($mode, 'del', $permission_type, $ug_type, (($ug_type == 'user') ? $user_id : $group_id), (sizeof($forum_id) ? $forum_id : array(0 => 0)));
0831
0832 trigger_error($user->lang['AUTH_UPDATED'] . adm_back_link($this->u_action));
0833 }
0834
0835 /**
0836 * Log permission changes
0837 */
0838 function log_action($mode, $action, $permission_type, $ug_type, $ug_id, $forum_id)
0839 {
0840 global $db, $user;
0841
0842 if (!is_array($ug_id))
0843 {
0844 $ug_id = array($ug_id);
0845 }
0846
0847 if (!is_array($forum_id))
0848 {
0849 $forum_id = array($forum_id);
0850 }
0851
0852 // Logging ... first grab user or groupnames ...
0853 $sql = ($ug_type == 'group') ? 'SELECT group_name as name, group_type FROM ' . GROUPS_TABLE . ' WHERE ' : 'SELECT username as name FROM ' . USERS_TABLE . ' WHERE ';
0854 $sql .= $db->sql_in_set(($ug_type == 'group') ? 'group_id' : 'user_id', array_map('intval', $ug_id));
0855 $result = $db->sql_query($sql);
0856
0857 $l_ug_list = '';
0858 while ($row = $db->sql_fetchrow($result))
0859 {
0860 $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']);
0861 }
0862 $db->sql_freeresult($result);
0863
0864 $mode = str_replace('setting_', '', $mode);
0865
0866 if ($forum_id[0] == 0)
0867 {
0868 add_log('admin', 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), $l_ug_list);
0869 }
0870 else
0871 {
0872 // Grab the forum details if non-zero forum_id
0873 $sql = 'SELECT forum_name
0874 FROM ' . FORUMS_TABLE . '
0875 WHERE ' . $db->sql_in_set('forum_id', $forum_id);
0876 $result = $db->sql_query($sql);
0877
0878 $l_forum_list = '';
0879 while ($row = $db->sql_fetchrow($result))
0880 {
0881 $l_forum_list .= (($l_forum_list != '') ? ', ' : '') . $row['forum_name'];
0882 }
0883 $db->sql_freeresult($result);
0884
0885 add_log('admin', 'LOG_ACL_' . strtoupper($action) . '_' . strtoupper($mode) . '_' . strtoupper($permission_type), $l_forum_list, $l_ug_list);
0886 }
0887 }
0888
0889 /**
0890 * Display a complete trace tree for the selected permission to determine where settings are set/unset
0891 */
0892 function permission_trace($user_id, $forum_id, $permission)
0893 {
0894 global $db, $template, $user, $auth;
0895
0896 if ($user_id != $user->data['user_id'])
0897 {
0898 $sql = 'SELECT user_id, username, user_permissions, user_type
0899 FROM ' . USERS_TABLE . '
0900 WHERE user_id = ' . $user_id;
0901 $result = $db->sql_query($sql);
0902 $userdata = $db->sql_fetchrow($result);
0903 $db->sql_freeresult($result);
0904 }
0905 else
0906 {
0907 $userdata = $user->data;
0908 }
0909
0910 if (!$userdata)
0911 {
0912 trigger_error('NO_USERS', E_USER_ERROR);
0913 }
0914
0915 $forum_name = false;
0916
0917 if ($forum_id)
0918 {
0919 $sql = 'SELECT forum_name
0920 FROM ' . FORUMS_TABLE . "
0921 WHERE forum_id = $forum_id";
0922 $result = $db->sql_query($sql, 3600);
0923 $forum_name = $db->sql_fetchfield('forum_name');
0924 $db->sql_freeresult($result);
0925 }
0926
0927 $back = request_var('back', 0);
0928
0929 $template->assign_vars(array(
0930 'PERMISSION' => $user->lang['acl_' . $permission]['lang'],
0931 'PERMISSION_USERNAME' => $userdata['username'],
0932 'FORUM_NAME' => $forum_name,
0933
0934 'S_GLOBAL_TRACE' => ($forum_id) ? false : true,
0935
0936 'U_BACK' => ($back) ? build_url(array('f', 'back')) . "&f=$back" : '')
0937 );
0938
0939 $template->assign_block_vars('trace', array(
0940 'WHO' => $user->lang['DEFAULT'],
0941 'INFORMATION' => $user->lang['TRACE_DEFAULT'],
0942
0943 'S_SETTING_NO' => true,
0944 'S_TOTAL_NO' => true)
0945 );
0946
0947 $sql = 'SELECT DISTINCT g.group_name, g.group_id, g.group_type
0948 FROM ' . GROUPS_TABLE . ' g
0949 LEFT JOIN ' . USER_GROUP_TABLE . ' ug ON (ug.group_id = g.group_id)
0950 WHERE ug.user_id = ' . $user_id . '
0951 AND ug.user_pending = 0
0952 ORDER BY g.group_type DESC, g.group_id DESC';
0953 $result = $db->sql_query($sql);
0954
0955 $groups = array();
0956 while ($row = $db->sql_fetchrow($result))
0957 {
0958 $groups[$row['group_id']] = array(
0959 'auth_setting' => ACL_NO,
0960 'group_name' => ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']
0961 );
0962 }
0963 $db->sql_freeresult($result);
0964
0965 $total = ACL_NO;
0966 $add_key = (($forum_id) ? '_LOCAL' : '');
0967
0968 if (sizeof($groups))
0969 {
0970 // Get group auth settings
0971 $hold_ary = $auth->acl_group_raw_data(array_keys($groups), $permission, $forum_id);
0972
0973 foreach ($hold_ary as $group_id => $forum_ary)
0974 {
0975 $groups[$group_id]['auth_setting'] = $hold_ary[$group_id][$forum_id][$permission];
0976 }
0977 unset($hold_ary);
0978
0979 foreach ($groups as $id => $row)
0980 {
0981 switch ($row['auth_setting'])
0982 {
0983 case ACL_NO:
0984 $information = $user->lang['TRACE_GROUP_NO' . $add_key];
0985 break;
0986
0987 case ACL_YES:
0988 $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]);
0989 $total = ($total == ACL_NO) ? ACL_YES : $total;
0990 break;
0991
0992 case ACL_NEVER:
0993 $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]);
0994 $total = ACL_NEVER;
0995 break;
0996 }
0997
0998 $template->assign_block_vars('trace', array(
0999 'WHO' => $row['group_name'],
1000 'INFORMATION' => $information,
1001
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)
1008 );
1009 }
1010 }
1011
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];
1015
1016 switch ($auth_setting)
1017 {
1018 case ACL_NO:
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;
1021 break;
1022
1023 case ACL_YES:
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;
1026 break;
1027
1028 case ACL_NEVER:
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]);
1030 $total = ACL_NEVER;
1031 break;
1032 }
1033
1034 $template->assign_block_vars('trace', array(
1035 'WHO' => $userdata['username'],
1036 'INFORMATION' => $information,
1037
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)
1044 );
1045
1046 if ($forum_id != 0 && isset($auth->acl_options['global'][$permission]))
1047 {
1048 if ($user_id != $user->data['user_id'])
1049 {
1050 $auth2 = new auth();
1051 $auth2->acl($userdata);
1052 $auth_setting = $auth2->acl_get($permission);
1053 }
1054 else
1055 {
1056 $auth_setting = $auth->acl_get($permission);
1057 }
1058
1059 if ($auth_setting)
1060 {
1061 $information = ($total == ACL_YES) ? $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_YES'] : $user->lang['TRACE_USER_GLOBAL_YES_TOTAL_NEVER'];
1062 $total = ACL_YES;
1063 }
1064 else
1065 {
1066 $information = $user->lang['TRACE_USER_GLOBAL_NEVER_TOTAL_KEPT'];
1067 }
1068
1069 // If there is no auth information we do not need to worry the user by showing non-relevant data.
1070 if ($auth_setting)
1071 {
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>'),
1075
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)
1082 );
1083 }
1084 }
1085
1086 // Take founder status into account, overwriting the default values
1087 if ($userdata['user_type'] == USER_FOUNDER && strpos($permission, 'a_') === 0)
1088 {
1089 $template->assign_block_vars('trace', array(
1090 'WHO' => $userdata['username'],
1091 'INFORMATION' => $user->lang['TRACE_USER_FOUNDER'],
1092
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)
1099 );
1100
1101 $total = ACL_YES;
1102 }
1103
1104 // Total value...
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,
1109 ));
1110 }
1111
1112 /**
1113 * Get already assigned users/groups
1114 */
1115 function retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type)
1116 {
1117 global $db, $user;
1118
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);
1121
1122 $sql = $db->sql_build_query('SELECT_DISTINCT', array(
1123 'SELECT' => 'u.username, u.username_clean, u.user_regdate, u.user_id',
1124
1125 'FROM' => array(
1126 USERS_TABLE => 'u',
1127 ACL_OPTIONS_TABLE => 'o',
1128 ACL_USERS_TABLE => 'a'
1129 ),
1130
1131 'LEFT_JOIN' => array(
1132 array(
1133 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
1134 'ON' => 'a.auth_role_id = r.role_id'
1135 )
1136 ),
1137
1138 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
1139 $sql_permission_option
1140 $sql_forum_id
1141 AND u.user_id = a.user_id",
1142
1143 'ORDER_BY' => 'u.username_clean, u.user_regdate ASC'
1144 ));
1145 $result = $db->sql_query($sql);
1146
1147 $s_defined_user_options = '';
1148 $defined_user_ids = array();
1149 while ($row = $db->sql_fetchrow($result))
1150 {
1151 $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>';
1152 $defined_user_ids[] = $row['user_id'];
1153 }
1154 $db->sql_freeresult($result);
1155
1156 $sql = $db->sql_build_query('SELECT_DISTINCT', array(
1157 'SELECT' => 'g.group_type, g.group_name, g.group_id',
1158
1159 'FROM' => array(
1160 GROUPS_TABLE => 'g',
1161 ACL_OPTIONS_TABLE => 'o',
1162 ACL_GROUPS_TABLE => 'a'
1163 ),
1164
1165 'LEFT_JOIN' => array(
1166 array(
1167 'FROM' => array(ACL_ROLES_DATA_TABLE => 'r'),
1168 'ON' => 'a.auth_role_id = r.role_id'
1169 )
1170 ),
1171
1172 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)
1173 $sql_permission_option
1174 $sql_forum_id
1175 AND g.group_id = a.group_id",
1176
1177 'ORDER_BY' => 'g.group_type DESC, g.group_name ASC'
1178 ));
1179 $result = $db->sql_query($sql);
1180
1181 $s_defined_group_options = '';
1182 $defined_group_ids = array();
1183 while ($row = $db->sql_fetchrow($result))
1184 {
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'];
1187 }
1188 $db->sql_freeresult($result);
1189
1190 return array(
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
1195 );
1196 }
1197 }
1198
1199 ?>