<?php
require 'inc.php';
$obj_tab_account=new cls_tab_sys_account;

(isset($get_s_key)) ? $get_s_key=chk_escape($get_s_key) : $get_s_key="";
(isset($get_s_gold_total1) && !empty($get_s_gold_total1))? $get_s_gold_total1=(int)$get_s_gold_total1 : $get_s_gold_total1="";
(isset($get_s_gold_total2) && !empty($get_s_gold_total2))? $get_s_gold_total2=(int)$get_s_gold_total2 : $get_s_gold_total2="";
(isset($get_s_score_total1) && !empty($get_s_score_total1))? $get_s_score_total1=(int)$get_s_score_total1 : $get_s_score_total1="";
(isset($get_s_score_total2) && !empty($get_s_score_total2))? $get_s_score_total2=(int)$get_s_score_total2 : $get_s_score_total2="";

(isset($get_s_gold1) && !empty($get_s_gold1))? $get_s_gold1=(int)$get_s_gold1 : $get_s_gold1="";
(isset($get_s_gold2) && !empty($get_s_gold2))? $get_s_gold2=(int)$get_s_gold2 : $get_s_gold2="";
(isset($get_s_score1) && !empty($get_s_score1))? $get_s_score1=(int)$get_s_score1 : $get_s_score1="";
(isset($get_s_score2) && !empty($get_s_score2))? $get_s_score2=(int)$get_s_score2 : $get_s_score2="";

$page_footer_info=<<<HTML
HTML;

if($get_act=="edit_score" && !empty($get_edit_score)){
	foreach($get_accountids as $item){
		$arr_msg=$obj_tab_account->on_save_score($item,$get_edit_score,1,$obj_ctl_user->id,$get_edit_score_beta);
		if($arr_msg["err"]!=""){
			$obj_msg->alert($arr_msg["err"]);
			break;
		}
	}
}
if($get_act=="edit_gold" && !empty($get_edit_gold)){
	foreach($get_accountids as $item){
		$arr_msg=$obj_tab_account->on_save_gold($item,$get_edit_gold,2,$obj_ctl_user->id,$get_edit_gold_beta);
		if($arr_msg["err"]!=""){
			$obj_msg->alert($arr_msg["err"]);
			break;
		}
	}
}
switch($get_act)
{	
	default:
	{
		$get_issearch=0;
		$str_where=" where 1";
		if($get_s_key!=""){
			$get_issearch=1;
			if(is_numeric($get_s_key)){
				$arr_where[]="account_user_id=".$get_s_key;
			}
			$arr_uid=$obj_ctl_user->get_user_id($get_s_key);
			if(count($arr_uid)>0){
				$arr_where[]="account_user_id=".$arr_uid[$get_s_key];
			}else{
				$obj_rs=$obj_db->get_one("select company_user_id from ".DB_PRE."hr_company where company_name like '%".$get_s_key."%'");
				if(isset($obj_rs["company_user_id"])){
					$arr_where[]="account_user_id=".$obj_rs["company_user_id"];
				}else{
					$obj_rs=$obj_db->get_one("select resume_user_id from ".DB_PRE."hr_resume where resume_name like '%".$get_s_key."%'");
					if(isset($obj_rs["company_user_id"])){
						$arr_where[]="account_user_id=".$obj_rs["resume_user_id"];
					}else{
						$arr_where[]="1>2";
					}
				}
			}
			$str_where.=" and (".implode(" or ",$arr_where).")";
		}
		$arr_account = array();
		$arr_userid=array();
		$arr_uid=array();
		$arr_showname=array();
		$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."sys_account".$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."sys_account".$str_where.$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["gold"]=$obj_rs["account_gold"]+$obj_rs["account_gold_use"];
			$obj_rs["score"]=$obj_rs["account_score"]+$obj_rs["account_score_use"];
			$arr_userid[]=$obj_rs["account_user_id"];
			$arr_showname["id_".$obj_rs["account_user_id"]]="";
			$arr_account[]=$obj_rs;
		}
		if(count($arr_userid)>0){
			$arr_uname=$obj_ctl_user->get_user_name($arr_userid);
			$str_ids=implode(",",$arr_userid);
			$obj_result=$obj_db->query("select resume_name,resume_user_id from ".DB_PRE."hr_resume where resume_user_id in(".$str_ids.")");
			while($obj_rs=$obj_db->fetch_array($obj_result)){
				$arr_showname["id_".$obj_rs["resume_user_id"]]=$obj_rs["resume_name"]."(¸öÈË)";
			}
			$obj_result=$obj_db->query("select company_name,company_user_id from ".DB_PRE."hr_company where company_user_id in(".$str_ids.")");
			while($obj_rs=$obj_db->fetch_array($obj_result)){
				$arr_showname["id_".$obj_rs["company_user_id"]]=$obj_rs["company_name"]."(ÆóÒµ)";
			}
		}
		include 'tpl/account.tpl.php';
	}
}


?>
