<?php
require 'inc.php';
$obj_tab_area=new cls_tab_sys_area();
$obj_tab_jobcategory=new cls_tab_hr_job_category();

$tab_job=DB_PRE."hr_job";
$obj_tab_job=new cls_tab_hr_job();
if(!isset($int_pagesize)) $int_pagesize=10;
if(!isset($get_act)) $get_act="";
(!isset($get_page))? $get_page=0:$get_page=intval($get_page);

if(!isset($get_s_state)) $get_s_state=-101;
if(!isset($get_s_updatetime1)) $get_s_updatetime1="";
if(!isset($get_s_updatetime2)) $get_s_updatetime2="";
if(!isset($get_s_name)) $get_s_name="";

$this_is_job_html=$obj_tab_job->ishtml;


$page_footer_info=<<<HTML
HTML;
if($get_act=='del_sel')
{
	$arr_msg=$obj_tab_job->on_del($get_jobids);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

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

}
switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		if(isset($get_job_user_id)) $arr_fields["job_user_id"]=$get_job_user_id;
		$arr_fields["job_id"]=$get_id;
		$arr_fields["job_name"]=trim($get_job_name);
		$arr_fields["job_category"]=trim($get_job_category);
		$arr_fields["job_num"]=$get_job_num;
		$arr_fields["job_pay1"]=$get_job_pay1;
		$arr_fields["job_pay2"]=$get_job_pay2;
		$arr_fields["job_experience1"]=$get_job_experience1;
		$arr_fields["job_experience2"]=$get_job_experience2;
		if(!isset($get_job_validdate_is)){
			$lng_validdate=0;
			if(is_date($get_job_validdate)){
				$lng_validdate=format_date_int($get_job_validdate);
			}
			$arr_fields["job_validdate"]=$lng_validdate;
		}else{
			$arr_fields["job_validdate"]=0;
		}
		$arr_fields["job_area"]=trim($get_job_area);
		$arr_fields["job_marry"]=$get_job_marry;
		$arr_fields["job_degree"]=$get_job_degree;
		$arr_fields["job_sex"]=$get_job_sex;
		$arr_fields["job_age1"]=$get_job_age1;
		$arr_fields["job_age2"]=$get_job_age2;
		$arr_fields["job_nowarea"]=trim($get_job_nowarea);
		$arr_fields["job_intro"]=$get_job_intro;
		if(isset($get_job_linkmethod)){
			$arr_fields["job_linkman"]="";
			$arr_fields["job_tel"]="";
			$arr_fields["job_fax"]="";
			$arr_fields["job_email"]="";
			$arr_fields["job_address"]="";
			$arr_fields["job_linkmethod"]="1";
		}else{
			$arr_fields["job_linkman"]=trim($get_job_linkman);
			$arr_fields["job_tel"]=trim($get_job_tel);
			$arr_fields["job_fax"]=trim($get_job_fax);
			$arr_fields["job_email"]=trim($get_job_email);
			$arr_fields["job_address"]=trim($get_job_address);
			$arr_fields["job_linkmethod"]="0";
		}
		$arr_msg=$obj_tab_job->on_save($arr_fields);
		if($arr_msg["err"]=="") $get_id=$arr_msg["id"];
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'add':
	{
		$get_id=0;
		$arr_experience=$obj_tab_job->experience;
		$this_job_type=get_radio_html($obj_tab_job->type,"job_type");
		$this_category=$obj_tab_jobcategory->get_select_category("job_category");;
		$this_degree=get_select_html($obj_tab_job->degree);
		$this_pay=get_select_html($obj_tab_job->pay);
		include 'tpl/job.add.tpl.php';
		break;
	}
	case 'edit':
	{
		$arr_experience=$obj_tab_job->experience;
		if(!is_array($arr_experience)){
			$arr_pay=array(1,2,3,4,5,6,7,8);
		}
		$arr_company=array();
		$arr_job=array();
		$obj_result = $obj_db->query("SELECT * FROM ".$tab_job." where job_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["job_type"]=get_radio_html($obj_tab_job->type,"job_type",$obj_rs["job_type"]);
			$obj_rs["job_category"]=$obj_tab_jobcategory->get_select_category("job_category",$obj_rs["job_category"]);;
			$obj_rs["job_degree"]=get_select_html($obj_tab_job->degree,$obj_rs["job_degree"]);
			$obj_rs["job_pay1"]=get_select_html($obj_tab_job->pay,$obj_rs["job_pay1"]);
			$obj_rs["job_pay2"]=get_select_html($obj_tab_job->pay,$obj_rs["job_pay2"]);
			if($obj_rs["job_validdate"]<1){
				$obj_rs["job_validdate"]="";
			}else{
				$obj_rs["job_validdate"]=format_date($obj_rs["job_validdate"],"Y-m-d");
			}
			$arr_job = $obj_rs;
			$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_company where company_user_id='".$arr_job["job_user_id"]."'");
			if($obj_rs = $obj_db->fetch_array($obj_result))
			{
				$arr_company = $obj_rs;
			}
		}
		include 'tpl/job.edit.tpl.php';
		break;
	}
	case "html_exe":
	{
		//分页
		$int_pagesize=100;
		$arr_job=array();
		$str_jobid="";
		$str_where=" where 1";
		if(isset($get_jobids)){
			if(is_array($get_jobids)){
				$str_jobid=get_arr_id($get_jobids);
			}else{
				$arr_x=explode(",",$get_jobids);
				$arr_y=array();
				foreach($arr_x as $item){
					if(!is_numeric($item)) continue;
					$arr_y[]=$item;
				}
				$str_jobid=implode(",",$arr_y);
			}
			if($str_jobid!=""){
				$str_where.=" and job_id in(".$str_jobid.")";
			}
		}
		$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($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 job_id FROM ".DB_PRE."hr_job".$str_where." order by job_id desc".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_job[]=$obj_rs;
		}
		include 'tpl/job.html.tpl.php';
		break;
	}
	default:
	{
		$str_where=" where 1";
		//查询
		$get_issearch="";
		if($get_s_name!=""){
			$get_s_name=str_replace(" ","%",$get_s_name);
			$str_where.=" and (job_name like '%".$get_s_name."%'";
			$get_issearch="1";
			$arr_s_uid=array();
			$obj_result = $obj_db->query("SELECT company_user_id FROM ".DB_PRE."hr_company where company_name like '%".$get_s_name."%'");
			while($obj_rs = $obj_db->fetch_array($obj_result))
			{
				$arr_s_uid[]=$obj_rs["company_user_id"];
			}
			$str_x_where="";
			if(count($arr_s_uid)>0){
				$str_s_uid=implode(",",$arr_s_uid);
				$str_x_where=" or job_user_id in(".$str_s_uid.")";
			}
			$str_where.=$str_x_where.")";
		}
		if($get_s_state!=-101&&$get_s_state!=-99){
			$str_where.=" and job_state='".$get_s_state."'";
			$get_issearch="1";
		}
		//过期职位
		if($get_s_state==-99){
			$str_where.=" and job_validdate>0 and job_validdate<'".TIME."'";
			$get_issearch="1";
		}
		if(is_date($get_s_updatetime1)){
			$str_where.=" and FROM_UNIXTIME(job_updatetime)>='".$get_s_updatetime1."'";
			$get_issearch="1";
		}
		if(is_date($get_s_updatetime2)){
			$lng_x=format_date_int($get_s_updatetime2)+86400;
			$str_s_updatetime2=format_date($lng_x,"Y-m-d");
			$str_where.=" and FROM_UNIXTIME(job_updatetime)<'".$str_s_updatetime2."'";
			$get_issearch="1";
		}
		if(isset($get_fz_id) && intval($get_fz_id)>=0){
			$str_where.=" and job_fz_id='".$get_fz_id."'";
		}


		$arr_job = array();
		$arr_user_id=array();
		$arr_company=array();
		$arr_state=$obj_tab_job->state;
		$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".$tab_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($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 ".$tab_job.$str_where." order by job_id desc".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["state"]=array_search($obj_rs["job_state"],$arr_state);
			if($obj_rs["job_state"]<1){
				$obj_rs["state"]="<font color='#ff0000'>".$obj_rs["state"]."</font>";
			}
			$obj_rs["job_addtime"]=format_date($obj_rs["job_addtime"]);
			if($obj_rs["job_validdate"]<1){
				$obj_rs["validdate"]="无限";
			}else{
				$obj_rs["validdate"]=format_date($obj_rs["job_validdate"],"Y-m-d");
				if($obj_rs["job_validdate"]<TIME) $obj_rs["validdate"]="<font color='#ff0000'>".$obj_rs["validdate"]."</font>";
			}
			$arr_company["id_".$obj_rs["job_user_id"]]=array("company_name"=>"");
			$arr_user_id[]=$obj_rs["job_user_id"];
			$obj_rs["url"]=$obj_tab_job->get_url($obj_rs["job_id"]);
			$arr_job[] = $obj_rs;
		}
		if(count($arr_user_id)>0){
			$str_user_id=implode(",",$arr_user_id);
			$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_company where company_user_id in(".$str_user_id.")");
			while($obj_rs = $obj_db->fetch_array($obj_result))
			{
				$arr_company["id_".$obj_rs["company_user_id"]]=$obj_rs;
			}
		}
		include 'tpl/job.tpl.php';
	}
}


?>
