<?php
require 'inc.php';
$obj_tab_config=new cls_tab_sys_config();

$tab_config=DB_PRE."sys_config";

if(!isset($get_act)) $get_act="";
(!isset($get_id))?$get_id=0:$get_id=intval($get_id);
$arr_model=array();
$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_model order by model_sort");
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$arr_model[]=$obj_rs;
}
if(!isset($get_model_id)){
	if(count($arr_model)>0){
		$get_model_id=$arr_model[0]["model_id"];
	}else{
		$get_model_id=0;
	}
}

$page_footer_info=<<<HTML
<input type='hidden' name='model_id' value='$get_model_id'>
HTML;


if($get_act=="del"&&$get_id>0)
{
	$arr_msg=$obj_tab_config->on_del($get_id);
	if($arr_msg["err"]=="")
	{
		$obj_msg->alert("成功注销！");
	}
	else
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
if($get_act=="update")
{
		$str_msginfo="";
		$arr_fields=array();
		for($i=0;$i<count($get_selid);$i++)
		{
			(isset($get_selid[$i]))?$str_id=intval($get_selid[$i]):$str_id=0;
			(isset($get_config_name[$i]))?$str_config_name=$get_config_name[$i]:$str_config_name="";
			(isset($get_config_val[$i]))?$str_config_val=$get_config_val[$i]:$str_config_val="";
			(isset($get_config_intro[$i]))?$str_config_intro=$get_config_intro[$i]:$str_config_intro="";
			(isset($get_config_readonly[$i]))?$str_config_readonly=intval($get_config_readonly[$i]):$str_config_readonly=0;
			if($str_id>0)
			{
				//处理多选
				$str_dim="get_config_val_".$str_id;
				if(isset($$str_dim))
				{
					$str_config_val=implode("|",$$str_dim);
				}
				//处理布尔
				$str_dim="get_config_val_bool_".$str_id;
				if(isset($$str_dim))
				{
					$str_config_val=intval($$str_dim);
				}
				$arr_x=array();
				$arr_x["config_name"]=$str_config_name;
				$arr_x["config_val"]=$str_config_val;
				$arr_x["config_intro"]=$str_config_intro;
				$arr_x["config_updatetime"]=TIME;
				$arr_x["config_id"]=$str_id;
				$arr_fields[]=$arr_x;

			}
		}
		if(count($arr_fields)>0){
			$arr_msg=$obj_tab_config->on_saveall($arr_fields);
			if($arr_msg["err"]!="")
			{
				$obj_msg->alert($arr_msg["err"]);
			}
		}
}
switch($get_act)
{
	case "save":
	{
		$arr_fields=array();
		$arr_fields["config_id"]=$get_id;
		$arr_fields["config_name"]=$get_config_name;
		$arr_fields["config_val"]=$get_config_val;
		$arr_fields["config_intro"]=$get_config_intro;
		$arr_fields["config_type"]=$get_config_type;
		$arr_fields["config_list"]=$get_config_list;
		$arr_fields["config_model_id"]=$get_config_model_id;
		$arr_msg=$obj_tab_config->on_save($arr_fields);
		$arr_msg["act"]="save";
		include 'tpl/_msg.tpl.php';
		break;
	}
	case "edit":
	{
		$arr_config = array();
		$obj_result = $obj_db->query("SELECT * FROM ".$tab_config." where config_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_config = $obj_rs;
		}
		include 'tpl/config.edit.tpl.php';
		break;
	}
	case "add":
	{
		$get_id=0;
		include 'tpl/config.add.tpl.php';
		break;
	}
	default:
	{
		$arr_config = array();
		$str_where=" where config_model_id='".$get_model_id."'";
		$obj_result = $obj_db->query("SELECT * FROM ".$tab_config.$str_where);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			if($obj_rs["config_list"]!="")	$obj_rs["config_list"]=$obj_tab_config->get_config_list($obj_rs["config_list"]);
			$arr_config[] = $obj_rs;
		}
		include 'tpl/config.tpl.php';
	}
}

?>
