<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<2028>")) {	//没有权限
		ob_clean();
		header("Location: accesserror.html");
		exit;
	}
?>


<html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>批次信息</title>
</head>

<body background="bkg.bmp">
<center>
<p align="center"><font size="5"><b>批次信息</b></font></p>
<hr color="#999966">
<?php
		$strYear1=$_REQUEST["year1"];
		$strMonth1=$_REQUEST["month1"];
		$strDay1=$_REQUEST["day1"];
		$strYear2=$_REQUEST["year2"];
		$strMonth2=$_REQUEST["month2"];
		$strDay2=$_REQUEST["day2"];
		$time1="2004-01-01 00:00:01";		//统计开始时间
		$time2=strftime("%Y-%m-%d 23:59:59");		//统计结束时间
		if ($strYear1!="" && $strMonth1!="" && $strDay1!="") {
	    	$time1=$strYear1;
	    	if (intval($strMonth1)<10) {
	    		$time1=$time1."-0".$strMonth1;
			}
	    	else {
	    		$time1=$time1."-".$strMonth1;
	    	}
	    	if (intval($strDay1)<10) {
	    		$time1=$time1."-0".$strDay1." 00:00:01";		//统计开始时间
			}
	    	else {
	    		$time1=$time1."-".$strDay1." 00:00:01";		//统计开始时间
	    	}
		}
		if ($strYear2!="" && $strMonth2!="" && $strDay2!="") {
	    	$time2=$strYear2;
	    	if (intval($strMonth2)<10) {
	    		$time2=$time2."-0".$strMonth2;
			}
	    	else {
	    		$time2=$time2."-".$strMonth2;
	    	}
	    	if (intval($strDay2)<10) {
	    		$time2=$time2."-0".$strDay2." 23:59:59";		//统计结束时间
			}
	    	else {
	    		$time2=$time2."-".$strDay2." 23:59:59";		//统计结束时间
	    	}
		}
	    $db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
        mysql_select_db(get_cfg_var("SIPDB"),$db);
		$str=$_REQUEST["pageno"];
		if ($str=="") {
			$str="1";
		}
		$page_no=intval($str);			//当前显示页号，因为可能需要多页显示
		$pagecount=20;		//每页显示多少条记录
		$count=0;
		$allpage=0;
        $sqlstr="select count(b.batchid) from batchs b,types t where t.typeid=b.type"; 
	    $sqlstr=$sqlstr." and b.createtime>='".$time1."'";
	    $sqlstr=$sqlstr." and  b.createtime<'".$time2."'";
		$rs = mysql_query( $sqlstr,$db );
		//计算总记录数，计算共有多少页
		if ($row = mysql_fetch_array($rs)) {			//有记录
			$count=$row[0];
		}
		mysql_free_result($rs);
		if ($count<1) {
			echo("查询范围内没有批次记录!");
		}
		else {
			$allpage=(int)($count/$pagecount);
			if ($allpage*$pagecount<$count) {		//不是整除
				$allpage=$allpage+1;
			}
			if ($page_no>$allpage) {
				echo("页号超出记录范围!");
			}
			else {
				$sqlstr="select b.startuserid,b.batchid,b.createtime,b.count,b.active,b.gpid,b.comment,t.name from batchs b,types t where t.typeid=b.type"; 
				$sqlstr=$sqlstr." and b.createtime>='".$time1."'";
				$sqlstr=$sqlstr." and  b.createtime<'".$time2."'";
				$sqlstr=$sqlstr." order by b.batchid";
				$rs = mysql_query( $sqlstr,$db );
				if ($row = mysql_fetch_array($rs)) {			//有记录
					$n=1;
					while ( $row && $n<=($page_no-1)*$pagecount ) {		//移动行号直到当前页对应起始行号位置
						$row = mysql_fetch_array($rs);
						$n=$n+1;
					}
					if ($row) {
						 echo("<table border='1' bordercolor='#008080' cellspacing='0' cellpadding='0'>");
						 echo("<tr>");
						 echo("    <td align='center'>序号</td>");
						 echo("    <td align='center'>详细信息</td>");
						 echo("    <td align='center'>生成时激活</td>");
						 echo("    <td align='center'>批号</td>"); 
						 echo("    <td align='center'>生成时间</td>");
						 echo("    <td align='center'>起始用户ID</td>"); 
						 echo("    <td align='center'>用户类型</td>"); 
						 echo("    <td align='center'>用户数量</td>");
						 echo("    <td align='center'>备注</td>");
						 echo("</tr>"); 
						 while ($row && $n<=$page_no*$pagecount) {		//显示当前页记录
							echo("<td  width='40' align='center'>".strval($n)."</td>");          //序号
							echo("<td  align='center'><a href='querybatch1_result.php?batchid=".strval($row[1])."' target='_blank'>点击查看</a></td>"); 
							echo("<td  width='65' align='center'>");                                            //是否在注册时激活
							if ($row[4]=="y") {
							   echo("是</td>");
							}
							else {
							   echo("否</td>");  
							}
							echo("<td  align='center'>".strval($row[1])."</td>");     //批号 
							echo("<td  align='center'>".$row[2]."</td>");                //注册时间
							echo("<td  align='center'>".$row[0]."</td>");                //起始ID
							echo("<td  align='center'>".$row[7]."</td>");                //用户类型
							echo("<td  align='center'>".strval($row[3])."</td>");           //用户数量
							echo("<td  align='center'>".$row[6]."&nbsp;</td>");          //备注
							echo("</tr>");
							$row = mysql_fetch_array($rs);
							$n=$n+1;
						 }
						 echo("</table>");
						  echo("第 ".strval($page_no)." 页，共 ".strval($allpage)." 页。");
						  if ($page_no>1) {			//有前一页
							 echo("<a href='querybatch_result.php?pageno=".strval($page_no-1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."'>前一页</a>");
						  }
						  if ($page_no<$allpage) {	//有后一页
							 echo("&nbsp<a href='querybatch_result.php?pageno=".strval($page_no+1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."'>后一页</a>");
						  }
					}
					else {
						echo("页号已经超出记录范围!");
					}
				}
				else {
					echo("查询范围内没有批次记录!");
				}
				mysql_free_result($rs);
			}
		}
        mysql_close($db);				
?>
<p align="center">统计时间范围：从 <?php echo $time1; ?> 起，到 <?php echo $time2; ?> 止。</p>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>
</center>
</body>

</html>
