<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
	if($_roleid!=1 && $_userid!=ADMIN_FOUNDERS)showmsg_nourl('您没有该操作的权限!');
	$action=empty($action)?'manage':trim($action);

	$c=new cache();
	switch($action)
	{
		case 'manage':
			if(isset($do_submit)) 
			{
				foreach($id as $val)
				{
					$db->update(DB_PRE.'role',array('name'=>$name[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
				}
				$c->cache_role();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=role&action=manage');
			}
			$result=$db->fetch_all("SELECT * FROM ".DB_PRE."role ORDER BY ".DB_PRE."role.orderby ASC,id DESC");
			include admin_tlp('role_manage');			
			break;
		case 'add':
			if(isset($do_submit)) 
			{
				if(!$newrole['name'])showmsg('角色名称不能为空!',ADMIN_FILE.'?file=role&action=manage');
				$db->insert(DB_PRE.'role',$newrole,true);
				$c->cache_role();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=role&action=manage');
			}
			include admin_tlp('role_add');			
			break;
		case 'lock':
			if($db->query("UPDATE ".DB_PRE."role SET ".DB_PRE."role.disabled=".intval($disabled)." WHERE ".DB_PRE."role.id=".intval($id),true))
			{
				$c->cache_role();
				if(!intval($disabled))cache_delete('role'.intval($id).'.cache.php',DIRCMS_ROOT.'data/cache/');
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=role&action=manage');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR'],ADMIN_FILE.'?file=role&action=manage');
			}
			break;
		case 'delete':
			$db->mysql_delete(DB_PRE.'role',intval($id));
			$c->cache_role();
			cache_delete('role'.intval($id).'.cache.php',DIRCMS_ROOT.'data/cache/');
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=role&action=manage');
			break;
	}
?>
