<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<2016>")) {	//没有权限
		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">

<p align="center"><font size="5"><b>每月注册用户清单</b></font></p>
<hr color="#999966">

<p align="center">
<?php
		$strYear=$_REQUEST["year"];
		$strMonth=$_REQUEST["month"];
		$time1=strftime("%Y-%m-01 00:00:01");		//统计开始时间，本月开始
		$time2=strftime("%Y-%m-01 00:00:01",strtotime("+1 month",time()));		//统计结束时间，下一个月开始
		if ($strYear!="" && $strMonth!="") {
	    	$time1=$strYear;
	    	if (intval($strMonth)<10) {
	    		$time1=$time1."-0".$strMonth."-01 00:00:01";		//统计开始时间
			}
	    	else {
	    		$time1=$time1."-".$strMonth."-01 00:00:01";		//统计开始时间
	    	}
	    	$time2=$strYear;
	    	if (intval($strMonth)<10) {
	    		$time2=$time2."-0".$strMonth."-01 00:00:01";
			}
	    	else {
	    		$time2=$time2."-".$strMonth."-01 00:00:01";
	    	}
			$time2=strftime("%Y-%m-01 00:00:01",strtotime("+1 month",strtotime($time2)));		//统计结束时间，下一个月开始
		}
		$pagecount=20;		//每页显示多少条记录
		$str=$_REQUEST["pageno"];
		if ($str=="") {
			$str="1";
		}
		$page_no=intval($str);			//当前显示页号，因为可能需要多页显示
		$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
		mysql_select_db(get_cfg_var("SIPDB"),$db);
		$count=0;
		$allpage=0;
		$allmoney=0;
		$rs = mysql_query( "select count(userid) as allcount,sum(money2) as allmoney from addtimelist where addtime>='".$time1."' and addtime<='".$time2."' and flag='1'",$db );	//读取总数
		//计算总记录数，计算共有多少页。
		if ($row = mysql_fetch_array($rs)) {			//有记录
			$count=$row["allcount"];
		    if (is_null($count)) $count=0;
			$allmoney=$row["allmoney"];
		    if (is_null($allmoney)) $allmoney=0;
			$allmoney=round($allmoney,2);
		}
		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 {
				$rs = mysql_query( "select users.userid,users.loginname,users.username,types.name,users.createtime,addtimelist.length+addtimelist.datalength,addtimelist.otherlength,addtimelist.price,addtimelist.money1,addtimelist.discount,addtimelist.money2 from users,types,addtimelist where users.type=types.typeid and users.userid=addtimelist.userid and users.createtime>='".$time1."' and users.createtime<='".$time2."' and addtimelist.flag='1' order by users.createtime",$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><td align=center>序号</td><td align=center>用户ID</td><td align=center>用户名称</td><td align=center>用户类型</td><td align=center>注册时间</td><td align=center>购买数量</td><td align=center>赠送数量</td><td align=center>单价(元)</td><td align=center>应收(元)</td><td align=center>折扣(%)</td><td align=center>实收(元)</td></tr>");
						while ($row && $n<=$page_no*$pagecount) {		//显示当前页记录
							echo("<tr>");
							echo("<td>".strval($n)."</td>");
							echo("<td><a href=queryuser_content.php?userid=".$row[0].">".$row[1]."</a></td>");
						    echo("<td>".$row[2]."&nbsp;</td>");
							echo("<td>".$row[3]."</td>");
							echo("<td>".$row[4]."</td>");
							echo("<td>".strval($row[5])."</td>");
							echo("<td>".strval($row[6])."</td>");
							echo("<td>".strval($row[7])."</td>");
							echo("<td>".strval($row[8])."</td>");
							echo("<td>".strval($row[9])."</td>");
							echo("<td>".strval($row[10])."</td>");
							echo("</tr>");
							$row = mysql_fetch_array($rs);
							$n=$n+1;
						}
						echo("</table><br>");
						echo("<form method=GET action=querynew1_result.php><input type=hidden name=year value=".$strYear."><input type=hidden name=month value=".$strMonth.">");
						echo("共".strval($count)."人，实收".strval($allmoney)."元。第 ".strval($page_no)." 页，共 ".strval($allpage)." 页。");
						if ($page_no>1) {			//有前一页
							echo("<a href=querynew1_result.php?year=".$strYear."&month=".$strMonth."&pageno=".strval($page_no-1).">前一页</a>");
						}
						if ($page_no<$allpage) {	//有后一页
							echo(" <a href=querynew1_result.php?year=".$strYear."&month=".$strMonth."&pageno=".strval($page_no+1).">后一页</a>");
						}
						if ($allpage>2) {	//超过2页
							echo(" 到<input type=text size=3 name=pageno maxlength=3>页");
						}
						echo("</form>");
					}
					else {
						echo("页号已经超出记录范围!");
					}
				}
				else {
					echo("该月没有注册用户！");
				}
				mysql_free_result($rs);
			}
		}
		mysql_close($db);
?>
</p>

<p align="center">统计时间范围：从 <?php echo $time1; ?> 起，到 <?php echo $time2; ?> 止。</p>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
