<?php
/*
===========================注册模块控制器
*/
class cls_tab_hr_photo extends cls_base_table
{
	private $perms;
	//构造函数
	function __construct()
	{
		parent::__construct();
		global $obj_db;
		$this->obj_db=$obj_db;
		$this->perms["state"]=array("待审"=>0,"通过"=>1,"隐藏"=>-1);
	}
	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{
		}
	}
	//保存
	function on_save($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		(!isset($arr_fields["photo_id"]))? $arr_fields["photo_id"]=0:$arr_fields["photo_id"]=intval($arr_fields["photo_id"]);
		//保存操作
		$lng_id=$arr_fields["photo_id"];
		unset($arr_fields["photo_id"]);//释放id
		$arr_fields["photo_updatetime"]=TIME;
		if($lng_id<1){
			$arr_fields["photo_addtime"]=TIME;
			$arr_return=self::_insert($arr_fields);
		}else{
			$str_where="photo_id='".$lng_id."'";
			$arr_return=self::_update($arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		return $arr_return;
	}
	//添加
	private function _insert($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["photo_url"])||$arr_fields["photo_url"]==""){
			$arr_return["err"]="相册地址不存在";
			return $arr_return;
		}
		$arr_return=parent::on_insert(DB_PRE."hr_photo",$arr_fields);
		return $arr_return;
	}
	//修改
	private function _update($arr_fields,$msg_where)
	{
		$arr_return=array("err"=>"","id"=>0);
		$arr_return=parent::on_update(DB_PRE."hr_photo",$arr_fields,$msg_where);
		return $arr_return;
	}
	//删除
	function on_del($arr_id,$lng_uid=0)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$str_where="photo_id in(".$str_id.")";
		if($lng_uid>0) $str_where.=" and photo_user_id=".$lng_uid;
		$arr_return=parent::on_del(DB_PRE."hr_photo",$str_where);
		return $arr_return;
	}
	function on_state($arr_id,$msg_val,$lng_uid=0){
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要设置的记录！";
			return $arr_return;
		}
		global $obj_db;
		$str_where=" where photo_id in(".$str_id.")";
		if($lng_uid>0) $str_where.=" and photo_state!=0 and photo_user_id=".$lng_uid;
		$arr_return["err"]=$obj_db->execute("update ".DB_PRE."hr_photo set photo_state=".intval($msg_val).$str_where);
		return $arr_return;
	}
}
?>
