<?php
define('THIS_SCRIPT', 'moneylog');
include_once 'global.php';
$lang = load_lang($lang, 'moneylog' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'45,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $lang,$dv,$db,$action,$stype,$titlestr,$log_set,$page_size,$page,$total,$page_count,$offset,$p;
	switch ($action){
		case "del":
			del_log();
		break;
		case "alldel":
			del_alllog();
		break;
		default:
			log_list();
			sub_title();
		break;
	}
include_once printout('moneylog');
}
function sub_title(){
	global $stype,$titlestr,$lang;
	$stype=$_GET['stype'];
	switch(intval($stype)){
		case 1:
			$titlestr=$lang['log.info2'].$lang['log.info3'];
		break;
		case 2:
			$titlestr=$lang['log.info2'].$lang['log.info4'];
		break;
		case 3:
			$titlestr=$lang['log.info2'].$lang['log.info5'];
		break;
		case 4:
			$titlestr=$lang['log.info2'].$lang['log.info6'];
		break;
		case 5:
			$titlestr=$lang['log.info2'].$lang['log.info7'];
		break;
		case 6:
			$titlestr=$lang['log.info2'].$lang['log.info8'];
		break;
		default:
			$titlestr=$lang['log.info2'].$lang['log.info9'];
		break;
	}
}
function log_list(){
	global $lang,$db,$dv,$stype,$keyword,$log_set,$page_size,$page,$total,$page_count,$offset,$p;
	//'(0=其它,1=使用,2=转让,3=充值,4=购买,5=奖励)
	$log_set=array();
	$stype=intval($_GET['stype']);
	$keyword=$_POST['keyword'];
	switch ($stype){
		case 1:
			$conf="WHERE log_type=1";
		break;
		case 2:
			$conf="WHERE log_type=2";
		break;
		case 3:
			$conf="WHERE log_type=3";
		break;
		case 4:
			$conf="WHERE log_type=4";
		break;
		case 5:
			$conf="WHERE log_type=5";
		break;
		case 6:
			$conf="WHERE log_type=6";
		break;
		case -1:
			$conf="WHERE boardid=-1";
		break;
		case 7:
			$conf="";
		break;
		default:
			$conf="";
		break;
	}
	if($conf<>""){
		if($keyword<>""){
			$conf.=" AND (addusername like '%".$keyword."%' OR conect like '%".$keyword."%')";
		}
	}
	else{
		if($keyword<>""){
			$conf="WHERE addusername like '%".$keyword."%' OR conect like '%".$keyword."%'";
		}
	}
	$total=$db->scalar("SELECT count(1) FROM {$dv}moneylog ".$conf);
	page_info(20);
	$sql=$db->query("SELECT log_id,toolsid,countnum,log_money,log_ticket,addusername,adduserid,log_ip,log_time,log_type,boardid,conect,hmoney FROM {$dv}moneylog ".$conf." ORDER BY log_id Desc",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while($arr=$db->fetch_array($sql)){
		$log_set[]=$arr;
	}
$db->free_result($sql);
}
function del_log(){
	global $lang,$dv,$db,$dtype;
	$dtype=$_GET['dtype'];
	if(!is_numeric($dtype) or $dtype==""){
		show_msg($lang['sys.info'],$lang['log.info12'],0,'','',$lang['url'],$lang['comback']);
	exit;	
	}
	else{
		$dtype=intval($_GET['dtype']);
	}
	$endlogtime=time()+date('Z')-getUserTimeZoneOffset()-(10*24*3600);
	switch($dtype){
		case 1://使用日志
			$sql="DELETE FROM {$dv}moneylog WHERE log_type=1 AND log_time<='".$endlogtime."'";
		break;
		case 2://转让日志
			$sql="DELETE FROM {$dv}moneylog WHERE log_type=2 AND log_time<='".$endlogtime."'";
		break;
		case 3://充值日志
			$sql="DELETE FROM {$dv}moneylog WHERE log_type=3 AND log_time<='".$endlogtime."'";
		break;
		case 4://购买日志
			$sql="DELETE FROM {$dv}moneylog WHERE log_type=4 AND log_time<='".$endlogtime."'";
		break;
		case 5://奖励日志
			$sql="DELETE FROM {$dv}moneylog WHERE log_type=5 AND log_time<='".$endlogtime."'";
		break;
		case 6://后台操作日志-1
			$sql="DELETE FROM {$dv}moneylog WHERE boardid=-1 AND log_time<='".$endlogtime."'";
		break;
		case 7://所有0
			$sql="DELETE FROM {$dv}moneylog WHERE log_time<='".$endlogtime."'";
		break;
	}
	$result=$db->query($sql);
	if($result){
		show_msg($lang['sys.info'],$lang['log.info13'],1,'','',$lang['url'],$lang['comback']);
	exit;	
	}
	else{
		show_msg($lang['sys.info'],$lang['log.info14'],0,'','',$lang['url'],$lang['comback']);
	exit;	
	}
}
function del_alllog(){
	global $lang,$dv,$db,$logid;
	$logid=$_POST['logid'];
	$count=count($logid);
	if($count==0){
		show_msg($lang['sys.info'],$lang['log.info15'],0,'','',$lang['url'],$lang['comback']);
	exit;	
	}
	else{
		for($i=0;$i<=$count;$i++){
			$delid.=$logid[$i].",";
		}
		$endlogtime=time()+date('Z')-getUserTimeZoneOffset()-(10*24-3600);
		$delid=substr($delid,0,-2);
		$sql="DELETE FROM {$dv}moneylog WHERE log_id in (".$delid.") AND log_time<'".$endlogtime."'";
		$result=$db->query($sql);
		if($result){
			show_msg($lang['sys.info'],$lang['log.info13'],1,'','',$lang['url'],$lang['comback']);
		exit;	
		}
		else{
			show_msg($lang['sys.info'],$lang['log.info14'],0,'','',$lang['url'],$lang['comback']);
		exit;	
		}
	}
}
?>