⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 acp_permission_roles.php

📁 这些都是我以前学习是用到的源码
💻 PHP
📖 第 1 页 / 共 2 页
字号:
					$auth_options = array();					while ($row = $db->sql_fetchrow($result))					{						$auth_options[$row['auth_option']] = $row['auth_setting'];					}					$db->sql_freeresult($result);				}				if (!$role_row)				{					trigger_error($user->lang['NO_ROLE_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING);				}				$template->assign_vars(array(					'S_EDIT'			=> true,					'U_ACTION'			=> $this->u_action . "&amp;action={$action}&amp;role_id={$role_id}",					'U_BACK'			=> $this->u_action,					'ROLE_NAME'			=> $role_row['role_name'],					'ROLE_DESCRIPTION'	=> $role_row['role_description'],					'L_ACL_TYPE'		=> $user->lang['ACL_TYPE_' . strtoupper($permission_type)],					)				);				// We need to fill the auth options array with ACL_NO options ;)				$sql = 'SELECT auth_option_id, auth_option					FROM ' . ACL_OPTIONS_TABLE . "					WHERE auth_option LIKE '{$permission_type}%'						AND auth_option <> '{$permission_type}'					ORDER BY auth_option_id";				$result = $db->sql_query($sql);				while ($row = $db->sql_fetchrow($result))				{					if (!isset($auth_options[$row['auth_option']]))					{						$auth_options[$row['auth_option']] = ACL_NO;					}				}				$db->sql_freeresult($result);				// Unset global permission option				unset($auth_options[$permission_type]);				// Display auth options				$this->display_auth_options($auth_options);				// Get users/groups/forums using this preset...				if ($action == 'edit')				{					$hold_ary = $auth_admin->get_role_mask($role_id);					if (sizeof($hold_ary))					{						$template->assign_var(array(							'S_DISPLAY_ROLE_MASK'	=> true,							'L_ROLE_ASSIGNED_TO'	=> sprintf($user->lang['ROLE_ASSIGNED_TO'], $role_row['role_name']))						);						$auth_admin->display_role_mask($hold_ary);					}				}				return;			break;			case 'move_up':			case 'move_down':				$order = request_var('order', 0);				$order_total = $order * 2 + (($action == 'move_up') ? -1 : 1);				$sql = 'UPDATE ' . ACL_ROLES_TABLE . '					SET role_order = ' . $order_total  . " - role_order					WHERE role_type = '" . $db->sql_escape($permission_type) . "'						AND role_order IN ($order, " . (($action == 'move_up') ? $order - 1 : $order + 1) . ')';				$db->sql_query($sql);			break;		}		// By default, check that role_order is valid and fix it if necessary		$sql = 'SELECT role_id, role_order			FROM ' . ACL_ROLES_TABLE . "			WHERE role_type = '" . $db->sql_escape($permission_type) . "'			ORDER BY role_order ASC";		$result = $db->sql_query($sql);		if ($row = $db->sql_fetchrow($result))		{			$order = 0;			do			{				$order++;				if ($row['role_order'] != $order)				{					$db->sql_query('UPDATE ' . ACL_ROLES_TABLE . " SET role_order = $order WHERE role_id = {$row['role_id']}");				}			}			while ($row = $db->sql_fetchrow($result));		}		$db->sql_freeresult($result);		// Display assigned items?		$display_item = request_var('display_item', 0);		// Select existing roles		$sql = 'SELECT *			FROM ' . ACL_ROLES_TABLE . "			WHERE role_type = '" . $db->sql_escape($permission_type) . "'			ORDER BY role_order ASC";		$result = $db->sql_query($sql);		$s_role_options = '';		while ($row = $db->sql_fetchrow($result))		{			$template->assign_block_vars('roles', array(				'ROLE_NAME'				=> $row['role_name'],				'ROLE_DESCRIPTION'		=> (!empty($user->lang[$row['role_description']])) ? $user->lang[$row['role_description']] : nl2br($row['role_description']),				'U_EDIT'			=> $this->u_action . '&amp;action=edit&amp;role_id=' . $row['role_id'],				'U_REMOVE'			=> $this->u_action . '&amp;action=remove&amp;role_id=' . $row['role_id'],				'U_MOVE_UP'			=> $this->u_action . '&amp;action=move_up&amp;order=' . $row['role_order'],				'U_MOVE_DOWN'		=> $this->u_action . '&amp;action=move_down&amp;order=' . $row['role_order'],				'U_DISPLAY_ITEMS'	=> ($row['role_id'] == $display_item) ? '' : $this->u_action . '&amp;display_item=' . $row['role_id'] . '#assigned_to')			);			$s_role_options .= '<option value="' . $row['role_id'] . '">' . $row['role_name'] . '</option>';			if ($display_item == $row['role_id'])			{				$template->assign_vars(array(					'L_ROLE_ASSIGNED_TO'	=> sprintf($user->lang['ROLE_ASSIGNED_TO'], $row['role_name']))				);			}		}		$db->sql_freeresult($result);		$template->assign_vars(array(			'S_ROLE_OPTIONS'		=> $s_role_options)		);		if ($display_item)		{			$template->assign_vars(array(				'S_DISPLAY_ROLE_MASK'	=> true)			);			$hold_ary = $auth_admin->get_role_mask($display_item);			$auth_admin->display_role_mask($hold_ary);		}	}	/**	* Display permission settings able to be set	*/	function display_auth_options($auth_options)	{		global $template, $user;		$content_array = $categories = array();		$key_sort_array = array(0);		$auth_options = array(0 => $auth_options);		// Making use of auth_admin method here (we do not really want to change two similar code fragments)		auth_admin::build_permission_array($auth_options, $content_array, $categories, $key_sort_array);		$content_array = $content_array[0];		$template->assign_var('S_NUM_PERM_COLS', sizeof($categories));		// Assign to template		foreach ($content_array as $cat => $cat_array)		{			$template->assign_block_vars('auth', array(				'CAT_NAME'	=> $user->lang['permission_cat'][$cat],				'S_YES'		=> ($cat_array['S_YES'] && !$cat_array['S_NEVER'] && !$cat_array['S_NO']) ? true : false,				'S_NEVER'	=> ($cat_array['S_NEVER'] && !$cat_array['S_YES'] && !$cat_array['S_NO']) ? true : false,				'S_NO'		=> ($cat_array['S_NO'] && !$cat_array['S_NEVER'] && !$cat_array['S_YES']) ? true : false)			);			foreach ($cat_array['permissions'] as $permission => $allowed)			{				$template->assign_block_vars('auth.mask', array(					'S_YES'		=> ($allowed == ACL_YES) ? true : false,					'S_NEVER'	=> ($allowed == ACL_NEVER) ? true : false,					'S_NO'		=> ($allowed == ACL_NO) ? true : false,					'FIELD_NAME'	=> $permission,					'PERMISSION'	=> $user->lang['acl_' . $permission]['lang'])				);			}		}	}	/**	* Remove role	*/	function remove_role($role_id, $permission_type)	{		global $db;		$auth_admin = new auth_admin();		// Get complete auth array		$sql = 'SELECT auth_option, auth_option_id			FROM ' . ACL_OPTIONS_TABLE . "			WHERE auth_option LIKE '" . $db->sql_escape($permission_type) . "%'";		$result = $db->sql_query($sql);		$auth_settings = array();		while ($row = $db->sql_fetchrow($result))		{			$auth_settings[$row['auth_option']] = ACL_NO;		}		$db->sql_freeresult($result);		// Get the role auth settings we need to re-set...		$sql = 'SELECT o.auth_option, r.auth_setting			FROM ' . ACL_ROLES_DATA_TABLE . ' r, ' . ACL_OPTIONS_TABLE . ' o			WHERE o.auth_option_id = r.auth_option_id				AND r.role_id = ' . $role_id;		$result = $db->sql_query($sql);		while ($row = $db->sql_fetchrow($result))		{			$auth_settings[$row['auth_option']] = $row['auth_setting'];		}		$db->sql_freeresult($result);		// Get role assignments		$hold_ary = $auth_admin->get_role_mask($role_id);		// Re-assign permissions		foreach ($hold_ary as $forum_id => $forum_ary)		{			if (isset($forum_ary['users']))			{				$auth_admin->acl_set('user', $forum_id, $forum_ary['users'], $auth_settings, 0, false);			}			if (isset($forum_ary['groups']))			{				$auth_admin->acl_set('group', $forum_id, $forum_ary['groups'], $auth_settings, 0, false);			}		}		// Remove role from users and groups just to be sure (happens through acl_set)		$sql = 'DELETE FROM ' . ACL_USERS_TABLE . '			WHERE auth_role_id = ' . $role_id;		$db->sql_query($sql);		$sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '			WHERE auth_role_id = ' . $role_id;		$db->sql_query($sql);		// Remove role data and role		$sql = 'DELETE FROM ' . ACL_ROLES_DATA_TABLE . '			WHERE role_id = ' . $role_id;		$db->sql_query($sql);		$sql = 'DELETE FROM ' . ACL_ROLES_TABLE . '			WHERE role_id = ' . $role_id;		$db->sql_query($sql);		$auth_admin->acl_clear_prefetch();	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -