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

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

$keyword=trim($keyword);
if($keyword){
	$wheres = " AND (host.Domain like '%$keyword%') ";
}
if($iStatus!=""){
	$wheres .= " AND host.iStatus='$iStatus' ";
}
if($UserName!=""){
	$wheres .= " AND host.UserName='$UserName'";
}
if($day != ""){
	 if($day<0)$wheres=" AND TO_DAYS(host.dtExpiry)-TO_DAYS(now())<=".abs($day)." AND TO_DAYS(host.dtExpiry)-TO_DAYS(now())>0";
	 elseif($day>0)$wheres=" AND TO_DAYS(now())-TO_DAYS(host.dtExpiry)>=".abs($day);
}
/*** 得到总记录数 *************/
$sql = "select count(*) from host 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 host.*,products.ProductName FROM host ".
	   "LEFT JOIN products ON products.IDProduct = host.fIDProd ".
	   "WHERE 1 $wheres ORDER BY IDHost 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">
<title>产品管理</title>
<LINK href="../share/style.css" rel=stylesheet>
<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" />
<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>
<!--子导航--><div class="page-container">
<? include "product_nav.inc.php"?>
<!--结束-->
<!--搜索-->
<div id="search">
<form method='post' action='<?=$_SERVER['PHP_SELF']?>'>
快速搜索:
<input type="text" name="keyword" class="input">
<input name="submit" type="submit" class="bt2" value="搜 索">
<input type="button" class="bt2" value="全部列出" onClick="location='host_list.php'">
</form>
</div>

<form action='' method='post'>
<div id="page">

</div>
      <?
		if($PNum){
	    ?>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0" class="table table-border table-bordered table-bg table-hover table-sort">

		<tr id="tr">
		
          <td>编号</td>
          <td class='white'>所属用户</td>
         
		
		  <td class='white'>产品类型</td>
          <td class='white'>状态</td>
		  <td class='white'>建立时间</td>
		
          <td class='white'>操作</td>
        </tr>
        <? while($HostI=$DB->fetch_array($result)){
		       $dkey = GetHashKey('host'.$HostI[IDHost]);
			   $ukey = GetHashKey('users'.$HostI[UserName]);	
	    ?>
        <tr id="td" onmouseover='inStyle(this)' onmouseout='outStyle(this)'>
     
		  <td><?=$HostI[IDHost]?></td>
	      <td><a href='../users/user_edit.php?UserName=<?=$HostI[UserName]?>&backUrl=<?=$backUrl?>&key=<?=$ukey?>'><?=$HostI[UserName]?></a></td>
		
	
		  <td><?=$HostI[ProductName]?></td>
		  <td>
			 <?
				
				  if($HostI[iStatus]==ProductStatus_Actived) echo "<font color='green'>已发货</font>";
				  elseif($HostI[iStatus]==ProductStatus_NotActived) echo"<font color=#999999>未生效</font>";
				  elseif($HostI[iStatus]==ProductStatus_Deleted) echo "<font color='#FF0000'>已删除</font>";
				  elseif($HostI[iStatus]==ProductStatus_Doing) echo "<font color='#FF0000'>已付款</font>"; 
				  	  elseif($HostI[iStatus]==ProductStatus_Stoped) echo "<font color='#FF0000'>已收货</font>"; 
			
		     ?>
		  </td>
          <td><?=$HostI[dtCreate]?></td>
		
          <td> 
          
			<a href="Product_op.php?ID=<?=$HostI[IDHost]?>&key=<?=$dkey?>&op=delete&backUrl=<?=urlencode($backUrl)?>" onClick="return confirm('确定删除吗?')">删除</a> |
			<a href="Product_edit.php?ID=<?=$HostI[IDHost]?>&key=<?=$dkey?>&backUrl=<?=$backUrl?>">详情</a> 
		  </td>
        </tr>
        <? }?>
      </table>
<div id="page">
	<?=$pageStr?>
</div>
<center>
<? if($pageList) echo "$pageList[0] <br> $pageList[1]";?>
</center>
		</form>
	  <?}else{
		   echo "<br><br>没有相关记录";
		}
	  ?>
<? 
$DB->close();
include "../share/bottom.php";
?>
</div>
</body>
</html>
