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

*/
class cls_tab_hr_job_collect extends cls_base_table
{
	private $obj_db;
	//构造函数
	function __construct()
	{
		global $obj_db;
		parent::__construct();
		$this->obj_db=$obj_db;
	}
	/*添加
	arr_fields:关健字数组
	*/
	function on_save($arr_fields,$str_where="")
	{
		$arr_return=array("err"=>"","id"=>0);
		//保存操作
		if(isset($arr_fields["collect_id"])) unset($arr_fields["collect_id"]);//释放id
		//检查最大收藏数
		global $obj_tab_sys_config,$obj_ctl_user;
		if($obj_tab_sys_config->get_val("personal","max_job_collect_num")!=""){
			$obj_rs   = $this->obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_job_collect where collect_user_id='".$obj_ctl_user->id."'");
			$lng_collectnum=$obj_rs["num"];
			$lng_val=intval($obj_tab_sys_config->get_val("personal","max_job_collect_num"));
			if($lng_val>0&&$lng_val<=$lng_collectnum){
				$arr_return["err"]="您的最多能收藏".$lng_val."次职位,请删除以前没用收藏的职位！";
			}else if($lng_val==0){
				$arr_return["err"]="系统关闭了个人收藏职位的功能，请联系工作人员！";
			}
		}
		$arr_fields["collect_addtime"]=TIME;
		$arr_return=self::_insert($arr_fields);
		return $arr_return;
	}
	function _insert($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["collect_user_id"])||intval($arr_fields["collect_user_id"])<1){
			$arr_return["err"]="您不是个人会员，不能收藏职位！";
			return $arr_return;
		}
		if(!isset($arr_fields["collect_job_id"])||intval($arr_fields["collect_job_id"])<1){
			$arr_return["err"]="收藏职位不存在！";
			return $arr_return;
		}
		$obj_result = $this->obj_db->query("SELECT * FROM ".DB_PRE."hr_job_collect where collect_user_id='".$arr_fields["collect_user_id"]."' and collect_job_id='".$arr_fields["collect_job_id"]."'");
		if($obj_rs = $this->obj_db->fetch_array($obj_result))
		{
			$arr_return["err"]="该职位您已经收藏过了！";
			return $arr_return;
		}
		if(defined("SYS_OPEN_FZ") && SYS_OPEN_FZ=="1"){
			global $obj_ctl_user;
			$arr_fields["collect_fz_id"]=$obj_ctl_user->get_fz_id();
		}
		$arr_return=parent::on_insert(DB_PRE."hr_job_collect",$arr_fields);
		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(DB_PRE."hr_job_collect","collect_id in(".$str_id.")");

		return $arr_return;
	}
}
?>
