<?php
require 'inc.php';
$obj_tab_order=new cls_tab_pay_order;
$arr_state=$obj_tab_order->state;

(isset($get_s_key)) ? $get_s_key=chk_escape($get_s_key) : $get_s_key="";
(isset($get_s_state)) ? $get_s_state=intval($get_s_state) : $get_s_state=-101;
(isset($get_s_addtime1) && is_date($get_s_addtime1) ) ? $get_s_addtime1=$get_s_addtime1 : $get_s_addtime1="";
(isset($get_s_addtime2) && is_date($get_s_addtime2) ) ? $get_s_addtime2=$get_s_addtime2 : $get_s_addtime2="";

$page_footer_info=<<<HTML
HTML;

if($get_act=='del_sel' && isset($get_orderids))
{
	$arr_msg=$obj_tab_order->on_del($get_orderids);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
if($get_act=='state'&&isset($get_state_val) && isset($get_orderids))
{
	$arr_msg=$obj_tab_order->on_state($get_orderids,$get_state_val);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
switch($get_act)
{	
	default:
	{
		$get_issearch=0;
		$str_where=" where 1";
		if($get_s_key!=""){
			if(is_numeric($get_s_key) && strlen($get_s_key)<10){
				$str_uid=(int)$get_s_key;
			}else{
				$str_uid=0;
				$arr_x=$obj_ctl_user->get_user_id($get_s_key);
				if(isset($arr_x[$get_key])) $str_uid=$arr_x[$get_s_key];
			}
			$str_where.=" and (order_number='".$get_s_key."' or order_user_id in(".$str_uid."))";
			$get_issearch=1;
		}
		if($get_s_addtime1!=""){
			$str_where.=" and order_addtime>='".strtotime($get_s_addtime1)."'";
			$get_issearch=1;
		}
		if($get_s_addtime2!=""){
			$str_where.=" and order_addtime<='".strtotime($get_s_addtime2)."'";
			$get_issearch=1;
		}
		if($get_s_state!=-101){
			$str_where.=" and order_state<='".$get_s_state."'";
			$get_issearch=1;
		}
		$arr_order = array();
		$arr_uid=array();
		$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."pay_order".$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;
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."pay_order".$str_where." order by order_id desc".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["addtime"]=date("Y-m-d H:i:s",$obj_rs["order_addtime"]);
			$obj_rs["state"]=array_search($obj_rs["order_state"],$arr_state);
			if($obj_rs["order_state"]<=0){
				$obj_rs["state"]="<font color='#ff0000'>".$obj_rs["state"]."</font>";
			}
			$arr_uid[]=$obj_rs["order_user_id"];
			$arr_order[]=$obj_rs;
		}
		$arr_uname=$obj_ctl_user->get_user_name($arr_uid);
		foreach($arr_uid as $item){
			if(!isset($arr_uname["id_".$item])) $arr_uname["id_".$item]="";
		}
		if(count($arr_uid)>0){
			$str_uids=implode(",",$arr_uid);
			$obj_result=$obj_db->query("select resume_user_id,resume_name from ".DB_PRE."hr_resume where resume_user_id in(".$str_uids.")");
			while($obj_rs=$obj_db->fetch_array($obj_result)){
				$arr_name["id_".$obj_rs["resume_user_id"]]=$obj_rs["resume_name"];
			}
			$obj_result=$obj_db->query("select company_user_id,company_name from ".DB_PRE."hr_company where company_user_id in(".$str_uids.")");
			while($obj_rs=$obj_db->fetch_array($obj_result)){
				$arr_name["id_".$obj_rs["company_user_id"]]=$obj_rs["company_name"];
			}
		}
		include 'tpl/order.tpl.php';
	}
}


?>
