<?php
/*
===========================注册模块控制器
*/
class cls_tab_temp extends cls_base_table
{
	private $perms;
	//构造函数
	function __construct()
	{
		parent::__construct();
		global $obj_db;
		$this->obj_db=$obj_db;
		$this->perms["state"]=array("关闭"=>0,"开启"=>1);
		$this->perms["fields_type"]=array("文本"=>"txt","数字"=>"int","电话"=>"tel","邮箱"=>"email","图片"=>"pic","附件"=>"attatch","地区"=>"area","日期"=>"date","内容"=>"cont","文章列表"=>"list","图片列表"=>"piclist");
		$this->perms["industry"]=array("普通","酒店","餐饮","学校","IT企业","旅游","汔车","礼品","装饰","房产");
	}
	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["temp_id"]))? $arr_fields["temp_id"]=0:$arr_fields["temp_id"]=intval($arr_fields["temp_id"]);
		//保存操作
		$lng_id=$arr_fields["temp_id"];
		unset($arr_fields["temp_id"]);//释放id
		if($lng_id<1){
			$arr_return=self::_insert($arr_fields);
		}else{
			$str_where="temp_id='".$lng_id."'";
			$arr_return=self::_update($arr_fields,$str_where);
			$arr_return["id"]=$lng_id;
		}
		return $arr_return;
	}
	function get_fields($msg_id,$msg_cont=""){
		global $obj_db;
		$arr_fields=array();
		$obj_result=$obj_db->query("select temp_fields_cont from ".DB_PRE."temp where temp_id=".$msg_id);
		if($obj_rs=$obj_db->fetch_array($obj_result)){
			$arr_fields=unserialize($obj_rs["temp_fields_cont"]);
		}
		$arr_cont=array();
		$lng_x=count($arr_fields);
		if($msg_cont!=""){
			$arr_cont=unserialize($msg_cont);
		}
		for($i=0;$i<$lng_x;$i++){
			if(isset($arr_cont[$arr_fields[$i]["name"]])){
				$arr_fields[$i]["value"]=$arr_cont[$arr_fields[$i]["name"]];
			}
			$arr_fields[$i]["htmlbox"]=self::get_htmlbox($arr_fields[$i],$i);
		}
		return $arr_fields;
	}
	function get_htmlbox($arr_item,$msg_i){
		global $obj_tab_area;
		$str_html="";
		switch($arr_item["type"]){
			case "cont":
				$str_html="<textarea name='N_temp_".$msg_i."' id='Id_temp_".$msg_i."' style='width:500px;height:120px'>".$arr_item["value"]."</textarea>";
				break;
			case "pic":
				$str_html="<input type='input' name='N_temp_".$msg_i."' id='Id_temp_".$msg_i."' value='".addslashes($arr_item["value"])."' size=50>&nbsp;<input type='button' name='btnpic' value='选择' style='border:1px #000000 solid' onclick=\"dialog_winPic('Id_temp_".$msg_i."');\"><br><iframe name='frm_upload_pic".$msg_i."' src='".WEB_URL."/plus/dialog/upload_attatch.php?type=pic&obj_id=Id_temp_".$msg_i."' width='300px' height='30px' frameborder=0 scrolling='no'></iframe>";
				break;
			case "attatch":
				$str_html="<input type='input' name='N_temp_".$msg_i."' id='Id_temp_".$msg_i."' value='".addslashes($arr_item["value"])."' size=50>&nbsp;<input type='button' name='btnpic' value='选择' style='border:1px #000000 solid' onclick=\"dialog_winPic('Id_temp_".$msg_i."');\"><br><iframe name='frm_upload_pic".$msg_i."' src='".WEB_URL."/plus/dialog/upload_attatch.php?type=attatch&obj_id=Id_temp_".$msg_i."' width='300px' height='30px' frameborder=0 scrolling='no'></iframe>";
				break;
			case "area":
				if(strtolower(gettype($obj_tab_area))!="object"){
					require_once(SYS_ROOT.'/cls_tab/tab.sys.area.php');
					$obj_tab_area=new cls_tab_sys_area();
				}
				$str_html=$obj_tab_area->get_select_area('N_temp_'.$msg_i,$arr_item["value"]);
				break;
			case "date":
				$str_html='<input type="text" name="N_temp_'.$msg_i.'" value="'.addslashes($arr_item["value"]).'" onfocus="setday(this);">';
				break;
			default:
				$str_html="<input type='text' name='N_temp_".$msg_i."' value='".addslashes($arr_item["value"])."'>";
		}
		return $str_html;
	}
	//添加
	private function _insert($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["temp_title"])||$arr_fields["temp_title"]==""){
			$arr_return["err"]="分站名称不能为空！";
			return $arr_return;
		}
		$arr_fields["temp_addtime"]=TIME;
		$arr_return=parent::on_insert(DB_PRE."temp",$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."temp",$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(DB_PRE."temp","temp_id in(".$str_id.")");
		return $arr_return;
	}

}
?>
