includes/acp/acp_permission_roles.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/acp/acp_permission_roles.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,571 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* @package acp
    1.24 +*/
    1.25 +class acp_permission_roles
    1.26 +{
    1.27 +	var $u_action;
    1.28 +
    1.29 +	function main($id, $mode)
    1.30 +	{
    1.31 +		global $db, $user, $auth, $template, $cache;
    1.32 +		global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
    1.33 +
    1.34 +		include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.35 +		include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
    1.36 +
    1.37 +		$auth_admin = new auth_admin();
    1.38 +
    1.39 +		$user->add_lang('acp/permissions');
    1.40 +		add_permission_language();
    1.41 +
    1.42 +		$this->tpl_name = 'acp_permission_roles';
    1.43 +
    1.44 +		$submit = (isset($_POST['submit'])) ? true : false;
    1.45 +		$role_id = request_var('role_id', 0);
    1.46 +		$action = request_var('action', '');
    1.47 +		$action = (isset($_POST['add'])) ? 'add' : $action;
    1.48 +
    1.49 +		$form_name = 'acp_permissions';
    1.50 +		add_form_key($form_name);
    1.51 +
    1.52 +		switch ($mode)
    1.53 +		{
    1.54 +			case 'admin_roles':
    1.55 +				$permission_type = 'a_';
    1.56 +				$this->page_title = 'ACP_ADMIN_ROLES';
    1.57 +			break;
    1.58 +
    1.59 +			case 'user_roles':
    1.60 +				$permission_type = 'u_';
    1.61 +				$this->page_title = 'ACP_USER_ROLES';
    1.62 +			break;
    1.63 +
    1.64 +			case 'mod_roles':
    1.65 +				$permission_type = 'm_';
    1.66 +				$this->page_title = 'ACP_MOD_ROLES';
    1.67 +			break;
    1.68 +
    1.69 +			case 'forum_roles':
    1.70 +				$permission_type = 'f_';
    1.71 +				$this->page_title = 'ACP_FORUM_ROLES';
    1.72 +			break;
    1.73 +
    1.74 +			default:
    1.75 +				trigger_error('NO_MODE', E_USER_ERROR);
    1.76 +			break;
    1.77 +		}
    1.78 +
    1.79 +		$template->assign_vars(array(
    1.80 +			'L_TITLE'		=> $user->lang[$this->page_title],
    1.81 +			'L_EXPLAIN'		=> $user->lang[$this->page_title . '_EXPLAIN'])
    1.82 +		);
    1.83 +
    1.84 +		// Take action... admin submitted something
    1.85 +		if ($submit || $action == 'remove')
    1.86 +		{
    1.87 +			switch ($action)
    1.88 +			{
    1.89 +				case 'remove':
    1.90 +
    1.91 +					if (!$role_id)
    1.92 +					{
    1.93 +						trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
    1.94 +					}
    1.95 +
    1.96 +					$sql = 'SELECT *
    1.97 +						FROM ' . ACL_ROLES_TABLE . '
    1.98 +						WHERE role_id = ' . $role_id;
    1.99 +					$result = $db->sql_query($sql);
   1.100 +					$role_row = $db->sql_fetchrow($result);
   1.101 +					$db->sql_freeresult($result);
   1.102 +
   1.103 +					if (!$role_row)
   1.104 +					{
   1.105 +						trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.106 +					}
   1.107 +
   1.108 +					if (confirm_box(true))
   1.109 +					{
   1.110 +						$this->remove_role($role_id, $permission_type);
   1.111 +
   1.112 +						$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
   1.113 +						add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_REMOVED', $role_name);
   1.114 +						trigger_error($user->lang['ROLE_DELETED'] . adm_back_link($this->u_action));
   1.115 +					}
   1.116 +					else
   1.117 +					{
   1.118 +						confirm_box(false, 'DELETE_ROLE', build_hidden_fields(array(
   1.119 +							'i'			=> $id,
   1.120 +							'mode'		=> $mode,
   1.121 +							'role_id'	=> $role_id,
   1.122 +							'action'	=> $action,
   1.123 +						)));
   1.124 +					}
   1.125 +
   1.126 +				break;
   1.127 +
   1.128 +				case 'edit':
   1.129 +					if (!$role_id)
   1.130 +					{
   1.131 +						trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.132 +					}
   1.133 +
   1.134 +					// Get role we edit
   1.135 +					$sql = 'SELECT *
   1.136 +						FROM ' . ACL_ROLES_TABLE . '
   1.137 +						WHERE role_id = ' . $role_id;
   1.138 +					$result = $db->sql_query($sql);
   1.139 +					$role_row = $db->sql_fetchrow($result);
   1.140 +					$db->sql_freeresult($result);
   1.141 +
   1.142 +					if (!$role_row)
   1.143 +					{
   1.144 +						trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.145 +					}
   1.146 +
   1.147 +				// no break;
   1.148 +
   1.149 +				case 'add':
   1.150 +
   1.151 +					if (!check_form_key($form_name))
   1.152 +					{
   1.153 +						trigger_error($user->lang['FORM_INVALID']. adm_back_link($this->u_action), E_USER_WARNING);
   1.154 +					}
   1.155 +
   1.156 +					$role_name = utf8_normalize_nfc(request_var('role_name', '', true));
   1.157 +					$role_description = utf8_normalize_nfc(request_var('role_description', '', true));
   1.158 +					$auth_settings = request_var('setting', array('' => 0));
   1.159 +
   1.160 +					if (!$role_name)
   1.161 +					{
   1.162 +						trigger_error($user->lang['NO_ROLE_NAME_SPECIFIED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.163 +					}
   1.164 +
   1.165 +					if (utf8_strlen($role_description) > 4000)
   1.166 +					{
   1.167 +						trigger_error($user->lang['ROLE_DESCRIPTION_LONG'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.168 +					}
   1.169 +
   1.170 +					// if we add/edit a role we check the name to be unique among the settings...
   1.171 +					$sql = 'SELECT role_id
   1.172 +						FROM ' . ACL_ROLES_TABLE . "
   1.173 +						WHERE role_type = '" . $db->sql_escape($permission_type) . "'
   1.174 +							AND role_name = '" . $db->sql_escape($role_name) . "'";
   1.175 +					$result = $db->sql_query($sql);
   1.176 +					$row = $db->sql_fetchrow($result);
   1.177 +					$db->sql_freeresult($result);
   1.178 +
   1.179 +					// Make sure we only print out the error if we add the role or change it's name
   1.180 +					if ($row && ($mode == 'add' || ($mode == 'edit' && $role_row['role_name'] != $role_name)))
   1.181 +					{
   1.182 +						trigger_error(sprintf($user->lang['ROLE_NAME_ALREADY_EXIST'], $role_name) . adm_back_link($this->u_action), E_USER_WARNING);
   1.183 +					}
   1.184 +
   1.185 +					$sql_ary = array(
   1.186 +						'role_name'			=> (string) $role_name,
   1.187 +						'role_description'	=> (string) $role_description,
   1.188 +						'role_type'			=> (string) $permission_type,
   1.189 +					);
   1.190 +
   1.191 +					if ($action == 'edit')
   1.192 +					{
   1.193 +						$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
   1.194 +							SET ' . $db->sql_build_array('UPDATE', $sql_ary) . '
   1.195 +							WHERE role_id = ' . $role_id;
   1.196 +						$db->sql_query($sql);
   1.197 +					}
   1.198 +					else
   1.199 +					{
   1.200 +						// Get maximum role order for inserting a new role...
   1.201 +						$sql = 'SELECT MAX(role_order) as max_order
   1.202 +							FROM ' . ACL_ROLES_TABLE . "
   1.203 +							WHERE role_type = '" . $db->sql_escape($permission_type) . "'";
   1.204 +						$result = $db->sql_query($sql);
   1.205 +						$max_order = (int) $db->sql_fetchfield('max_order');
   1.206 +						$db->sql_freeresult($result);
   1.207 +
   1.208 +						$sql_ary['role_order'] = $max_order + 1;
   1.209 +
   1.210 +						$sql = 'INSERT INTO ' . ACL_ROLES_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
   1.211 +						$db->sql_query($sql);
   1.212 +
   1.213 +						$role_id = $db->sql_nextid();
   1.214 +					}
   1.215 +
   1.216 +					// Now add the auth settings
   1.217 +					$auth_admin->acl_set_role($role_id, $auth_settings);
   1.218 +
   1.219 +					$role_name = (!empty($user->lang[$role_name])) ? $user->lang[$role_name] : $role_name;
   1.220 +					add_log('admin', 'LOG_' . strtoupper($permission_type) . 'ROLE_' . strtoupper($action), $role_name);
   1.221 +
   1.222 +					trigger_error($user->lang['ROLE_' . strtoupper($action) . '_SUCCESS'] . adm_back_link($this->u_action));
   1.223 +
   1.224 +				break;
   1.225 +			}
   1.226 +		}
   1.227 +
   1.228 +		// Display screens
   1.229 +		switch ($action)
   1.230 +		{
   1.231 +			case 'add':
   1.232 +
   1.233 +				$options_from = request_var('options_from', 0);
   1.234 +
   1.235 +				$role_row = array(
   1.236 +					'role_name'			=> utf8_normalize_nfc(request_var('role_name', '', true)),
   1.237 +					'role_description'	=> utf8_normalize_nfc(request_var('role_description', '', true)),
   1.238 +					'role_type'			=> $permission_type,
   1.239 +				);
   1.240 +
   1.241 +				if ($options_from)
   1.242 +				{
   1.243 +					$sql = 'SELECT p.auth_option_id, p.auth_setting, o.auth_option
   1.244 +						FROM ' . ACL_ROLES_DATA_TABLE . ' p, ' . ACL_OPTIONS_TABLE . ' o
   1.245 +						WHERE o.auth_option_id = p.auth_option_id
   1.246 +							AND p.role_id = ' . $options_from . '
   1.247 +						ORDER BY p.auth_option_id';
   1.248 +					$result = $db->sql_query($sql);
   1.249 +
   1.250 +					$auth_options = array();
   1.251 +					while ($row = $db->sql_fetchrow($result))
   1.252 +					{
   1.253 +						$auth_options[$row['auth_option']] = $row['auth_setting'];
   1.254 +					}
   1.255 +					$db->sql_freeresult($result);
   1.256 +				}
   1.257 +				else
   1.258 +				{
   1.259 +					$sql = 'SELECT auth_option_id, auth_option
   1.260 +						FROM ' . ACL_OPTIONS_TABLE . "
   1.261 +						WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char) . "
   1.262 +							AND auth_option <> '{$permission_type}'
   1.263 +						ORDER BY auth_option_id";
   1.264 +					$result = $db->sql_query($sql);
   1.265 +
   1.266 +					$auth_options = array();
   1.267 +					while ($row = $db->sql_fetchrow($result))
   1.268 +					{
   1.269 +						$auth_options[$row['auth_option']] = ACL_NO;
   1.270 +					}
   1.271 +					$db->sql_freeresult($result);
   1.272 +				}
   1.273 +
   1.274 +			// no break;
   1.275 +
   1.276 +			case 'edit':
   1.277 +
   1.278 +				if ($action == 'edit')
   1.279 +				{
   1.280 +					if (!$role_id)
   1.281 +					{
   1.282 +						trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.283 +					}
   1.284 +					
   1.285 +					$sql = 'SELECT *
   1.286 +						FROM ' . ACL_ROLES_TABLE . '
   1.287 +						WHERE role_id = ' . $role_id;
   1.288 +					$result = $db->sql_query($sql);
   1.289 +					$role_row = $db->sql_fetchrow($result);
   1.290 +					$db->sql_freeresult($result);
   1.291 +
   1.292 +					$sql = 'SELECT p.auth_option_id, p.auth_setting, o.auth_option
   1.293 +						FROM ' . ACL_ROLES_DATA_TABLE . ' p, ' . ACL_OPTIONS_TABLE . ' o
   1.294 +						WHERE o.auth_option_id = p.auth_option_id
   1.295 +							AND p.role_id = ' . $role_id . '
   1.296 +						ORDER BY p.auth_option_id';
   1.297 +					$result = $db->sql_query($sql);
   1.298 +
   1.299 +					$auth_options = array();
   1.300 +					while ($row = $db->sql_fetchrow($result))
   1.301 +					{
   1.302 +						$auth_options[$row['auth_option']] = $row['auth_setting'];
   1.303 +					}
   1.304 +					$db->sql_freeresult($result);
   1.305 +				}
   1.306 +
   1.307 +				if (!$role_row)
   1.308 +				{
   1.309 +					trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);
   1.310 +				}
   1.311 +
   1.312 +				$template->assign_vars(array(
   1.313 +					'S_EDIT'			=> true,
   1.314 +
   1.315 +					'U_ACTION'			=> $this->u_action . "&amp;action={$action}&amp;role_id={$role_id}",
   1.316 +					'U_BACK'			=> $this->u_action,
   1.317 +
   1.318 +					'ROLE_NAME'			=> $role_row['role_name'],
   1.319 +					'ROLE_DESCRIPTION'	=> $role_row['role_description'],
   1.320 +					'L_ACL_TYPE'		=> $user->lang['ACL_TYPE_' . strtoupper($permission_type)],
   1.321 +					)
   1.322 +				);
   1.323 +
   1.324 +				// We need to fill the auth options array with ACL_NO options ;)
   1.325 +				$sql = 'SELECT auth_option_id, auth_option
   1.326 +					FROM ' . ACL_OPTIONS_TABLE . "
   1.327 +					WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char) . "
   1.328 +						AND auth_option <> '{$permission_type}'
   1.329 +					ORDER BY auth_option_id";
   1.330 +				$result = $db->sql_query($sql);
   1.331 +
   1.332 +				while ($row = $db->sql_fetchrow($result))
   1.333 +				{
   1.334 +					if (!isset($auth_options[$row['auth_option']]))
   1.335 +					{
   1.336 +						$auth_options[$row['auth_option']] = ACL_NO;
   1.337 +					}
   1.338 +				}
   1.339 +				$db->sql_freeresult($result);
   1.340 +
   1.341 +				// Unset global permission option
   1.342 +				unset($auth_options[$permission_type]);
   1.343 +
   1.344 +				// Display auth options
   1.345 +				$this->display_auth_options($auth_options);
   1.346 +
   1.347 +				// Get users/groups/forums using this preset...
   1.348 +				if ($action == 'edit')
   1.349 +				{
   1.350 +					$hold_ary = $auth_admin->get_role_mask($role_id);
   1.351 +
   1.352 +					if (sizeof($hold_ary))
   1.353 +					{
   1.354 +						$role_name = (!empty($user->lang[$role_row['role_name']])) ? $user->lang[$role_row['role_name']] : $role_row['role_name'];
   1.355 +
   1.356 +						$template->assign_vars(array(
   1.357 +							'S_DISPLAY_ROLE_MASK'	=> true,
   1.358 +							'L_ROLE_ASSIGNED_TO'	=> sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_name))
   1.359 +						);
   1.360 +
   1.361 +						$auth_admin->display_role_mask($hold_ary);
   1.362 +					}
   1.363 +				}
   1.364 +
   1.365 +				return;
   1.366 +			break;
   1.367 +
   1.368 +			case 'move_up':
   1.369 +			case 'move_down':
   1.370 +
   1.371 +				$order = request_var('order', 0);
   1.372 +				$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);
   1.373 +
   1.374 +				$sql = 'UPDATE ' . ACL_ROLES_TABLE . '
   1.375 +					SET role_order = ' . $order_total . " - role_order
   1.376 +					WHERE role_type = '" . $db->sql_escape($permission_type) . "'
   1.377 +						AND role_order IN ($order, " . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';
   1.378 +				$db->sql_query($sql);
   1.379 +
   1.380 +			break;
   1.381 +		}
   1.382 +
   1.383 +		// By default, check that role_order is valid and fix it if necessary
   1.384 +		$sql = 'SELECT role_id, role_order
   1.385 +			FROM ' . ACL_ROLES_TABLE . "
   1.386 +			WHERE role_type = '" . $db->sql_escape($permission_type) . "'
   1.387 +			ORDER BY role_order ASC";
   1.388 +		$result = $db->sql_query($sql);
   1.389 +
   1.390 +		if ($row = $db->sql_fetchrow($result))
   1.391 +		{
   1.392 +			$order = 0;
   1.393 +			do
   1.394 +			{
   1.395 +				$order++;
   1.396 +				if ($row['role_order'] != $order)
   1.397 +				{
   1.398 +					$db->sql_query('UPDATE ' . ACL_ROLES_TABLE . " SET role_order = $order WHERE role_id = {$row['role_id']}");
   1.399 +				}
   1.400 +			}
   1.401 +			while ($row = $db->sql_fetchrow($result));
   1.402 +		}
   1.403 +		$db->sql_freeresult($result);
   1.404 +
   1.405 +		// Display assigned items?
   1.406 +		$display_item = request_var('display_item', 0);
   1.407 +
   1.408 +		// Select existing roles
   1.409 +		$sql = 'SELECT *
   1.410 +			FROM ' . ACL_ROLES_TABLE . "
   1.411 +			WHERE role_type = '" . $db->sql_escape($permission_type) . "'
   1.412 +			ORDER BY role_order ASC";
   1.413 +		$result = $db->sql_query($sql);
   1.414 +
   1.415 +		$s_role_options = '';
   1.416 +		while ($row = $db->sql_fetchrow($result))
   1.417 +		{
   1.418 +			$role_name = (!empty($user->lang[$row['role_name']])) ? $user->lang[$row['role_name']] : $row['role_name'];
   1.419 +
   1.420 +			$template->assign_block_vars('roles', array(
   1.421 +				'ROLE_NAME'				=> $role_name,
   1.422 +				'ROLE_DESCRIPTION'		=> (!empty($user->lang[$row['role_description']])) ? $user->lang[$row['role_description']] : nl2br($row['role_description']),
   1.423 +
   1.424 +				'U_EDIT'			=> $this->u_action . '&amp;action=edit&amp;role_id=' . $row['role_id'],
   1.425 +				'U_REMOVE'			=> $this->u_action . '&amp;action=remove&amp;role_id=' . $row['role_id'],
   1.426 +				'U_MOVE_UP'			=> $this->u_action . '&amp;action=move_up&amp;order=' . $row['role_order'],
   1.427 +				'U_MOVE_DOWN'		=> $this->u_action . '&amp;action=move_down&amp;order=' . $row['role_order'],
   1.428 +				'U_DISPLAY_ITEMS'	=> ($row['role_id'] == $display_item) ? '' : $this->u_action . '&amp;display_item=' . $row['role_id'] . '#assigned_to')
   1.429 +			);
   1.430 +
   1.431 +			$s_role_options .= '<option value="' . $row['role_id'] . '">' . $role_name . '</option>';
   1.432 +
   1.433 +			if ($display_item == $row['role_id'])
   1.434 +			{
   1.435 +				$template->assign_vars(array(
   1.436 +					'L_ROLE_ASSIGNED_TO'	=> sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_name))
   1.437 +				);
   1.438 +			}
   1.439 +		}
   1.440 +		$db->sql_freeresult($result);
   1.441 +
   1.442 +		$template->assign_vars(array(
   1.443 +			'S_ROLE_OPTIONS'		=> $s_role_options)
   1.444 +		);
   1.445 +
   1.446 +		if ($display_item)
   1.447 +		{
   1.448 +			$template->assign_vars(array(
   1.449 +				'S_DISPLAY_ROLE_MASK'	=> true)
   1.450 +			);
   1.451 +
   1.452 +			$hold_ary = $auth_admin->get_role_mask($display_item);
   1.453 +			$auth_admin->display_role_mask($hold_ary);
   1.454 +		}
   1.455 +	}
   1.456 +
   1.457 +	/**
   1.458 +	* Display permission settings able to be set
   1.459 +	*/
   1.460 +	function display_auth_options($auth_options)
   1.461 +	{
   1.462 +		global $template, $user;
   1.463 +
   1.464 +		$content_array = $categories = array();
   1.465 +		$key_sort_array = array(0);
   1.466 +		$auth_options = array(0 => $auth_options);
   1.467 +
   1.468 +		// Making use of auth_admin method here (we do not really want to change two similar code fragments)
   1.469 +		auth_admin::build_permission_array($auth_options, $content_array, $categories, $key_sort_array);
   1.470 +
   1.471 +		$content_array = $content_array[0];
   1.472 +
   1.473 +		$template->assign_var('S_NUM_PERM_COLS', sizeof($categories));
   1.474 +
   1.475 +		// Assign to template
   1.476 +		foreach ($content_array as $cat => $cat_array)
   1.477 +		{
   1.478 +			$template->assign_block_vars('auth', array(
   1.479 +				'CAT_NAME'	=> $user->lang['permission_cat'][$cat],
   1.480 +
   1.481 +				'S_YES'		=> ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,
   1.482 +				'S_NEVER'	=> ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,
   1.483 +				'S_NO'		=> ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false)
   1.484 +			);
   1.485 +
   1.486 +			foreach ($cat_array['permissions'] as $permission => $allowed)
   1.487 +			{
   1.488 +				$template->assign_block_vars('auth.mask', array(
   1.489 +					'S_YES'		=> ($allowed == ACL_YES) ? true : false,
   1.490 +					'S_NEVER'	=> ($allowed == ACL_NEVER) ? true : false,
   1.491 +					'S_NO'		=> ($allowed == ACL_NO) ? true : false,
   1.492 +
   1.493 +					'FIELD_NAME'	=> $permission,
   1.494 +					'PERMISSION'	=> $user->lang['acl_' . $permission]['lang'])
   1.495 +				);
   1.496 +			}
   1.497 +		}
   1.498 +	}
   1.499 +
   1.500 +	/**
   1.501 +	* Remove role
   1.502 +	*/
   1.503 +	function remove_role($role_id, $permission_type)
   1.504 +	{
   1.505 +		global $db;
   1.506 +
   1.507 +		$auth_admin = new auth_admin();
   1.508 +
   1.509 +		// Get complete auth array
   1.510 +		$sql = 'SELECT auth_option, auth_option_id
   1.511 +			FROM ' . ACL_OPTIONS_TABLE . "
   1.512 +			WHERE auth_option " . $db->sql_like_expression($permission_type . $db->any_char);
   1.513 +		$result = $db->sql_query($sql);
   1.514 +
   1.515 +		$auth_settings = array();
   1.516 +		while ($row = $db->sql_fetchrow($result))
   1.517 +		{
   1.518 +			$auth_settings[$row['auth_option']] = ACL_NO;
   1.519 +		}
   1.520 +		$db->sql_freeresult($result);
   1.521 +
   1.522 +		// Get the role auth settings we need to re-set...
   1.523 +		$sql = 'SELECT o.auth_option, r.auth_setting
   1.524 +			FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o
   1.525 +			WHERE o.auth_option_id = r.auth_option_id
   1.526 +				AND r.role_id = ' . $role_id;
   1.527 +		$result = $db->sql_query($sql);
   1.528 +
   1.529 +		while ($row = $db->sql_fetchrow($result))
   1.530 +		{
   1.531 +			$auth_settings[$row['auth_option']] = $row['auth_setting'];
   1.532 +		}
   1.533 +		$db->sql_freeresult($result);
   1.534 +
   1.535 +		// Get role assignments
   1.536 +		$hold_ary = $auth_admin->get_role_mask($role_id);
   1.537 +
   1.538 +		// Re-assign permissions
   1.539 +		foreach ($hold_ary as $forum_id => $forum_ary)
   1.540 +		{
   1.541 +			if (isset($forum_ary['users']))
   1.542 +			{
   1.543 +				$auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false);
   1.544 +			}
   1.545 +
   1.546 +			if (isset($forum_ary['groups']))
   1.547 +			{
   1.548 +				$auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false);
   1.549 +			}
   1.550 +		}
   1.551 +
   1.552 +		// Remove role from users and groups just to be sure (happens through acl_set)
   1.553 +		$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
   1.554 +			WHERE auth_role_id = ' . $role_id;
   1.555 +		$db->sql_query($sql);
   1.556 +
   1.557 +		$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
   1.558 +			WHERE auth_role_id = ' . $role_id;
   1.559 +		$db->sql_query($sql);
   1.560 +
   1.561 +		// Remove role data and role
   1.562 +		$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '
   1.563 +			WHERE role_id = ' . $role_id;
   1.564 +		$db->sql_query($sql);
   1.565 +
   1.566 +		$sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '
   1.567 +			WHERE role_id = ' . $role_id;
   1.568 +		$db->sql_query($sql);
   1.569 +
   1.570 +		$auth_admin->acl_clear_prefetch();
   1.571 +	}
   1.572 +}
   1.573 +
   1.574 +?>
   1.575 \ No newline at end of file