<?php
class cls_tab_hr_resume_letter extends cls_base_table
{
	private $tab_jobletter;
	private $obj_db;
	private $config=array();
	//构造函数
	function __construct()
	{
		global $obj_db;
		parent::__construct();
		$this->obj_db=$obj_db;
		$this->tab_jobletter=DB_PRE."hr_resume_letter";
		$this->config["letter_max_num"]=1;//默认每个用户可添加一条求职信
	}
	/*添加
	arr_fields:关健字数组
	*/
	function on_save($arr_fields,$str_where="")
	{
		$arr_return=array("err"=>"","id"=>0);
		$arr_letter=array();
		(!isset($arr_fields["letter_id"]))? $arr_fields["letter_id"]=0:$arr_fields["letter_id"]=intval($arr_fields["letter_id"]);
		//格式化数据
		if(!isset($arr_fields["letter_content"])||$arr_fields["letter_content"]==""){
			$arr_return["err"]="求职信内容不能为空！";
			return $arr_return;
		}
		//保存操作
		$lng_id=$arr_fields["letter_id"];
		unset($arr_fields["letter_id"]);//释放id
		$arr_fields["letter_updatetime"]=TIME;
		if($lng_id<1){
			$arr_fields["letter_addtime"]=TIME;
			$arr_return=self::_insert($arr_fields);
		}else{
			$str_where="letter_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_ctl_user;
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["letter_uid"])||intval($arr_fields["letter_uid"])<1){
			if($obj_ctl_user->id>0){
				$arr_fields["letter_uid"]=$obj_ctl_user->id;
			}else{
				$arr_return["err"]="用户ID不能为空！";
				return $arr_return;
			}
		}
		//判断是否重名
		if(isset($this->config["letter_max_num"])){
			$obj_rs = $this->obj_db->get_one("SELECT count(*) as num FROM ".$this->tab_jobletter." where letter_uid='".$arr_fields["letter_uid"]."'");
			if($obj_rs["num"]>=$this->config["letter_max_num"])
			{
				$arr_return["err"]="求职信最多可设".$this->config["letter_max_num"]."条！";
				return $arr_return;
			}
		}
		$arr_return=parent::on_insert($this->tab_jobletter,$arr_fields);
		return $arr_return;
	}
	function _update($arr_fields,$msg_where)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(isset($arr_fields["letter_uid"])) unset($arr_fields["letter_uid"]);
		$arr_return=parent::on_update($this->tab_jobletter,$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_jobletter,"letter_id in(".$str_id.")");
		return $arr_return;
	}

}
?>
