<?php
define('THIS_SCRIPT', 'forum_log');
include_once 'global.php';
$lang = load_lang($lang,'forum_log');
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'3,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $do_action,$dv,$db,$lang,$action,$cond_str,$info_list,$type,$keyword,$key_match,$ss_check,$zero_check,$one_check,$two_check,$three_check,$four_check,$five_check,$six_check,$select_all,$touser_check,$sl_check,$cont_check,$ip_check,$user_check,$star,$tab,$select_all,$all_check,$dnums,$selected_id,$url;
	global $page_size,$page,$total,$page_count,$offset;
	global $type,$search_area,$keyword,$key_match;
	$url="javascript:void(window.history.back(-1))";
	switch ($do_action) {
		case "del":
			record_del();
			break;
		case "search":
			log_search();
			break;
		case "all_del":
			del_all();
			break;
		default:
			select_value();
			log_info();
			break;
	}
include printout('forum_log');
}
function log_search(){
	global $dv,$db,$lang,$info_list,$do_action,$action,$type,$keyword,$key_match;
	global $page_size,$page,$total,$page_count,$offset,$url,$cond_str;
	global $type,$search_area,$keyword,$key_match;
	$info_list=array();
	$type=$_POST['type'];
	if($type==''){
		$type=$_GET['type'];
	}
	$search_area=$_POST['search_area'];
	if($search_area==''){
		$search_area=$_GET['search_area'];
	}
	$keyword=$_POST['keyword'];
	if($keyword==''){
		$keyword=$_GET['keyword'];
	}
	$key_match=$_POST['key_match'];
	if($key_match==''){
		$key_match=$_GET['key_match'];
	}
	$cond_str="";//条件部分;
	if($type<>"")
		$cond_str.="l_type=".$type." and ";
	if($search_area<>"")
		$cond_str.=" l_boardid=".$search_area." and ";
	if($keyword!="" and $key_match!="")
		$cond_str.=$key_match." like '%$keyword%'";
	elseif($keyword<>"" and $key_match=="")
		$cond_str.=" l_touser like '%".$keyword."%' or l_content like '%".$keyword."%' or l_ip like '%".$keyword."%' or l_username like '%".$keyword."%'";
	else
		$cond_str=substr($cond_str,0,strlen($cond_str)-5);
	if($cond_str!=""){//执行部分;
		$stmt="select l_id,l_announceid,l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type from {$dv}log where ".$cond_str." order by l_addtime desc";
		$total=intval($db->scalar("select count(1) from {$dv}log where ".$cond_str));//得到总记录;
	}
	else{
		$stmt="select l_id,l_announceid,l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type from {$dv}log order by l_addtime desc";
		$total=intval($db->scalar("select count(1) from {$dv}log"));//得到总记录;
	}
	if($total<=0){
			show_msg($lang['sys.info'],$lang['error.info'],0,'','',$url,$lang['cmdback']);
		exit;	
	}
	page_info(20);
	if($result=$db->query($stmt,array('absolutePage'=>$offset,'pageSize'=>$page_size))){
		while($arr=$db->fetch_array($result)){
			$info_list[]=$arr;
		}
	}
$db->free_result($result);
}
function select_value(){
	global $type,$keyword,$key_match,$do_action,$ss_check,$zero_check,$one_check,$two_check,$three_check,$four_check,$five_check,$six_check,$touser_check,$sl_check,$cont_check,$ip_check,$user_check,$url;
	if($type==='')
		$ss_check="selected";
	else
		$ss_check="";
	if($type==3)
		$three_check="selected";
	else
		$three_check="";
	if($type==4)
		$four_check="selected";
	else
		$four_check="";
	if($type==5)
		$five_check="selected";
	else
		$five_check="";
	if($type==6)
		$six_check="selected";
	else
		$six_check="";
	if($type==='0')
		$zero_check="selected";
	else
		$zero_check="";
	if($type==1)
		$one_check="selected";
	else
		$one_check="";
	if($type==2)
		$two_check="selected";
	else 
		$tow_check="";//type selected end;
	
	if($key_match=="")
		$sl_check="selected";
	else 
		$sl_check="";
	if($key_match=="l_touser")
		$touser_check="selected";
	else
		$touser_check="";
	if($key_match=="l_content")
		$cont_check="selected";
	else
		$cont_check="";
	if($key_match=="l_ip")
		$ip_check="selected";
	else
		$ip_check="";
	if($key_match=="l_username")
		$user_check="selected";
	else
		$user_check="";
}
function log_info(){
	global $dv,$db,$info_list,$do_action,$action,$type,$keyword,$key_match,$page_size,$page,$total,$page_count,$offset,$url;
	$info_list=array();
	$total=intval($db->scalar("select count(1) from {$dv}log"));//得到总记录;
	page_info(50);
	$stmt="select l_id,l_announceid,l_boardid,l_touser,l_username,l_content,l_addtime,l_ip,l_type from {$dv}log order by l_addtime desc";
	if($result=$db->query($stmt,array('absolutePage'=>$offset,'pageSize'=>$page_size))){
		while($arr=$db->fetch_array($result)){
			$info_list[]=$arr;
		}
	}
}
function record_del(){
	global $dv,$db,$lang,$action_del,$dnums,$do_action,$selected_id,$url;
	$dnums=count($_POST['selected_id']);
	$endaddtime=dv_gmtimestamp(gmdate('Y-m-d 23:59:59'))-2*24*3600;
	if ($dnums!=0){
		for($i=0;$i<$dnums;$i++){
			$db->query("delete from {$dv}log where l_addtime<='".$endaddtime."' and l_id=".$selected_id[$i]);
			$err=$db->error();
			if ($err){
				show_msg($lang['sys.info'],$lang['error.info1'].$selected_id[$i].$lang['error.info2'],0,'','',$url,$lang['cmdback']);
			exit;		
			}
			else{
				$db->query("delete from {$dv}log where l_addtime<='".$endaddtime."' and l_id=".$selected_id[$i]);
				$err1=$db->error();
				if ($err1){
					show_msg($lang['sys.info'],$lang['error.info1'].$selected_id[$i].$lang['error.info2'],0,'','',$url,$lang['cmdback']);
				exit;	
				}
			}
		}
			show_msg($lang['sys.info'],$lang['succeed.info'],1,'','',$url,$lang['backcmd']);
		exit;
	}
	else{
			show_msg($lang['sys.info'],$lang['error.info3'],0,'','',$url,$lang['backcmd']);
		exit;	
	}
}
function del_all(){
	global $dv,$db,$lang,$do_action,$url;
	$endaddtime=dv_gmtimestamp(gmdate('Y-m-d 23:59:59'))-2*24*3600;
	$stmt="delete from {$dv}log where l_addtime<='".$endaddtime."'";
	$result=$db->query($stmt);
	if($result){
		show_msg($lang['sys.info'],$lang['succeed.info'],1,'','',$url,$lang['backcmd']);
	exit;	
	}
	else{
		show_msg($lang['sys.info'],$lang['error.info3'],0,'','',$url,$lang['backcmd']);
	exit;	
	}
}
?>