<?php
require("../../class/connect.php");
include("../../class/db_sql.php");
include("../../class/config.php");
include("../../class/functions.php");
include "../".LoadLang("pub/fun.php");
$link=db_connect();
$empire=new mysqlquery();
$logininid=getcvar('loginuserid');
$loginin=getcvar('loginusername');
$loginrnd=getcvar('loginrnd');
$loginlevel=getcvar('loginlevel');
$editor=1;
is_login($logininid,$loginin,$loginrnd);
//验证权限
CheckLevel($logininid,$loginin,$classid,"log");

//删除日志
function DelLog($loginid,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"log");
	$loginid=(int)$loginid;
	if(!$loginid)
	{printerror("NotDelLogid","history.go(-1)");}
	$sql=$empire->query("delete from {$dbtbpre}enewslog where loginid='$loginid'");
	if($sql)
	{
		//操作日志
		insert_dolog("loginid=".$loginid);
		printerror("DelLogSuccess","ListLog.php");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//批量删除日志
function DelLog_all($loginid,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"log");
	$count=count($loginid);
	if(!$count)
	{printerror("NotDelLogid","history.go(-1)");}
	for($i=0;$i<$count;$i++)
	{
		$add.=" loginid='$loginid[$i]' or";
	}
	$add=substr($add,0,strlen($add)-3);
	$sql=$empire->query("delete from {$dbtbpre}enewslog where".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("");
		printerror("DelLogSuccess","ListLog.php");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

//日期删除日志
function DelLog_date($start_y,$start_m,$start_d,$end_y,$end_m,$end_d,$uname,$userid,$username){
	global $empire,$dbtbpre;
	//验证权限
	CheckLevel($userid,$username,$classid,"log");
	$start=$start_y.$start_m.$start_d;
	$end=$end_y.$end_m.$end_d;
	$add="";
	if($uname)
	{
		$add.=" and username='$uname'";
    }
	$sql=$empire->query("delete from {$dbtbpre}enewslog where logintime<'$end' and logintime>'$start'".$add);
	if($sql)
	{
		//操作日志
		insert_dolog("username=$uname&time=".$start."-".$end);
		printerror("DelLogSuccess","ListLog.php");
	}
	else
	{
		printerror("DbError","history.go(-1)");
	}
}

$enews=$_POST['enews'];
if(empty($enews))
{$enews=$_GET['enews'];}
//删除日志
if($enews=="DelLog")
{
	$loginid=$_GET['loginid'];
	DelLog($loginid,$logininid,$loginin);
}
//批量删除日志
elseif($enews=="DelLog_all")
{
	$loginid=$_POST['loginid'];
	DelLog_all($loginid,$logininid,$loginin);
}

$line=20;//每页显示条数
$page_line=18;//每页显示链接数
$page=(int)$_GET['page'];
$start=(int)$_GET['start'];
$offset=$start+$page*$line;//总偏移量
$query="select loginid,username,loginip,logintime from {$dbtbpre}enewslog";
$totalquery="select count(*) as total from {$dbtbpre}enewslog";
$username=$_GET['username'];
if(empty($username))
{
	$username=$_POST['username'];
}
$username=RepPostVar($username);
//搜索
$doing=$_GET['doing'];
if(empty($doing))
{$doing=$_POST['doing'];}
if($doing=="del")
{
	$start_y=$_POST['start_y'];
	$start_m=$_POST['start_m'];
	$start_d=$_POST['start_d'];
	$end_y=$_POST['end_y'];
	$end_m=$_POST['end_m'];
	$end_d=$_POST['end_d'];
	DelLog_date($start_y,$start_m,$start_d,$end_y,$end_m,$end_d,$username,$logininid,$loginin);
}
elseif($doing=="search")
{
	$start_y=$_POST['start_y'];
	$start_m=$_POST['start_m'];
	$start_d=$_POST['start_d'];
	$end_y=$_POST['end_y'];
	$end_m=$_POST['end_m'];
	$end_d=$_POST['end_d'];
	if(empty($start_y))
	{
		$start_y=$_GET['start_y'];
		$start_m=$_GET['start_m'];
		$start_d=$_GET['start_d'];
		$end_y=$_GET['end_y'];
		$end_m=$_GET['end_m'];
		$end_d=$_GET['end_d'];
	}
	$start1=$start_y.$start_m.$start_d;
	$end=$end_y.$end_m.$end_d;
	$a="";
	if($username)
	{
		$a=" and username='$username'";
	}
	$where=" where logintime<'$end' and logintime>'$start1'".$a;
	$query.=$where;
	$totalquery.=$where;
	$search="&doing=search&username=$username&start_y=$start_y&start_m=$start_m&start_d=$start_d&end_y=$end_y&end_m=$end_m&end_d=$end_d";
	//$query.=" where username like '%$keyboard%'";
	//$search="&sear=1&keyboard=".$keyboard;
}
else
{}
$num=$empire->gettotal($totalquery);//取得总条数
$query=$query." order by loginid desc limit $offset,$line";
$sql=$empire->query($query);
$returnpage=page1($num,$line,$page_line,$start,$page,$search);
//返回年
$thisyear=date("Y");
for($i=2003;$i<=$thisyear+1;$i++)
{
	$selected='';
	if($i==$thisyear)
	{
		$selected=' selected';
	}
	$yearoption.="<option value='".$i."'".$selected.">".$i."</option>";
}
//用户
$usql=$empire->query("select username from {$dbtbpre}enewsuser order by userid");
while($ur=$empire->fetch($usql))
{
	$select="";
	if($ur['username']==$username)
	{
		$select=" selected";
	}
	$user.="<option value='".$ur[username]."'".$select.">".$ur[username]."</option>";
}
//风格
$loginadminstyleid=(int)getcvar('loginadminstyleid');
?>
<link href="../adminstyle/<?=$loginadminstyleid?>/adminstyle.css" rel="stylesheet" type="text/css"> 
<script>
function CheckAll(form)
  {
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
    }
  }
</script>
<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
  <tr> 
    <td>位置：日志管理 &gt; <a href="ListLog.php">管理登陆日志</a></td>
    <td width="50%"><div align="right">
        <input type="button" name="Submit5" value="管理操作日志" onclick="self.location.href='ListDolog.php';">
      </div></td>
  </tr>
</table>
  
<br>
<table width="100%" align=center cellpadding=0 cellspacing=0>
  <form name=form1 method=post action='ListLog.php' onsubmit="return confirm('确认要执行此操作?');"><input type=hidden name=phome value=DelLog_date>
    <tr> 
      <td height="25"> <div align="center"><font color=#333333>操作: 
          <select name=start_y size=1>
            <?=$yearoption?>
          </select>
          年 
          <select name=start_m size=1>
            <option value=01>1</option>
            <option value=02>2</option>
            <option value=03>3</option>
            <option value=04>4</option>
            <option value=05>5</option>
            <option value=06>6</option>
            <option value=07>7</option>
            <option value=08>8</option>
            <option value=09>9</option>
            <option value=10>10</option>
            <option value=11>11</option>
            <option value=12>12</option>
          </select>
          月 
          <select name=start_d size=1>
            <option value=01>1</option>
            <option value=02>2</option>
            <option value=03>3</option>
            <option value=0>4</option>
            <option value=05>5</option>
            <option value=06>6</option>
            <option value=07>7</option>
            <option value=08>8</option>
            <option value=09>9</option>
            <option value=10>10</option>
            <option value=11>11</option>
            <option value=12>12</option>
            <option value=13>13</option>
            <option value=14>14</option>
            <option value=15>15</option>
            <option value=16>16</option>
            <option value=17>17</option>
            <option value=18>18</option>
            <option value=19>19</option>
            <option value=20>20</option>
            <option value=21>21</option>
            <option value=22>22</option>
            <option value=23>23</option>
            <option value=24>24</option>
            <option value=25>25</option>
            <option value=26>26</option>
            <option value=27>27</option>
            <option value=28>28</option>
            <option value=29>29</option>
            <option value=30>30</option>
            <option value=31>31</option>
          </select>
          日---到--- 
          <select name=end_y size=1>
            <?=$yearoption?>
          </select>
          年 
          <select name=end_m size=1>
            <option value=01>1</option>
            <option value=02>2</option>
            <option value=03>3</option>
            <option value=04>4</option>
            <option value=05>5</option>
            <option value=06>6</option>
            <option value=07>7</option>
            <option value=08>8</option>
            <option value=09>9</option>
            <option value=10>10</option>
            <option value=11>11</option>
            <option value=12>12</option>
          </select>
          月 
          <select name=end_d size=1>
            <option value=01>1</option>
            <option value=02>2</option>
            <option value=03>3</option>
            <option value=04>4</option>
            <option value=05>5</option>
            <option value=06>6</option>
            <option value=07>7</option>
            <option value=08>8</option>
            <option value=09>9</option>
            <option value=10>10</option>
            <option value=11>11</option>
            <option value=12>12</option>
            <option value=13>13</option>
            <option value=14>14</option>
            <option value=15>15</option>
            <option value=16>16</option>
            <option value=17>17</option>
            <option value=18>18</option>
            <option value=19>19</option>
            <option value=20>20</option>
            <option value=21>21</option>
            <option value=22>22</option>
            <option value=23>23</option>
            <option value=24>24</option>
            <option value=25>25</option>
            <option value=26>26</option>
            <option value=27>27</option>
            <option value=28>28</option>
            <option value=29>29</option>
            <option value=30>30</option>
            <option value=31>31</option>
          </select>
          日的日志</font></div></td>
    </tr>
    <tr>
      <td height="25"><div align="center">用户：
          <select name="username">
            <option value="">所有用户</option>
			<?=$user?>
          </select>
        </div></td>
    </tr>
    <tr> 
      <td height="25"> <div align=center> 
          <input name="doing" type="radio" value="search" checked>
          查询日志 
          <input type="radio" name="doing" value="del">
          删除日志 
          <input name=do type=submit id="do" value=执行操作>
        </div></td>
    </tr>
	</form>
  </table>
<form name="form2" method="post" action="ListLog.php" onsubmit="return confirm('确认要删除?');">
  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="tableborder">
    <tr class="header"> 
      <td width="28%" height="25"><div align="center">登陆用户</div></td>
      <td width="26%" height="25"><div align="center">登陆IP</div></td>
      <td width="28%"><div align="center">登陆时间</div></td>
      <td width="18%" height="25"><div align="center">删除</div></td>
    </tr>
    <?
  while($r=$empire->fetch($sql))
  {
  ?>
    <tr bgcolor="#FFFFFF" id=log<?=$r[loginid]?>> 
      <td height="25"><div align="center"> 
          <?=$r[username]?>
        </div></td>
      <td height="25"><div align="center"> 
          <?=$r[loginip]?>
        </div></td>
      <td><div align="center"> 
          <?=$r[logintime]?>
        </div></td>
      <td height="25"><div align="center">[<a href=ListLog.php?enews=DelLog&loginid=<?=$r[loginid]?> onclick="return confirm('确认要删除此日志?');">删除</a> 
          <input name="loginid[]" type="checkbox" id="loginid[]" value="<?=$r[loginid]?>" onclick="if(this.checked){log<?=$r[loginid]?>.style.backgroundColor='#DBEAF5';}else{log<?=$r[loginid]?>.style.backgroundColor='#ffffff';}">
          ]</div></td>
    </tr>
    <?
  }
  ?>
    <tr bgcolor="#FFFFFF"> 
      <td height="25" colspan="4"> 
        <?=$returnpage?>&nbsp;&nbsp;
        <input type="submit" name="Submit" value="批量删除"> <input name="enews" type="hidden" id="phome" value="DelLog_all">&nbsp;
        <input type=checkbox name=chkall value=on onClick=CheckAll(this.form)>
        选中全部 </td>
    </tr>
  </table>
</form>
<?
db_close();
$empire=null;
?>
