<?php 
session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	
	$ls=$_GET['ls'];
	if(isset($_POST['logSpace'])){	$logSpace=$_POST['logSpace'];}

	$ls_msg="日志管理";
	
	
	
	
	switch ($ls)
	{
		case "maxSpace":
			if($logSpace>$maxLogSpace){$logSpace=$maxLogSpace;}
			writeconstant("logSpace",$logSpace,"");
			writelog($_SERVER['PHP_SELF'],"change log space",$logSpace);
			$ls_msg="修改日志空间成功！";
			break;

	}
	
	$log_sql="select * from ls_log order by currentDateTime desc";
	$log_query=$opendb->query($log_sql);
	$log_num=mysql_num_rows($log_query);	
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>日志管理</title>
	</head>

	<body>
		<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>日志管理</strong></font></div>
			  </td>
			</tr>
			
			<tr>
				<td height="213" valign="top" bgcolor="#dee7ff"><br>
			   <?php 
					 if( isset($_GET['page']) ){
	   $page = intval( $_GET['page'] );
	}
	else{
	   $page = 1;
	}
	// 每页数量
	$PageSize = $logPage;
	
	// 获取总数据量
	/********************************************************************************/
	$sql="select * from ls_log order by currentDateTime desc";
	$result=$opendb->query($sql);
	
	/********************************************************************************/
	// 获取总数据量
	
	$row = mysql_num_rows($result);
	$amount = $row;
	
	// 记算总共有多少页
	if( $amount ){
	   if( $amount < $PageSize ){ $page_count = 1; }			   //如果总数据量小于$PageSize，那么只有一页
	   if( $amount % $PageSize ){								  //取总数据量除以每页数的余数
		   $page_count = (int)($amount / $PageSize) + 1;		   //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
	   }else{
		   $page_count = $amount / $PageSize;					  //如果没有余数，则页数等于总数据量除以每页数的结果
	   }
	}
	else{
	   $page_count = 0;
	}
	
	// 翻页链接
	$page_string = '';
	$pagecatestr="";
	if( $page == 1 ){
	   $page_string .= '首页 | 上一页 |';
	}
	else{
	   $page_string .= '<a href=?&page=1&'.$pagecatestr.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?&page='.($page-1)."&".$pagecatestr.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
	}
	if( ($page == $page_count) || ($page_count == 0) ){
	   $page_string .= ' 下一页 | 尾页';
	}
	else{
	   $page_string .= ' <a href=?&page='.($page+1).'&'.$pagecatestr.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?&page='.$page_count.'&'.$pagecatestr.'><u><font color=\"#0000FF\">尾页</font></u></a>';
	}
		 $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
		 $page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个日志每页";
	
	
 
?>
					<table border="0" width="97%" align="center">
				  <tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right">共 <b><?=$row?></b> 条</td>
					  </tr>
					</table>

					
				 <table width="97%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
					 <tr bgcolor="#B9DAFF"> 
						<td align="center" width="39" height="28">序号</td>
						<td align="center" width="179" height="28">调用页面</td>
						<td align="center" width="103">功能</td>
						<td width="81" align="center" >参数</td>
						<td width="94" align="center" >访问者IP</td>
						<td width="51" align="center" >日期</td>
						<td align="center" width="41">备注</td>
					  </tr>
<?	
		//查询数据
	$log_sql="select * from ls_log order by currentDateTime desc  limit ". ($page-1)*$PageSize .",".$PageSize." ";	
	
	//echo $b2b_sql."<br>";
	$log_query=$opendb->query($log_sql);
				 
					 $i=1;
					  while ($log_rows=mysql_fetch_assoc($log_query))
					  {
						echo "<tbody id='ZH_".$log_rows['ID']."' >";	
						echo "<tr bgcolor='#f4f4f4'";
						echo "onMouseOver=";
						echo " 	this.style.backgroundColor='#CCFFCC' ";
						echo "onMouseOut=";
						echo " 	this.style.backgroundColor='#f4f4f4' ";
						echo ">";	
						echo "	<td align='left' style='padding-left:10px;' height='25' >";
					  	echo 		$log_rows['ID'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25' >";
					  	echo 		$log_rows['currentProgram'];
						echo "	</td>";
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'>";
					  	echo 		$log_rows['currentFunction'];
						echo "	</td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'> ";
					  	echo 		$log_rows['parameter'];
						echo "  </td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'> ";
					  	echo 		$log_rows['ip'];
						echo "  </td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'> ";
					  	echo 		$log_rows['currentDateTime'];
						echo "  </td>";
						echo "	<td align='left' style='padding-left:20px;' height='25'> ";
					  	echo 		$log_rows['memo'];
						echo "  </td>";

						echo "</tr>";
						echo "</tbody>";
						

						$i++;
					  }
					  
					 ?> 
					 <tr>
					 <td colspan="7">				   	   </td>
					 </tr>
				  </table>
				  <table border="0" width="97%" align="center">
				  <tr>
							<td align="right"><? echo $page_string; ?> </td>
					  </tr>
					</table>
					
					<form name="fmaddmenu" action="?ls=maxSpace" method="post">
					 <table width="97%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
					 
						 <tr bgcolor="#B9DAFF"> 
						   <td width="33%" height="28" style='padding-left:20px;'>
							 <div align="right"></div></td>
					   </tr>
					  </table>
				  </form>
					
					
				</td>
			</tr>
		</table>
	</body>
</html>