<?php
	!defined('DIRCMS_MANAGE') && exit('Access Denied!');
	$r=cache_read('module.cache.php',DIRCMS_ROOT.'data/cache_module/');
	$r=$r['system']['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)) 
			{
				if(!$id)showmsg('请选择需要操作的类别!');
				foreach($id as $val)
				{
					switch($do)
					{
						case 'delete':
							$db->mysql_delete(DB_PRE.'type',intval($val));
							cache_delete('type'.$val.'.cache.php',DIRCMS_ROOT.'data/cache/');
							break;
						case 'lock':
							$db->update(DB_PRE.'type',array('islocked'=>1,'name'=>$name[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
							break;
						case 'unlock':
							$db->update(DB_PRE.'type',array('islocked'=>0,'name'=>$name[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
							break;
						default:
							$db->update(DB_PRE.'type',array('name'=>$name[$val],'orderby'=>$orderby[$val]),'id='.intval($val));
							break;
					}
				}
				$c->cache_model();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=type&action=manage');
			}
			$result=$db->fetch_all("SELECT * FROM ".DB_PRE."type ORDER BY ".DB_PRE."type.orderby ASC,id DESC");
			include admin_tlp('type_manage');			
			break;
		case 'add':
			if(isset($do_submit)) 
			{
				if(!$type['name'])showmsg('类别名称不能为空!');
				$db->insert(DB_PRE.'type',$type,true);
				$c->cache_model();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=type&action=manage');
			}
			include admin_tlp('type_add');
			break;
		case 'lock':
			if($db->query("UPDATE ".DB_PRE."type SET ".DB_PRE."type.islocked=".intval($islocked)." WHERE ".DB_PRE."type.id=".intval($id),true))
			{
				$c->cache_model();
				showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=type&action=manage');
			}
			else 
			{
				showmsg($LANG['MANAGE_ERROR'],ADMIN_FILE.'?file=type&action=manage');
			}
			break;
		case 'delete':
			$db->mysql_delete(DB_PRE.'type',intval($id));
			$c->cache_model();
			cache_delete('type'.$id.'.cache.php',DIRCMS_ROOT.'data/cache/');
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=type&action=manage');
			break;
	}
?>
