<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<2029>")) {	//没有权限
		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
		$gp_id=$_REQUEST["gpid"];
		$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";		//统计结束时间
	    	}
		}
		$str=$_REQUEST["pageno"];
		if ($str=="") {
			$str="1";
		}
		$page_no=intval($str);			//当前显示页号，因为可能需要多页显示
		$pagecount=20;		//每页显示多少条记录
		$count=0;
		$allpage=0;
        $db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
        mysql_select_db(get_cfg_var("SIPDB"),$db);
        $sqlstr="select count(gpid) from gpaddtimelist";        //生成SQL语句
        if ($gp_id!="") {
           $sqlstr=$sqlstr." where gpid=".$gp_id;
        }
        if (strpos($sqlstr,"where")>0) {
	       $sqlstr=$sqlstr." and addtime>'".$time1."' and addtime<'".$time2."'";
		}
	    else {
	       $sqlstr=$sqlstr." where addtime>'".$time1."' and addtime<'".$time2."'";
	    }
		$rs = mysql_query( $sqlstr,$db );
		//计算总记录数，计算共有多少页
		if ($row = mysql_fetch_array($rs)) {			//有记录
			$count=$row[0];
		}
		mysql_free_result($rs);
		if ($count<1) {
           echo("<p align='center'>没有组续费记录</p>");
		}
		else {
			$allpage=(int)($count/$pagecount);
			if ($allpage*$pagecount<$count) {		//不是整除
				$allpage=$allpage+1;
			}
			if ($page_no>$allpage) {
				echo("页号超出记录范围!");
			}
			else {
				$sqlstr="select * from gpaddtimelist";        //生成SQL语句
				if ($gp_id!="") {
				   $sqlstr=$sqlstr." where gpid=".$gp_id;
				}
				if (strpos($sqlstr,"where")>0) {
				   $sqlstr=$sqlstr." and addtime>'".$time1."' and addtime<'".$time2."'";
				}
				else {
				   $sqlstr=$sqlstr." where addtime>'".$time1."' and addtime<'".$time2."'";
				}
				$sqlstr=$sqlstr." order by gpid,addtime";
				$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'>赠送数量</td>");
						 echo("    <td align='center'>应收金额(元)</td>");
						 echo("    <td align='center'>折扣(%)</td>");
						 echo("    <td align='center'>实收金额(元)</td>");
						 echo("</tr>"); 
						 while ($row && $n<=$page_no*$pagecount) {		//显示当前页记录
							//输出
							$rs1=mysql_query("select gpname from groups where gpid=".strval($row[0]),$db);
							if ( ($row1 = mysql_fetch_array($rs1))==FALSE ) {
							   $gpname="&nbsp;";
							}
							else {
							  $gpname=$row1["gpname"];
							}
							mysql_free_result($rs1);
							echo("<td  width='40' align='center'>".strval($n)."</td>");          //序号
							echo("<td  align='center'>".$gpname."</td>");                                        //组名        
							echo("<td  align='center'>".strval($row[4])."</td>");                      //续费人数
							echo("<td  align='center'>".$row[1]."</td>");                            //续费时间
							echo("<td  align='center'>".strval($row[2])."</td>");                      //续费数量
							echo("<td  align='center'>".strval($row[3])."</td>");                      //赠送数量
							echo("<td  align='center'>".strval($row[5])."</td>");                      //应收金额
							echo("<td  align='center'>".strval($row[6])."</td>");                      //折扣
							echo("<td  align='center'>".strval($row[7])."</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='querygpaddtime_result.php?pageno=".strval($page_no-1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."&gpid=".$gp_id."'>前一页</a>");
						  }
						  if ($page_no<$allpage) {	//有后一页
							 echo("&nbsp<a href='querygpaddtime_result.php?pageno=".strval($page_no+1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."&gpid=".$gp_id."'>后一页</a>");
						  }
					}
					else {
						echo("页号已经超出记录范围!");
					}
				}
				else {
		           echo("<p align='center'>没有组续费记录</p>");
				}
				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>
