<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
	$r=$r['member']['roleid']; 
	if(!in_array($_roleid,$r) && $_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.'memberhonor',array('honorname'=>$honorname[$val],'point'=>$point[$val],'ico'=>$ico[$val]),'id='.intval($val));
				}
				$c->cache_memberhonor();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=memberhonor&action=manage');
			}
			$result=$db->fetch_all("SELECT * FROM ".DB_PRE."memberhonor ORDER BY ".DB_PRE."memberhonor.point ASC,id DESC");
			include admin_tlp('memberhonor_manage');			
			break;
		case 'add':
			if(isset($do_submit)) 
			{
				if(!$newmemberhonor['honorname'])showmsg('会员头衔名称不能为空!',ADMIN_FILE.'?file=memberhonor&action=add');
				$db->insert(DB_PRE.'memberhonor',$newmemberhonor,true);
				$c->cache_memberhonor();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=memberhonor&action=manage');
			}
			include admin_tlp('memberhonor_add');
			break;
		case 'disable':
			$isdisabled=intval($isdisabled);
			if($db->query("UPDATE `".DB_PRE."memberhonor` SET `".DB_PRE."memberhonor`.status={$isdisabled} WHERE `".DB_PRE."memberhonor`.`id`=".intval($id),true))
			{
				$c->cache_memberhonor();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=memberhonor&action=manage');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR'],ADMIN_FILE.'?file=memberhonor&action=manage');
			}
			break;
		case 'delete':
			$db->query("DELETE FROM `".DB_PRE."memberhonor` WHERE `".DB_PRE."memberhonor`.`id`=".intval($id),true);
			cache_delete('memberhonor'.$id.'.cache.php',DIRCMS_ROOT.'data/cache/');
			$c->cache_memberhonor();
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=memberhonor&action=manage');
			break;
	}
?>