<?php
$arr_search_param=array();
$int_pagesize=20;
(isset($get_page))? $get_page=intval($get_page):$get_page=1;
(isset($get_search_id))? $get_search_id=intval($get_search_id):$get_search_id=0;
$obj_tab_jobcategory=new cls_tab_hr_job_category();
$obj_tab_job=new cls_tab_hr_job();
$arr_userid=array();
$arr_company=array();
if($get_search_id>0){
	$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_job_search where search_id='".$get_search_id."'");
	if($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$get_search_name=$obj_rs["search_name"];
		$get_search_jobtype=$obj_rs["search_jobtype"];
		$get_search_jobcategory=$obj_rs["search_jobcategory"];
		$get_search_pay=$obj_rs["search_pay"];
		$get_search_pay_direction=$obj_rs["search_pay_direction"];
		$get_search_area=$obj_rs["search_area"];
		$get_search_pubtime=$obj_rs["search_pubtime"];
		$get_search_keyword=$obj_rs["search_keyword"];
		$get_search_degree=$obj_rs["search_degree"];
		$get_search_degree_direction=$obj_rs["search_degree_direction"];
		$get_search_experience=$obj_rs["search_experience"];
		$get_search_experience_direction=$obj_rs["search_experience_direction"];
		$get_search_sex=$obj_rs["search_sex"];
		$get_search_age=$obj_rs["search_age"];
		$get_search_age_direction=$obj_rs["search_age_direction"];
		$get_search_marry=$obj_rs["search_marry"];
		$get_search_additional=$obj_rs["search_additional"];
	}
}

$str_where=" where 1";
(isset($get_search_pay_direction))? $arr_search["search_pay_direction"]=intval($get_search_pay_direction):$arr_search["search_pay_direction"]=0;
if(isset($get_search_pay)&&intval($get_search_pay)>0){
	$get_search_pay=intval($get_search_pay);
	$arr_search["pay"]=get_select_html($obj_tab_job->pay,$get_search_pay);
	if($arr_search["search_pay_direction"]>0){
		$str_direction="=";
	}else if($arr_search["search_pay_direction"]<0){
		$str_direction="<";
	}else{
		$str_direction=">=";
	}
	$str_where.=" and job_pay1<>0 and job_pay2<>0 and job_pay1".$str_direction.$get_search_pay;
	$arr_search_param["search_pay"]=$get_search_pay;
}else{
	$arr_search["pay"]=get_select_html($obj_tab_job->pay);
}
(isset($get_search_experience_direction))? $arr_search["search_experience_direction"]=intval($get_search_experience_direction):$arr_search["search_experience_direction"]=0;
if(isset($get_search_experience)&&intval($get_search_experience)>0){
	$get_search_experience=intval($get_search_experience);
	$arr_search["experience"]=get_select_html($obj_tab_job->experience,$get_search_experience);
	if($arr_search["search_experience_direction"]>0){
		$str_direction="=";
	}else if($arr_search["search_experience_direction"]<0){
		$str_direction="<";
	}else{
		$str_direction=">=";
	}
	$str_where.=" and job_experience1".$str_direction.$get_search_experience;
	$arr_search_param["search_experience"]=$get_search_experience;
}else{
	$arr_search["experience"]=get_select_html($obj_tab_job->experience);
}
(isset($get_search_degree_direction))? $arr_search["search_degree_direction"]=intval($get_search_degree_direction):$arr_search["search_degree_direction"]=0;
if(isset($get_search_degree)&&intval($get_search_degree)>0){
	$get_search_degree=intval($get_search_degree);
	$arr_search["degree"]=get_select_html($obj_tab_job->degree,$get_search_degree);
	if($arr_search["search_degree_direction"]>0){
		$str_direction="=";
	}else if($arr_search["search_degree_direction"]<0){
		$str_direction="<";
	}else{
		$str_direction=">=";
	}
	$str_where.=" and job_degree".$str_direction.$get_search_degree;
	$arr_search_param["search_degree"]=$get_search_degree;
}else{
	$arr_search["degree"]=get_select_html($obj_tab_job->degree);
}
(isset($get_search_age_direction))? $arr_search["search_age_direction"]=intval($get_search_age_direction):$arr_search["search_age_direction"]=0;
if(isset($get_search_age)&&intval($get_search_age)>0){
	$get_search_age=intval($get_search_age);
	$arr_search["search_age"]=$get_search_age;
	if($arr_search["search_age_direction"]>0){
		$str_direction="=";
	}else if($arr_search["search_age_direction"]<0){
		$str_direction="<";
	}else{
		$str_direction=">=";
	}
	$str_where.=" and job_age1".$str_direction.$get_search_age;
	$arr_search_param["search_age"]=$get_search_age;
}else{
	$arr_search["search_age"]="";
}
if(isset($get_search_jobtype)&&$get_search_jobtype!=""){
	if(in_array($get_search_jobtype,$obj_tab_job->type)){
		$arr_search["jobtype"]=get_select_html($obj_tab_job->type,$get_search_jobtype);
		$str_where.=" and job_type='".$get_search_jobtype."'";
	}else{
		$arr_search["jobtype"]=get_select_html($obj_tab_job->type);
	}
	$arr_search_param["search_jobtype"]=urlencode($get_search_jobtype);
}else{
	$arr_search["jobtype"]=get_select_html($obj_tab_job->type);
}
(isset($get_search_pubtime))? $arr_search["search_pubtime"]=intval($get_search_pubtime):$arr_search["search_pubtime"]=0;
if($arr_search["search_pubtime"]!=0){
	$lng_time2=0;
	if($arr_search["search_pubtime"]>1){
		$lng_time=TIME-$arr_search["search_pubtime"]*86400;
	}else{
		switch($arr_search["search_pubtime"]){
			case 1:{
				$lng_time=format_date_int(date("Y-m-d",TIME));//当天
				break;
			}
			case -1:{
				$lng_time=get_toweek_time();//本周
				break;
			}
			case -2:{
				$str_date=date("Y-m",TIME)."-01";
				$lng_time=format_date_int($str_date);//本月
				break;
			}
			case -3:{
				$str_date=date("Y",TIME)."-01-01";
				$lng_time=format_date_int($str_date);//今年
				break;
			}
			case -4:{
				$lng_year=intval(date("Y",TIME))-1;
				$str_date=$lng_year."-01-01";
				$lng_time=format_date_int($str_date);//今年
				$str_date=date("Y",TIME)."-01-01";
				$lng_time2=format_date_int($str_date);//今年
				break;
			}
		}
	}
	$str_where.=" and job_updatetime>='".$lng_time."'";
	if($lng_time2>0) $str_where.=" and job_updatetime<'".$lng_time2."'";
	$arr_search_param["search_pubtime"]=$get_search_pubtime;
}
if(isset($get_search_sex)&&$get_search_sex!=""){
	if(in_array($get_search_sex,array("男","女"))){
		$str_where.=" and job_sex='".$get_search_sex."'";
	}
	$arr_search["search_sex"]=$get_search_sex;
	$arr_search_param["search_sex"]=urlencode($get_search_sex);
}else{
	$arr_search["search_sex"]="";
}
if(isset($get_search_marry)&&$get_search_marry!=""){
	if(in_array($get_search_marry,array("未婚","已婚"))){
		$str_where.=" and job_marry='".$get_search_marry."'";
	}
	$arr_search["search_marry"]=$get_search_marry;
	$arr_search_param["search_marry"]=urlencode($get_search_marry);
}else{
	$arr_search["search_marry"]="";
}
if(isset($get_search_keyword)&&$get_search_keyword!=""){
	$arr_search["search_keyword"]=$get_search_keyword;
	$arr_search_param["search_keyword"]=urlencode($get_search_keyword);
	$str_where.=" and job_name like '%".format_sql_safe($get_search_keyword)."%'";
}else{
	$arr_search["search_keyword"]="";
}
if(isset($get_search_jobcategory)&&$get_search_jobcategory!=""){
	$arr_search["search_jobcategory"]=$get_search_jobcategory;
	$arr_search["jobcategorytxt"]=format_len($get_search_jobcategory,40,"...");
	$arr_category=explode("|",$get_search_jobcategory);
	$arr_x=array();
	foreach($arr_category as $item){
		if($item!=""){
			$item=format_sql_safe($item);
			$item=str_replace(" ","%",$item);
			$arr_x[]="job_category like '%".$item."%'";
		}
	}
	if(count($arr_x)>0){
		$str_x=implode(" or ",$arr_x);
		$str_where.=" and (".$str_x.")";
	}
	$arr_search_param["search_jobcategory"]=urlencode($get_search_jobcategory);
}else{
	$arr_search["jobcategorytxt"]="不限";
	$arr_search["search_jobcategory"]="";
}
if(isset($get_search_area)&&$get_search_area!=""){
	$arr_search["search_area"]=$get_search_area;
	$arr_search["areatxt"]=format_len($get_search_area,40,"...");
	$get_search_area=format_sql_safe($get_search_area);
	$get_search_area=str_replace(" ","%",$get_search_area);
	$str_where.=" and job_area like '%".$get_search_area."%'";
	$arr_search_param["search_area"]=urlencode($get_search_area);
}else{
	$arr_search["areatxt"]="不限";
	$arr_search["search_area"]="";
}


