<?php
/*
===========================用户控制器
^^^^^^^^^^^^^^^^^^成员
------添加(on_insert)
------修改(on_update)
------删除(on_del)

*/
class cls_tab_hr_resume extends cls_base_table
{
	private $tab_resume;
	private $obj_db;
	private $config=array();
	private $perms=array();
	//构造函数
	function __construct()
	{
		global $obj_db,$obj_tab_sys_config;
		$arr_cfg_personal=$obj_tab_sys_config->get_model("personal");
		parent::__construct();
		$this->obj_db=$obj_db;
		$this->tab_resume=DB_PRE."hr_resume";
		$this->perms["jobtype"]=array("不限"=>"","全职"=>"全职","兼职"=>"兼职");//求职类型
		$this->perms["national"]=array("汉族"=>"汉族","少数民族"=>"少数民族","其它"=>"其它");//求职类型
		$this->perms["availability"]=array("我目前处于离职状态，可立即上岗"=>"我目前处于离职状态，可立即上岗","我目前在职，正考虑换个新环境（如有合适的工作机会，到岗时间一个月左右）"=>"我目前在职，正考虑换个新环境（如有合适的工作机会，到岗时间一个月左右）","我对现有工作还算满意，如有更好的工作机会，我也可以考虑。（到岗时间另议）"=>"我对现有工作还算满意，如有更好的工作机会，我也可以考虑。（到岗时间另议）","应届毕业生"=>"应届毕业生");//上岗时间
		$this->perms["jobpay"]=array("面议"=>"0","600以下"=>"600","600-1000"=>"1000","1000-1500"=>"1500","1500-3000"=>"3000","3000-5000"=>"5000","5000以上"=>"6000");//待遇要求
		$this->perms["marry"]=array("未婚"=>"未婚","已婚"=>"已婚");//求职类型
		$this->perms["degree"]=array("博士后"=>"9","博士"=>"8","硕士"=>"7","本科"=>"6","大专"=>"5","中专"=>"4","高中"=>"3","初中"=>"2","小学"=>"1");//求职类型
		$this->perms["vouchertype"]=array("身份证"=>"身份证","学生证"=>"学生证","占住证"=>"占住证");//证件类型
		$this->perms["zzmm"]=array("中共党员"=>"中共党员","民主党派"=>"民主党派","共青团员"=>"共青团员","群众"=>"群众");//政治面貌
		$this->perms["state"]=array("审核"=>"1","待审"=>"0");//简历状态,注意，大于零表示有效，否则无效，前台搜索不到,放在最前面的为新简历默认状态
		if(isset($arr_cfg_personal['job_type'])) $this->perms["jobtype"]=$arr_cfg_personal['job_type'];
		if(isset($arr_cfg_personal['national'])) $this->perms["national"]=$arr_cfg_personal['national'];
		if(isset($arr_cfg_personal['availability'])) $this->perms["availability"]=$arr_cfg_personal['availability'];
		if(isset($arr_cfg_personal['jobpay'])) $this->perms["jobpay"]=$arr_cfg_personal['jobpay'];
		if(isset($arr_cfg_personal['degree'])) $this->perms["degree"]=$arr_cfg_personal['degree'];
		if(isset($arr_cfg_personal['vouchertype'])) $this->perms["vouchertype"]=$arr_cfg_personal['vouchertype'];
		if(isset($arr_cfg_personal['zzmm'])) $this->perms["zzmm"]=$arr_cfg_personal['zzmm'];
		// 是否生成静态文件
		$this->perms["ishtml"]=false;
		if(isset($arr_cfg_personal["resume_htmlpath"])&&$arr_cfg_personal["resume_htmlpath"]!=""){
			$str_dir=$arr_cfg_personal["resume_htmlpath"];
			$str_dirpath=get_real_path("",$str_dir);
			if(is_dir($str_dirpath)){
				$this->perms["ishtml"]=true;
			}
		}

	}
	/*添加
	arr_fields:关健字数组
	*/
	function on_save($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		(!isset($arr_fields["resume_id"]))? $arr_fields["resume_id"]=0:$arr_fields["resume_id"]=intval($arr_fields["resume_id"]);
		//格式化数据
		if(isset($arr_fields["resume_name"])&&$arr_fields["resume_name"]==""){
			$arr_return["err"]="姓名不能为空！";
			return $arr_return;
		}
		if(isset($arr_fields["resume_uname"])&&$arr_fields["resume_uname"]==""){
			$arr_return["err"]="用户名不能为空！";
			return $arr_return;
		}
		if(isset($arr_fields["resume_tel"])&&$arr_fields["resume_tel"]==""){
			$arr_return["err"]="联系电话不能为空！";
			return $arr_return;
		}
		if(isset($arr_fields["resume_birthday"])&&is_date($arr_fields["resume_birthday"])){
			$arr_fields["resume_birthday"]=format_date_int($arr_fields["resume_birthday"]);
		}
		//改求职意向
		$arr_fields["resume_jobwill"]="";
		if(isset($arr_fields["resume_jobname"])) $arr_fields["resume_jobwill"]=$arr_fields["resume_jobname"];
		if(isset($arr_fields["resume_jobcategory"])&&$arr_fields["resume_jobwill"]==""){
			$arr_fields["resume_jobwill"]=$arr_fields["resume_jobcategory"];
		}
		//保存操作
		$lng_id=$arr_fields["resume_id"];
		unset($arr_fields["resume_id"]);//释放id
		$arr_fields["resume_updatetime"]=TIME;
		if($lng_id<1){
			$arr_fields["resume_addtime"]=TIME;
			$arr_return=self::_insert($arr_fields);
		}else{
			$str_where="resume_id='".$lng_id."'";
			$arr_return=self::_update($arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		return $arr_return;
	}
	function _insert($arr_fields)
	{
		global $obj_tab_sys_config,$obj_ctl_domain;
		global $obj_ctl_user;
		$arr_cfg_personal=$obj_tab_sys_config->get_model("personal");
		if(!isset($arr_fields["resume_state"])){
			$str_resume_state=0;
			if(isset($arr_cfg_personal["resume_state"])) $str_cresume_state=intval($arr_cfg_personal["resume_state"]);
			$arr_fields["resume_state"]=$str_cresume_state;
		}
		if(!isset($arr_fields["resume_user_id"])||intval($arr_fields["resume_user_id"])<1){
			if(!$obj_ctl_user->is_login()||$obj_ctl_user->type!="personal"){
				$arr_return["err"]="用户不存在！";
				return $arr_return;
			}else{
				$arr_fields["resume_user_id"]=$obj_ctl_user->id;
			}
		}
		//是否从分站注册
		if(gettype($obj_ctl_domain)=="object" && $obj_ctl_domain->type=="fz"){
			$arr_fields["resume_fz_id"]=$obj_ctl_domain->id;
		}

		$obj_result = $this->obj_db->query("SELECT * FROM ".$this->tab_resume." where resume_user_id='".$arr_fields["resume_user_id"]."'");
		if($obj_rs = $this->obj_db->fetch_array($obj_result))
		{
			$arr_return["err"]="已经有一份简历存在！";
			return $arr_return;
		}

		$arr_return=array("err"=>"","id"=>0);
		$arr_return=parent::on_insert($this->tab_resume,$arr_fields);
		return $arr_return;
	}
	function _update($arr_fields,$msg_where)
	{
		$arr_return=array("err"=>"","id"=>0);
		$arr_return=parent::on_update($this->tab_resume,$arr_fields,$msg_where);
		return $arr_return;
	}
	function on_del($arr_id)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$arr_return=parent::on_del($this->tab_resume,"resume_id in(".$str_id.")");

		return $arr_return;
	}
	//改变简历的状态,值来源于配置信息 state
	function on_state($arr_id,$msg_val)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$msg_val=intval($msg_val);
		$arr_return["err"]=$this->obj_db->execute("update ".DB_PRE."hr_resume set resume_state='".$msg_val."' where resume_id in(".$str_id.")");
		return $arr_return;
	}
	//改变头像的状态
	function on_photo($arr_id,$msg_val)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$msg_val=intval($msg_val);
		if($msg_val>=0){
			$arr_return["err"]=$this->obj_db->execute("update ".DB_PRE."hr_resume set resume_photo_state='".$msg_val."' where resume_id in(".$str_id.")");
		}else{
		//清除头像
			$arr_return["err"]=$this->obj_db->execute("update ".DB_PRE."hr_resume set resume_photo_state=0,resume_photo='' where resume_id in(".$str_id.")");
		}
		return $arr_return;
	}
	//检查简历有效性，只有完成系统设置的必填资料的简历才有效,通过 resume_progress 判断
	function on_progress($msg_index,$msg_val){
		global $obj_ctl_user,$obj_tab_sys_config;
		$arr_cfg_personal=$obj_tab_sys_config->get_model("personal");
		$msg_index=intval($msg_index);
		$msg_val=intval($msg_val);
		$obj_result = $this->obj_db->query("SELECT resume_progress_info FROM ".DB_PRE."hr_resume where resume_user_id='".$obj_ctl_user->id."'");
		if($obj_rs = $this->obj_db->fetch_array($obj_result))
		{
			$arr_x = explode(",",$obj_rs["resume_progress_info"]);
			$lng_x=count($arr_x);
			for($i=0;$i<6;$i++){
				if($i==$msg_index){
					$arr_val[]=$msg_val;
				}elseif($lng_x>$i){
					$arr_val[]=$arr_x[$i];
				}else{
					$arr_val[]=0;
				}
			}
			$str_progress=1;
			if(isset($arr_cfg_personal["resume_progress"])&&is_array($arr_cfg_personal["resume_progress"])){
				$lng_x=count($arr_cfg_personal["resume_progress"]);
				$arr_x=$arr_cfg_personal["resume_progress"];
				if($lng_x>6) $lng_x=6;
				for($i=0;$i<$lng_x;$i++){
					if($arr_val[$i]<$arr_x[$i]){
						$str_progress=0;
						break;
					}
				}
			}else{
				$arr_x=array(1,1,1,0,0,1);
				$lng_x=6;
				for($i=0;$i<$lng_x;$i++){
					if($arr_val[$i]<$arr_x[$i]){
						$str_progress=0;
						break;
					}
				}
			}
			$str_val=implode(",",$arr_val);
			$this->obj_db->execute("update ".DB_PRE."hr_resume set resume_progress_info='".$str_val."',resume_progress=".$str_progress." where resume_user_id='".$obj_ctl_user->id."'");
		}
	}

	function get_htmlinfo($msg_id)
	{
		global $obj_tab_sys_config;
		$arr_cfg_personal=$obj_tab_sys_config->get_model("personal");

		$this_html=array("path"=>"","url"=>"");
		if($msg_id<1) return $this_html;
		if(isset($arr_cfg_personal["resume_htmlpath"])&&$arr_cfg_personal["resume_htmlpath"]!=""){
			$str_dir=$arr_cfg_personal["resume_htmlpath"];
			$str_file=format_path($str_dir."/".$msg_id.".html");
			$str_dirpath=get_real_path("",$str_dir);
			$str_path=get_real_path("",$str_file);
			if(is_dir($str_dirpath)){
				$this_html["path"]=$str_path;
				$this_html["url"]=WEB_URL.$str_file;
			}
		}
		return $this_html;
	}
	function get_url($msg_id){
		global $obj_tab_sys_config;
		$arr_cfg_personal=$obj_tab_sys_config->get_model("personal");
		if($msg_id<1) return "";
		$str_return=WEB_URL."/index.php?app=resumeview&id=".$msg_id;
		if(isset($arr_cfg_personal["resume_htmlpath"])&&$arr_cfg_personal["resume_htmlpath"]!=""){
			$str_dir=$arr_cfg_personal["resume_htmlpath"];
			$str_file=format_path($str_dir."/".$msg_id.".html");
			$str_return=WEB_URL.$str_file;
		}
		return $str_return;
	}
	function __get($name){
		if(isset($this->perms["$name"])){
			return $this->perms["$name"];
		}
	}
	function __set($name,$value){
		if(isset($this->perms["$name"])){
			$this->perms["$name"]=$value;
		}else{
		}
	}


}
?>
