<?php
class cls_tab_other_msgbook extends cls_base_table
{
	private $tab_msgbook;
	private $obj_db;
	private $config=array();
	//构造函数
	function __construct()
	{
		parent::__construct();
		global $obj_db;
		$this->obj_db=$obj_db;
	}
	/*添加
	arr_fields:关健字数组
	*/
	private function _insert($arr_fields)
	{
		global $obj_ctl_user;
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["msg_msg"])||$arr_fields["msg_msg"]==""){
			$arr_return["err"]="留言内容不能为空！";
			return $arr_return;
		}
		if(!isset($arr_fields["msg_user_id"])&&intval($obj_ctl_user->id)>0){
			$arr_fields["msg_user_id"]=$obj_ctl_user->id;
		}
		$arr_return=parent::on_insert(DB_PRE."other_msgbook",$arr_fields);
		return $arr_return;
	}
	private function _update($arr_fields,$msg_where)
	{
		$str_msginfo=parent::on_update(DB_PRE."other_msgbook",$arr_fields,$msg_where);
		return $str_msginfo;
	}
	private function _del($msg_where)
	{
		$str_msginfo=parent::on_del(DB_PRE."other_msgbook",$msg_where);
		return $str_msginfo;
	}
	function on_save($arr_fields=array())
	{
		$arr_return=array("err"=>"","id"=>0);
		(!isset($arr_fields["msg_id"]))? $arr_fields["msg_id"]=0:$arr_fields["msg_id"]=intval($arr_fields["msg_id"]);
		$lng_id=$arr_fields["msg_id"];
		unset($arr_fields["msg_id"]);//释放id
		if($lng_id<1){
			$arr_fields["msg_addtime"]=TIME;
			$arr_fields["msg_ip"]=get_user_ip();
			if(!isset($arr_fields["msg_hide"])) $arr_fields["msg_hide"]=0;
			$arr_return=self::_insert($arr_fields);
		}else{
			$str_where="msg_id='".$lng_id."'";
			$arr_return=self::_update($arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		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=self::_del("msg_id in(".$str_id.")");
		return $arr_return;
	}

}
?>
