<?php
define('THIS_SCRIPT', 'forum_pay');
include_once 'global.php';
$lang = load_lang($lang, 'forum_pay' );
checklogin();
header("content-Type: text/html; charset=".$charset);
head();
if ( strpos($sysinfo['flag'],'17,') === false ){
	show_msg($lang['readme_tit'],$lang['error.str1'],0,'','','','');
	exit;
}
PageLoad();
footer();
function Pageload(){
	global $dv,$db,$lang,$action,$search_money_count,$pay_list,$page_size,$page,$total,$page_count,$offset,$p;
	switch($action){
		case "search":
			pay_search();
		break;
		default:
			pay_list();
		break;
	}
include printout('forum_pay');
}
function pay_list(){
	global $lang,$dv,$db,$search_money_count,$pay_list,$page_size,$page,$total,$page_count,$offset,$p;
	$total=$db->scalar("SELECT count(1) FROM {$dv}chanorders");
	page_info(20);
	$search_money_count=$db->scalar("SELECT sum(o_paymoney) FROM {$dv}chanorders");//×Ü½ð¶î;
	$sql=$db->query("SELECT o_id,o_type,o_mobile,o_username,o_isapply,o_issuc,o_paymoney,o_paycode,o_boardid,o_topicid,o_addtime FROM {$dv}chanorders order by o_id",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	while($arr=$db->fetch_array($sql)){
		$pay_list[]=$arr;
	}
$db->free_result($sql);
}
function pay_search(){
	global $lang,$dv,$db,$start_time,$end_time,$keyword,$type,$pay_state,$more_less,$money_num,$pay_list,$search_money_count;
	global $page_size,$page,$total,$page_count,$offset,$p;
	$pay_list=array();
	$keyword=str_replace(" ","",$_POST['keyword']);
	$start_time=$_POST['start_time'];
	$end_time=$_POST['end_time'];
	$type=$_POST['type'];
	$pay_state=$_POST['pay_state'];
	$more_less=$_POST['more_less'];
	$money_num=intval($_POST['money_num']);
	$search_str="";
	if($keyword<>""){
		$search_str.=" o_username like '%".$keyword."%' or o_paycode like '%".$keyword."%' and ";
	}
	if(intval($pay_state)==1){
		$search_str.=" o_issuc=0 and ";
	}
	elseif(intval($pay_state)==2){
		$search_str.=" o_issuc=1 and ";
	}
	else{
		$search_str=$search_str;
	}
	if(($start_time=str_replace(" ","",$start_time))<>"" and ereg("([0-9]{4})-([0-2]{1,2})-([0-3]{1,2})",$start_time)){
		$start_time=dv_gmtimestamp($start_time)-getUserTimeZoneOffset();
		$search_str.=" o_addtime>=".$start_time." and ";
	}
	if(($end_time=str_replace(" ","",$end_time))<>"" and ereg("([0-9]{4})-([0-2]{1,2})-([0-3]{1,2})",$end_time)){
		$start_time=dv_gmtimestamp($end_time)-getUserTimeZoneOffset();
		$search_str.=" o_addtime<=".$end_time." and ";
	}
	if(intval($type)==0 or intval($type)==""){
		$search_str=$search_str;
	}
	else{
		$search_str.=" o_type=".intval($type)." and ";
	}
	if(intval($money_num)<>0 or $money_pay<>""){
		if($more_less=="Y"){
			$search_str.=" o_paymoney>".$money_num."";
		}
		else{
			$search_str.=" o_paymoney<".$money_num."";
		}
	}
	else{
		$search_str=substr($search_str,0,-5);
	}
	if($search_str==""){
		$total=$db->scalar("SELECT count(1) FROM {$dv}chanorders");
		page_info(30);
		$search_money_count=$db->scalar("SELECT sum(o_paymoney) FROM {$dv}chanorders");
		$sql=$db->query("SELECT o_id,o_type,o_mobile,o_username,o_isapply,o_issuc,o_paymoney,o_paycode,o_boardid,o_topicid,o_addtime FROM {$dv}chanorders order by o_id",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	else{
		$total=$db->scalar("SELECT count(1) FROM {$dv}chanorders WHERE".$search_str);
		page_info(30);
		$search_money_count=$db->scalar("SELECT sum(o_paymoney) FROM {$dv}chanorders WHERE".$search_str);
		$sql=$db->query("SELECT o_id,o_type,o_mobile,o_username,o_isapply,o_issuc,o_paymoney,o_paycode,o_boardid,o_topicid,o_addtime FROM {$dv}chanorders WHERE".$search_str." order by o_id",array('absolutePage'=>$offset,'pageSize'=>$page_size));
	}
	if($total<=0){
		show_msg($lang['sys.info'],$lang['pay.info30'],0,'','','forum_pay.php',$lang['cmdback']);
	exit;
	}
	else{
		while($arr=$db->fetch_array($sql)){
			$pay_list[]=$arr;
		}
	}
$db->free_result($sql);
}
?>