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

<div align="center">
<table border=1 cellspacing="0" cellpadding="0" bordercolor="#008080">
<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></tr>
<?php
    $tmptime=strtotime("+1 month",time());		//计算下一个月的当日
	$timestr=strftime("%Y-%m-01 00:00:01",$tmptime);		//统计开始时间
	$tmptime=strtotime($timestr);	//下一个月的开始为止
    
	$db=mysql_pconnect(get_cfg_var("SIPSERVER"),get_cfg_var("SIPUSER"),get_cfg_var("SIPPWD"));
	mysql_select_db(get_cfg_var("SIPDB"),$db);
	$n=0;
	$rs=mysql_query( "select users.userid,users.loginname,users.type,users.username,users.usertel,usertime.starttime,usertime.length,types.name,types.unit from users,usertime,types where users.userid=usertime.userid and users.type=types.typeid and users.checked='n' and types.typemode='1' and (types.unit=3 or types.unit=4 or types.unit=5)",$db );
	if ($row = mysql_fetch_array($rs)) {
		while ($row) {
			$userid=$row[0];
			$loginname=$row[1];
			$usertype=$row[2];
			$username=$row[3];
			$usertel=$row[4];
			$starttime=$row[5];
			$timelength=$row[6];
			$usertypename=$row[7];
			$typeunit=$row[8];
			$unit1="";
			$bTimeout=FALSE;
			if ($typeunit==3) {
				if (strtotime("+".$timelength." day",strtotime($starttime))<=$tmptime) {
					$bTimeout=TRUE;
					$unit1="天";
				}
			}
			else {
				if (strtotime("+".$timelength." month",strtotime($starttime))<=$tmptime) {
					$bTimeout=TRUE;
					$unit1="月";
				}
			}
			if ($bTimeout) {
				echo("<tr>");
				echo("<td align=center>".strval($n)."</td>");
				echo("<td align=center><a href=queryuser_content.php?userid=".$userid.">".$loginname."</a></td>");
				echo("<td align=center>".$username."&nbsp;</td>");
				echo("<td align=center>".$usertypename."</td>");
				echo("<td align=center>".$usertel."&nbsp;</td>");
				echo("<td align=center>".$starttime."</td>");
				echo("<td align=center>".strval($timelength).$unit1."</td>");
				echo("</tr>");
				$n=$n+1;
			}
			$row = mysql_fetch_array($rs);
		}
	}
	mysql_free_result($rs);
	mysql_close($db);
?>

</table>
</div>

<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>

</body>

</html>
