<?php
	$acl=$_SESSION["acl"];
	if (strlen($acl)<1 || !strpos($acl,"<0014>")) {	//没有权限
		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">
<?php
		$operator=$_REQUEST["operator"];
?>
<p align="center">操作员：<?php echo $operator; ?></p>
<p align="center">
<?php
		$strYear1=$_REQUEST["year1"];
		$strMonth1=$_REQUEST["month1"];
		$strDay1=$_REQUEST["day1"];
		$strYear2=$_REQUEST["year2"];
		$strMonth2=$_REQUEST["month2"];
		$strDay2=$_REQUEST["day2"];
		$time1="";
		$time2="";
		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";				//统计起始时间
		}
	    else {
	       $time1="2006-01-01 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";				//统计结束时间
		}
	    else {
			$time2=strftime("%Y-%m-%d %H:%M:%S");		//当前时间
   	    }
		$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);
		$rs = mysql_query("select count(operator) as allcount from operation where operator='".$operator."' and opertime>='".$time1."' and opertime<'".$time2."'",$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("select opertime,action from operation where operator='".$operator."' and opertime>='".$time1."' and opertime<'".$time2."'",$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='#808080' cellspacing='0' cellpadding='0'>");
							echo("<tr><td>序号</td><td>操作时间</td><td>操作内容</td></tr>");
							 while ( $row && $n<=$page_no*$pagecount ) {		//显示当前页记录
								echo("<tr>");
								echo("<td>".strval($n)."</td>");
								echo("<td>".$row["opertime"]."</td>");
								echo("<td>".$row["action"]."</td>");
								echo("</tr>");
								$row = mysql_fetch_array($rs);
								$n=$n+1;
							 }
							 echo("</table><br>");
							 echo("<form method=GET action=listaction.php><input type=hidden name=year1 value=".$strYear1."><input type=hidden name=year2 value=".$strYear2."><input type=hidden name=month1 value=".$strMonth1."><input type=hidden name=month2 value=".$strMonth2."><input type=hidden name=day1 value=".$strDay1."><input type=hidden name=day2 value=".$strDay2."><input type=hidden name=operator value=".$operator.">");
							 echo("第 ".strval($page_no)." 页，共 ".strval($allpage)." 页。");
							 if ($page_no>1) {			//有前一页
								echo("<a href='listaction.php?pageno=".strval($page_no-1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."&operator=".$operator."'>前一页</a>");
							 }
							 if ($page_no<$allpage) {	//有后一页
								echo("&nbsp;<a href='listaction.php?pageno=".strval($page_no+1)."&year1=".$strYear1."&year2=".$strYear2."&month1=".$strMonth1."&month2=".$strMonth2."&day1=".$strDay1."&day2=".$strDay2."&operator=".$operator."'>后一页</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>
