<?php
require "inc.php";
$is_err=0;
if(!isset($get_jobid)) $get_jobid="";
if(!$obj_ctl_user->is_login()){
	$obj_msg->alert("您还没有登录，不能申请职位！");
	$obj_msg->js("div_hide_show_parent('winJobApply');");
	$is_err=1;
}
if($obj_ctl_user->type!="personal"){
	$obj_msg->alert("您不是个人会员，不能申请职位！");
	$obj_msg->js("div_hide_show_parent('winJobApply');");
	$is_err=1;
}
if(!isset($get_jobid)||$get_jobid==""){
	$obj_msg->alert("请选择申请的职位！");
	$obj_msg->js("div_hide_show_parent('winJobApply');");
	$is_err=1;
}
if(isset($get_act)&&$get_act=="save"&&$is_err==0){
	$arr_id=explode(",",$get_jobid);
	$obj_tab_job_apply=new cls_tab_hr_job_apply();
	//过滤jobid
	$arr_jobid=array();
	foreach($arr_id as $item){
		$lng_jobid=intval($item);
		if($lng_jobid>0){
			$arr_jobid[]=$lng_jobid;
		}
	}
	$str_msg="";
	if(count($arr_jobid)>0){
		$str_jobid=implode(",",$arr_jobid);
		$obj_result = $obj_db->query("SELECT job_id,job_user_id FROM ".DB_PRE."hr_job where job_id in(".$str_jobid.")");
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_fields=array();
			$arr_fields["apply_job_id"]=$obj_rs["job_id"];
			$arr_fields["apply_intro"]=$get_apply_intro;
			$arr_fields["apply_user_id"]=$obj_ctl_user->id;
			$arr_fields["apply_company_user_id"]=$obj_rs["job_user_id"];
			$arr_msg=$obj_tab_job_apply->on_save($arr_fields);
			if($arr_msg["err"]!=""){
				$str_msg=$arr_msg["err"];
			}
		}
		if($str_msg!=""){
			$obj_msg->alert($str_msg);
			$obj_msg->js("div_hide_show_parent('winJobApply');");
		}else{
			$obj_msg->alert("成功发送职位申请！");
			$obj_msg->js("div_hide_show_parent('winJobApply');");
		}
	}else{
		$obj_msg->alert("申请职位不存在！");
		$obj_msg->js("div_hide_show_parent('winJobApply');");
	}

}
$this_letter="";
$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_letter where letter_user_id='".$obj_ctl_user->id."'");
if($obj_rs = $obj_db->fetch_array($obj_result))
{
	$this_letter = $obj_rs["letter_content"];
}
include 'tpl/job.apply.tpl.php';
?>