<?php
$obj_tab_jobcategory=new cls_tab_hr_job_category();
$obj_tab_company=new cls_tab_hr_company();
$obj_tab_job=new cls_tab_hr_job();
(!isset($get_id))? $get_id=0:$get_id=intval($get_id);
$arr_company=array();
$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_company where company_user_id='".$obj_ctl_user->id."'");
if($obj_rs = $obj_db->fetch_array($obj_result))
{
	$arr_company=$obj_rs;
}else{
	$obj_msg->alert("请先完善您的基本信息，再发布招聘!");
	$obj_msg->go_url("?app=base");
	exit;
}
switch($get_app){
	case "job_edit":
		$obj_tab_area=new cls_tab_sys_area();
		$arr_job=array();
		if($get_id>0){
			$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_job where job_id='".$get_id."' and job_user_id=".$obj_ctl_user->id);
			if($obj_rs = $obj_db->fetch_array($obj_result))
			{
				$obj_rs["job_pay0"]=1;
				if($obj_rs["job_pay1"]>0&&$obj_rs["job_pay2"]>0){
					$obj_rs["job_pay0"]=0;
				}
				$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"]);
				$obj_rs["job_category"]=$obj_tab_jobcategory->get_select_category("job_category",$obj_rs["job_category"]);
				($obj_rs["job_validdate"]>0)? $obj_rs["job_validdate"]=format_date($obj_rs["job_validdate"]):$obj_rs["job_validdate"]="";
				$obj_rs["area"]=$obj_tab_area->get_select_area("job_area",$obj_rs["job_area"]);
				$arr_job = $obj_rs;
			}
		}
		if(count($arr_job)<1){
			$arr_x=$obj_db->get_fields(DB_PRE."hr_job");
			foreach($arr_x as $item){
				$arr_job[$item]="";
			}
			$arr_job["job_validdate"]=format_date(TIME+2592000);
			$arr_job["job_degree"]=get_select_html($obj_tab_job->degree,"job_degree");
			$arr_job["job_pay0"]=0;
			$arr_job["job_pay1"]=get_select_html($obj_tab_job->pay);
			$arr_job["job_pay2"]=get_select_html($obj_tab_job->pay);
			$arr_job["job_category"]=$obj_tab_jobcategory->get_select_category("job_category");;
			$arr_job["area"]=$obj_tab_area->get_select_area("job_area");
		}
		break;
	case "job_save":
		$arr_fields=array();
		$arr_msg=array();
		$arr_fields["job_id"]=$get_id;
		if($get_id>0){
			$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_job where job_id='".$get_id."' and job_user_id=".$obj_ctl_user->id);
			if(!$obj_rs = $obj_db->fetch_array($obj_result))
			{
				$obj_msg->alert("保存招聘信息出错!");
				$obj_msg->go_url("?app=job");
				exit;
			}
		}
		$arr_fields["job_user_id"]=$obj_ctl_user->id;
		if(isset($get_job_name)) $arr_fields["job_name"]=$get_job_name;
		if(isset($get_job_category)) $arr_fields["job_category"]=$get_job_category;
		if(isset($get_job_num)) $arr_fields["job_num"]=$get_job_num;
		if(isset($get_job_pay)) $arr_fields["job_pay"]=$get_job_pay;
		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;
		}
		if(isset($get_job_area)) $arr_fields["job_area"]=$get_job_area;
		if(isset($get_job_degree)) $arr_fields["job_degree"]=$get_job_degree;
		if(isset($get_job_sex)) $arr_fields["job_sex"]=$get_job_sex;
		if(isset($get_job_age1)) $arr_fields["job_age1"]=$get_job_age1;
		if(isset($get_job_age2)) $arr_fields["job_age2"]=$get_job_age2;
		if(isset($get_job_pay1)) $arr_fields["job_pay1"]=$get_job_pay1;
		if(isset($get_job_pay2)) $arr_fields["job_pay2"]=$get_job_pay2;
		if(isset($get_job_pay0)&&$get_job_pay0==1){
			$arr_fields["job_pay1"]=0;
			$arr_fields["job_pay2"]=0;
		}
		if(isset($get_job_nowarea)) $arr_fields["job_nowarea"]=$get_job_nowarea;
		if(isset($get_job_intro)) $arr_fields["job_intro"]=$get_job_intro;
		if(isset($get_job_linkman)) $arr_fields["job_linkman"]=$get_job_linkman;
		if(isset($get_job_tel)) $arr_fields["job_tel"]=$get_job_tel;
		if(isset($get_job_fax)) $arr_fields["job_fax"]=$get_job_fax;
		if(isset($get_job_email)) $arr_fields["job_email"]=$get_job_email;
		if(isset($get_job_address)) $arr_fields["job_address"]=$get_job_address;
		$str_job_linkmethod="";
		if(isset($get_job_linkmethod)) $str_job_linkmethod=$get_job_linkmethod;
		$arr_fields["job_linkmethod"]=$str_job_linkmethod;
		if(count($arr_fields)>2){
			$arr_msg=$obj_tab_job->on_save($arr_fields);
		}
		if($arr_msg["err"]==""){
			$get_id=$arr_msg["id"];
			$this_company_id=$arr_company["company_id"];
			//是否生成企业html文件
			$this_company_html=$obj_tab_company->get_htmlinfo($arr_company["company_id"]);
			$this_job_id=$get_id;
			//是否生成职位html文件
			$this_job_html=$obj_tab_job->get_htmlinfo($get_id);
		}
		break;
	default:
		if(isset($get_act)&&$get_act=="del"&&isset($get_id)&&$get_id>0){
			$arr_msg=$obj_tab_job->on_del($get_id);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
		if(isset($get_act)&&$get_act=="del_s"&&isset($get_jobids)){
			$arr_msg=$obj_tab_job->on_del($get_jobids);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
		if(isset($get_act)&&$get_act=="pause"&&isset($get_id)&&$get_id>0){
			$arr_msg=$obj_tab_job->on_pause($get_id);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
		if(isset($get_act)&&$get_act=="pause_s"&&isset($get_jobids)){
			$arr_msg=$obj_tab_job->on_pause($get_jobids);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
		if(isset($get_act)&&$get_act=="pause_cancel"&&isset($get_id)&&$get_id>0){
			$arr_msg=$obj_tab_job->on_pause_cancel($get_id);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
		$str_where=" where job_user_id='".$obj_ctl_user->id."'";
		if(!isset($get_state)) $get_state="";
		if($get_state==1){
			$str_where.=" and job_state>=0 and (job_validdate=0 or job_validdate>'".TIME."')";
		}else if($get_state==2){
			$str_where.=" and job_state=-2";
		}else if($get_state==3){
			$str_where.=" and job_validdate>0 and job_validdate<'".TIME."'";
		}
		$arr_job=array();
		$arr_state=$obj_tab_job->state;
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_job".$str_where);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["state"]=array_search($obj_rs["job_state"],$arr_state);
			if($obj_rs["job_validdate"]>0){
				$obj_rs["validdate"]=format_date($obj_rs["job_validdate"]);
			}else{
				$obj_rs["validdate"]="不限";
			}
			$obj_rs["addtime"]=format_date($obj_rs["job_addtime"]);
			$arr_job[]=$obj_rs;
		}
}
?>