$this_param="";
$arr_x=array();
foreach($arr_search_param as $item=>$key){
	$arr_x[]=$item."=".$key;
}
$this_param=implode("&",$arr_x);
if($this_param!="") $this_param="&".$this_param;

$arr_job = array();
$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_job".$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_html($int_total, $get_page, $int_pagesize,"?app=joblist".$this_param);
$int_offset = $int_pagesize*($get_page-1);
$str_limit = " limit ".$int_offset.",".$int_pagesize;
$str_sql="SELECT * FROM ".DB_PRE."hr_job".$str_where." order by job_addtime desc".$str_limit;
$obj_result = $obj_db->query($str_sql);
$lng_x=1;
while($obj_rs = $obj_db->fetch_array($obj_result)){
	if($obj_rs["job_pay1"]==0&&$obj_rs["job_pay2"]==0){
		$obj_rs["pay"]="面议";
	}else{
		$obj_rs["pay"]=$obj_rs["job_pay1"]."~".$obj_rs["job_pay2"];
	}
	if($lng_x==0){
		$lng_x=1;
		$obj_rs["rowid"]=1;
	}else{
		$lng_x=0;
		$obj_rs["rowid"]=2;
	}
	$arr_company["id_".$obj_rs["job_user_id"]]="";
	$obj_rs["updatetime"]=format_date($obj_rs["job_updatetime"],"Y-m-d");
	$arr_userid[]=$obj_rs["job_user_id"];
	$obj_rs["url"]=$obj_tab_job->get_url($obj_rs["job_id"]);
	$arr_job[]=$obj_rs;
}
if(count($arr_userid)>0){
	$str_userid=implode(",",$arr_userid);
	$obj_result = $obj_db->query("SELECT company_user_id,company_name FROM ".DB_PRE."hr_company where company_user_id in(".$str_userid.")");
	while($obj_rs = $obj_db->fetch_array($obj_result)){
		$arr_company["id_".$obj_rs["company_user_id"]]=$obj_rs["company_name"];
	}
}

$this_cache_name=md5($str_sql);
?>