<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<2007>")) {	//没有权限
		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">
<p align="center">
<?php
	$loginname =trim($_REQUEST["loginname"]);
	$username = trim($_REQUEST["username"]);
	$comment = trim($_REQUEST["comment"]);
	$str=$_REQUEST["pageno"];
	if ($str=="") {
		$str="1";
	}
	$page_no=intval($str);			//当前显示页号，因为可能需要多页显示
	$sqla="";
	$sqlb="";
	if ($loginname!="") {
		$sqla="select count(userid) as allcount from users where loginname like '%".$loginname."%' and checked='n'";
		$sqlb="select userid,loginname,username,usertel,comment,createtime,types.name from users,types where users.type=types.typeid and loginname like '%".$loginname."%' and checked='n'";
	}
	elseif ($username!="") {
		$sqla="select count(userid) as allcount from users where username like '%".$username."%' and checked='n'";
		$sqlb="select userid,loginname,username,usertel,comment,createtime,types.name from users,types where users.type=types.typeid and username like '%".$username."%' and checked='n'";
	}
	elseif ($comment!="") {
		$sqla="select count(userid) as allcount from users where comment like '%".$comment."%' and checked='n'";
		$sqlb="select userid,loginname,username,usertel,comment,createtime,types.name from users,types where users.type=types.typeid and comment like '%".$comment."%' and checked='n'";
	}
	else {
		$sqla="select count(userid) as allcount from users where checked='n'";
		$sqlb="select userid,loginname,username,usertel,comment,createtime,types.name from users,types where users.type=types.typeid and checked='n'";
	}
	$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);
	$rs = mysql_query( $sqla,$db );
	//计算总记录数，计算共有多少页
	if ($row = mysql_fetch_array($rs)) {			//有记录
		$count=$row["allcount"];
	}
	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( $sqlb,$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 cellpadding=0 cellspacing=0 bordercolor=#008080>");
					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></tr>");
					while ($row && $n<=$page_no*$pagecount) {		//显示当前页记录
						echo("<tr>");
						echo("<td>".strval($n)."</td>");
						echo("<td><a href=queryuser_content.php?userid=".$row[0]." target=_blank>".$row[1]."</a></td>");
						echo("<td>".$row[2]."&nbsp;</td>");
						echo("<td>".$row[6]."</td>");
						echo("<td>".$row[3]."&nbsp;</td>");
						echo("<td>".$row[4]."&nbsp;</td>");
						echo("<td>".$row[5]."</td>");
						echo("</tr>");
						$row = mysql_fetch_array($rs);
						$n=$n+1;
					}
					echo("</table><br>");
					echo("<form method=GET action=queryuser2.php><input type=hidden name=loginname value=".$loginname."><input type=hidden name=username value=".$username."><input type=hidden name=comment value=".$comment.">");
					echo("第 ".strval($page_no)." 页，共 ".strval($allpage)." 页。");
					if ($page_no>1) {			//有前一页
						echo("<a href=queryuser2.php?loginname=".$loginname."&username=".$username."&comment=".$comment."&pageno=".strval($page_no-1).">前一页</a>");
					}
					if ($page_no<$allpage) {	//有后一页
						echo(" <a href=queryuser2.php?loginname=".$loginname."&username=".$username."&comment=".$comment."&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>
<hr>
<p align="center">SIP宽带上网计费管理系统</p>
<p align="center">作者：<b>深圳市飞沃软件有限公司</b></p>
</body>

</html>
