<?php
session_start();
require_once "../init.php";
require_once "../authority.inc.php";

$iStatus = $_GET['iStatus'];
$day = $_GET['day'];
$keyword = $_POST['keyword'];
$backUrl = GetUrl();

$keyword=trim($keyword);
if($keyword){
	$wheres = " AND (order.About like '%$keyword%') ";
}
if($iStatus!=""){
	$wheres .= " AND order.iStatus='$iStatus'";
}
if($UserName!=""){
	$wheres .= " AND order.UserName='$UserName'";
}
if($day != ""){
	 if($day<0)$wheres=" AND TO_DAYS(order.dtExpiry)-TO_DAYS(now())<=".abs($day)." AND TO_DAYS(order.dtExpiry)-TO_DAYS(now())>0";
	 elseif($day>0)$wheres=" AND TO_DAYS(now())-TO_DAYS(order.dtExpiry)>=".abs($day);
}
/*** 得到总记录数 *************/
$sql = "select count(*) from `order` where 1 $wheres";
$rs  = $DB->query($sql);
$pageSize = 30;
$totalRecord = $DB->result($rs,0,0);
$totalPage   = ceil($totalRecord/$pageSize);
if(!$page)$page = 1;
$offset = ($page-1)*$pageSize;
/*** 查询 *************/
$sql = "SELECT * FROM `order` WHERE 1 $wheres ORDER BY OrderID DESC LIMIT $offset,$pageSize";
$result = $DB->query($sql);
$pageList = GetPageList($_SERVER[PHP_SELF],"page","15",$totalPage,$page);
$PNum = $DB->num_rows($result);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/admin/lib/html5.js"></script>
<script type="text/javascript" src="/admin/lib/respond.min.js"></script>
<script type="text/javascript" src="/admin/lib/PIE_IE678.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.7/iconfont.css" />
<link rel="stylesheet" type="text/css" href="/admin/lib/icheck/icheck.css" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />


<!--[if IE 6]>
<script type="text/javascript" src="/admin/static/h-ui.admin/js/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>定单管理</title>
<LINK href="../share/style.css" rel=stylesheet>
<script src='../share/global.js'></script>
</head>
<body>
<? include "../share/top.php"?>
<div id="topLink">
<div id="topInfo">
	<span class="tTitle">定单管理</span>
	<span class="sarr"> >> </span><a href="<?=$GLOBALS["parentpath"]?>">返回到管理首页</a>
</div>
</div>
<!--子导航-->
<? include "order_nav.inc.php"?>
<!--结束-->
<div class="page-container">

<!--搜索-->


<form method='post' action='<?=$_SERVER['PHP_SELF']?>'>

<div class="text-c"> 日期范围：
		<input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
		-
		<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
		<input type="text" name="keyword"  onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" class="input-text" style="width:250px" placeholder="输入定单" id="" name="">
		<button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜定单</button>
	</div>
</form>


<form action='' method='post'>
<div id="page">
<?
	$pageStr='';
	$pageStr.="共 $totalRecord 条记录,共 $totalPage 页,当前第 $page 页";
	echo $pageStr;
?>
</div>

      <table border="0" cellspacing="0" cellpadding="0" id="table" class="table table-border table-bordered table-hover table-bg table-sort">
		<tr id="tr">
	
          <td>订单编号</td>
          <td>所属用户</td>
		   <td>订单金额</td>
          <td>订单说明</td>
          <td>状态</td>
		  <td>建立时间</td>
		
          <td>操作</td>
        </tr>

		<?
	if($PNum){
?>
        <? while($OrderI=$DB->fetch_array($result)){
		       $dkey = GetHashKey('order'.$OrderI[OrderID]);
			   $ukey = GetHashKey('users'.$OrderI[UserName]);	
	    ?>
        <tr id="td" onmouseover='inStyle(this)' onmouseout='outStyle(this)'>
		
          <td><?=$OrderI[OrderID]?></td>
	      <td><a href='../users/user_edit.php?UserName=<?=$OrderI[UserName]?>&backUrl=<?=$backUrl?>&key=<?=$ukey?>'><?=$OrderI[UserName]?></a></td>
		  <td><?=$OrderI['Amount']?></td>
		  <td><?=$OrderI['About']?></td>
		  <td>
			 <?
				
					if($OrderI[iStatus]==2) echo "<font color='green'>已发货</font>";
					elseif($OrderI[iStatus]==0) echo "未生效";
					elseif($OrderI[iStatus]==1) echo "<font color='blue'>已付款</font>";
					elseif($OrderI[iStatus]==-1) echo "<font color='#FF0000'>已删除</font>";
					elseif($OrderI[iStatus]==3) echo "<font color='red'>已收货</font>";
					if($OrderI[iDoing]==1) echo ",<font color=blue>发货中</font>";
				
		     ?>
		  </td>
          <td><?=$OrderI[dtCreate]?></td>
		
          <td> 
			<?if($OrderI[iStatus]==0){?>
			<a href="order_op.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&op=pay&backUrl=<?=urlencode($backUrl)?>">交费生效</a> | 
			<a href="order_op.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&op=delete&backUrl=<?=urlencode($backUrl)?>" onclick="return confirm('确定删除吗?')">删除</a> |
			<?}?>
			<?if($OrderI[iStatus]==1){?>
				<? if(!$OrderI[iDoing]){?>
				<a href="order_op.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&op=doit&backUrl=<?=urlencode($backUrl)?>">生效</a> | 
				<? }?>
			<a href="order_op.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&op=refund&backUrl=<?=urlencode($backUrl)?>">退款</a> | 
				<? if($OrderI[iDoing]==1){?>
				<a href="order_op.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&op=redo&backUrl=<?=urlencode($backUrl)?>">重复提交</a> | 
				<? }?>
			<?}?>
			<a href="order_edit.php?OrderID=<?=$OrderI[OrderID]?>&key=<?=$dkey?>&backUrl=<?=$backUrl?>">详情</a> 
		  </td>
        </tr>
        <? }?>
		</form>
      </table>
<div id="page">

</div>
<center>
<?
 if($pageList) echo "$pageList[0] <br> $pageList[1]";
?>
<?}else{
   echo "<center><br><br>没有相关记录<br><br></center>";

}
?>
<br></div>
<? 
$DB->close();
include "../share/bottom.php";
?>
</body>
</html>
