<?php
class cls_tab_hr_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->config["letter_max_num"]=1;//默认每个用户可添加一条求职信
	}
	/*添加
	arr_fields:关健字数组
	*/
	function on_save($arr_fields)
	{
		global $obj_ctl_user;
		$arr_return=array("err"=>"","id"=>0);
		(!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;
		}
		//保存操作
		unset($arr_fields["letter_id"]);//释放id
		if(!isset($arr_fields["letter_user_id"])||intval($arr_fields["letter_user_id"])<1){
			if($obj_ctl_user->id>0){
				$arr_fields["letter_user_id"]=$obj_ctl_user->id;
			}else{
				$arr_return["err"]="用户ID不能为空！";
				return $arr_return;
			}
		}
		$arr_fields["letter_updatetime"]=TIME;
		$obj_result = $this->obj_db->query("SELECT * FROM ".DB_PRE."hr_letter"." where letter_user_id='".$arr_fields["letter_user_id"]."'");
		if($obj_rs = $this->obj_db->fetch_array($obj_result))
		{
			$str_where="letter_id=".$obj_rs["letter_id"];
			$arr_return=parent::on_update(DB_PRE."hr_letter",$arr_fields,$str_where);
		}else{
			$arr_fields["letter_addtime"]=TIME;
			$arr_return=parent::on_insert(DB_PRE."hr_letter",$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_letter","letter_id in(".$str_id.")");
		return $arr_return;
	}

}
?>
