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

	require_once(DIRCMS_ROOT.'include/list.class.php');
	$l=new dircmslist();
	switch($action)
	{
		case 'manage':
			$where=1;
			$where=isset($status)?$where." AND status=".intval($status):$where;
			$k=trim(preg_replace('/[!@#\$%\^&\*\(\):\'\"\{\}\[\]\.\?\,\/`\;]+/i','',$k));
			$where=!empty($k)?$where." AND orderid like '%".$k."%'":$where;
			$orderby="id DESC";
			$page=max(isset($page)?intval($page):1,1);
			$result=$l->getlist(DB_PRE.'order',$where,$orderby,$page,15);
			$pages=$l->pages;
			include admin_tlp('order_manage');
			break;
		case 'delete':
			if(!$id)showmsg('请选择需要删除的订单!');
			$id=!is_array($id)?array($id):$id;
			$db->mysql_delete(DB_PRE.'order',array_map('intval',$id));
			showmsg($LANG['MANAGE_SUCEESS'],ADMIN_FILE.'?file=order&action=manage');
			break;
		case 'cancel':
			$r=$db->fetch_one("SELECT * FROM `".DB_PRE."order` WHERE `".DB_PRE."order`.`id`=".intval($id));
			if(!$r)showmsg('错误的请求!');
			if($r['status']==0)
			$db->update(DB_PRE.'order',array('status'=>4),'id='.intval($r['id']));
			showmsg('订单取消成功!',ADMIN_FILE.'?file=order&action=manage');
			break;
		case 'deliver':
			$r=$db->fetch_one("SELECT * FROM `".DB_PRE."order` WHERE `".DB_PRE."order`.`id`=".intval($id));
			if(!$r)showmsg('错误的请求!');
			if($r['status']==1)
			{
				$db->update(DB_PRE.'order',array('status'=>2),'id='.intval($r['id']));
				showmsg('操作成功!',ADMIN_FILE.'?file=order&action=manage');
			}
			else
			{
				showmsg('订单已关闭或者尚未付款, 无法发货!');
			}
			break;
		case 'view':
			$val=$db->fetch_one("SELECT * FROM `".DB_PRE."order` WHERE `".DB_PRE."order`.`id`=".intval($id));
			include admin_tlp('order_view');
			unset($val);
			break;
	}
?>