<?php
require 'inc.php';
$obj_tab_log=new cls_tab_sys_admin_log();

if($get_act=="del_sel"){
	$arr_return=$obj_tab_log->on_del($get_selid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_clear"){
	$arr_return=$obj_tab_log->on_del(0,$get_del_addtime1,$get_del_addtime2);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}

if(!isset($get_s_addtime1) || !is_date($get_s_addtime1)) $get_s_addtime1="";
if(!isset($get_s_addtime2) || !is_date($get_s_addtime2)) $get_s_addtime2="";
if(!isset($get_s_key)) $get_s_key="";
if(!isset($get_s_ip)) $get_s_ip="";
if(!isset($get_s_uid)) $get_s_uid="";

$arr_admin_id=array();
$obj_result=$obj_db->query("select admin_user_id,admin_name from ".DB_PRE."sys_admin");
while($obj_rs=$obj_db->fetch_array($obj_result)){
	$arr_admin_id[]=$obj_rs["admin_user_id"];
}
if(defined("WEB_ADMIN_ID")){
	$arr_x=explode(",",WEB_ADMIN_ID);
	$arr_admin_id=array_unique(array_merge($arr_admin_id,$arr_x));
}
//·ÖÒ³
$get_issearch=0;
$str_where=" where 1";
if($get_s_addtime1!=""){
	$str_where.=" and log_addtime>='".strtotime($get_s_addtime1)."'";
	$get_issearch=1;
}
if($get_s_addtime2!=""){
	$str_where.=" and log_addtime<='".strtotime($get_s_addtime2)."'";
	$get_issearch=1;
}
if($get_s_ip!=""){
	$str_where.=" and log_ip like '%".format_sql_safe($get_s_ip)."%'";
	$get_issearch=1;
}
if(!empty($get_s_uid)){
	$str_where.=" and log_user_id='".format_sql_safe($get_s_uid)."'";
	$get_issearch=1;
}
if($get_s_key!=""){
	$str_where.=" and log_act_param like '%".format_sql_safe($get_s_key)."%'";
	$get_issearch=1;
}
$arr_log=array();
$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."sys_admin_log".$str_where);
$int_total=$obj_rs["num"];
$int_pages= ceil($int_total/$int_pagesize);
$get_page = min($int_pages, $get_page);
$get_page = max($get_page, 1);
$page_split_page=get_pages($int_total, $get_page, $int_pagesize);
$int_offset = $int_pagesize*($get_page-1);
$str_limit = " limit ".$int_offset.",".$int_pagesize;
$arr_modelkey=array();
$arr_page=array();
$arr_uid=$arr_admin_id;
$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_admin_log".$str_where." order by log_addtime desc".$str_limit);
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$obj_rs["log_addtime"] = format_date($obj_rs["log_addtime"],"Y-m-d H:i");
	if(!in_array($obj_rs["log_user_id"],$arr_uid)) $arr_uid[]=$obj_rs["log_user_id"];
	if(!in_array($obj_rs["log_modelkey"],$arr_modelkey)) $arr_modelkey[]=$obj_rs["log_modelkey"];
	if(!in_array($obj_rs["log_page"],$arr_page)) $arr_page[]=$obj_rs["log_page"];
	$arr_log[] = $obj_rs;
}
$arr_uname=array();
$arr_pagename=array();
if(count($arr_uid)>0){
	$arr_uname=$obj_ctl_user->get_user_name($arr_uid);

	$str_modelkey=implode("','",$arr_modelkey);
	$str_page=implode("','",$arr_page);
	$str_sql="SELECT a.model_regkey,a.model_name,b.page_name,page_url FROM ".DB_PRE."sys_model a inner join ".DB_PRE."sys_admin_page b on a.model_id=b.page_model_id where model_regkey in('".$str_modelkey."') and page_url in('".$str_page."')";
	$obj_result = $obj_db->query($str_sql);
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_pagename[$obj_rs["model_regkey"].$obj_rs["page_url"]]=$obj_rs["model_name"]."->".$obj_rs["page_name"];
	}
}
include "tpl/admin.log.tpl.php";
?>
