<?php
/*
===========================注册模块控制器
*/
class cls_tab_temp_fun_folder extends cls_base_table
{
	private $perms;
	//构造函数
	function __construct()
	{
		parent::__construct();
	}
	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["folder_id"]))? $arr_fields["folder_id"]=0:$arr_fields["folder_id"]=intval($arr_fields["folder_id"]);
		//保存操作
		$lng_id=$arr_fields["folder_id"];
		unset($arr_fields["folder_id"]);//释放id
		if($lng_id<1){
			global $obj_db;
			if(!isset($arr_fields["folder_pid"]) || empty($arr_fields["folder_pid"])) $arr_fields["folder_pid"]=0;
			$arr_return=self::_insert($arr_fields);
			if($arr_return["err"]==""){
				$str_pids="";
				$str_sql="select folder_pids from ".DB_PRE."temp_fun_folder where folder_id='".$arr_fields["folder_pid"]."'";
				$obj_result  = $obj_db->query($str_sql);
				if($obj_rs=$obj_db->fetch_array($obj_result)){
					$str_pids=$obj_rs["folder_pids"].",".$arr_return["id"];
				}else{
					$str_pids=$arr_return["id"];
				}
				//更新目录树
				$str_sql="update ".DB_PRE."temp_fun_folder set folder_pids='".$str_pids."' where folder_id='".$arr_return["id"]."'";
				$obj_db->execute($str_sql);
			}
		}else{
			global $obj_db;
			$str_where="folder_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"=>"");
		global $obj_db;
		$arr_return=array("err"=>"","id"=>0);
		$arr_fields["folder_addtime"]=TIME;
		if(!isset($arr_fields["folder_name"]) || empty($arr_fields["folder_name"])){
			$arr_return["err"]="请输入目录名称 !";
			return $arr_return;
		}
		$obj_result=$obj_db->query("select folder_id from ".DB_PRE."temp_fun_folder where folder_pid='".$arr_fields["folder_pid"]."' and folder_name='".$arr_fields["folder_name"]."'");
		if($obj_rs=$obj_db->fetch_array($obj_result)){
			$arr_return["err"]="目录已经存在 !";
			return $arr_return;
		}
		$arr_return=parent::on_insert(DB_PRE."temp_fun_folder",$arr_fields);
		return $arr_return;
	}
	//修改
	private function _update($arr_fields,$msg_where)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(isset($arr_fields["folder_name"]) && empty($arr_fields["folder_name"])){
			$arr_return["err"]="请输入目录名称 !";
			return $arr_return;
		}
		$arr_return=parent::on_update(DB_PRE."temp_fun_folder",$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_fun_folder","folder_id in(".$str_id.")");
		if($arr_return["err"]==""){
			//删除属于该目录的函数
			parent::on_del(DB_PRE."temp_fun","fun_folder_id in(".$str_id.")");
		}
		return $arr_return;
	}

}
?>
