<?php
require 'inc.php';
$obj_tab_area=new cls_tab_sys_area();
$tab_area=DB_PRE."sys_area";

if(!isset($int_pagesize)) $int_pagesize=10;
if(!isset($get_act)) $get_act="";
(!isset($get_page))? $get_page=0:$get_page=intval($get_page);
(!isset($get_id))? $get_id=0:$get_id=intval($get_id);
(isset($get_me_pid))?$get_me_pid=intval($get_me_pid):$get_me_pid=0;
(!isset($get_me_categoryid))?$get_me_categoryid=0:$get_me_categoryid=intval($get_me_categoryid);
$cateogry_path="<a href=\"javascript:meSetpid('0');\">¶¥¼¶</a>";
$cateogry_path.=me_area_path($get_me_pid);

$page_footer_info=<<<HTML
<script>function meSetpid(msgpid){document.getElementById('me_pid').value=msgpid;frmExecute('');}</script>
<input type='hidden' name='me_pid' value='$get_me_pid' id="me_pid">
HTML;

if($get_act=="save"){
	$str_pids="";
	$str_pids=$get_me_pid;
	$str_sql="select area_pids from ".$tab_area." where area_id='".$get_me_pid."'";
	$obj_result  = $obj_db->query($str_sql);
	$str_names="";
	if($obj_rs=$obj_db->fetch_array($obj_result))
	{
		$str_pids=$obj_rs["area_pids"].",".$get_me_pid;
	}
	for($i=0;$i<count($get_areaid);$i++)
	{
		(isset($get_areaid[$i]))?$str_id=intval($get_areaid[$i]):$str_id=0;
		(isset($get_area_name[$i]))?$str_area_name=$get_area_name[$i]:$str_area_name="";
		(isset($get_area_sort[$i]))?$str_area_sort=$get_area_sort[$i]:$str_area_sort="";
		if($str_area_name!="")
		{			
			$arr_fields=array();
			$arr_fields["area_name"]=$str_area_name;
			$arr_fields["area_sort"]=$str_area_sort;
			$arr_fields["area_pid"]=$get_me_pid;
			$arr_fields["area_pids"]=$str_pids;
			$arr_fields["area_id"]=$str_id;
			$arr_msg=$obj_tab_area->on_save($arr_fields);
			if($arr_msg["err"]!=""){
				$obj_msg->alert($arr_msg["err"]);
			}

		}
	}
	$get_act="";

}

if($get_act=='del')
{
	$arr_msg=$obj_tab_area->on_del($get_id);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}


$arr_area = array();
$obj_result = $obj_db->query("SELECT * FROM ".$tab_area." where area_pid='".$get_me_pid."' order by area_sort,area_id");
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$arr_area[] = $obj_rs;
}
include 'tpl/area.tpl.php';

function me_area_path($msg_pid)
{
	global $obj_db,$tab_area;
	$str_sql="select area_id,area_name,area_pid from ".$tab_area." where area_id='".$msg_pid."'";
	$obj_result = $obj_db->query($str_sql);
	$str_val="";
	if($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$str_val=" -> <a href=\"javascript:meSetpid('".$obj_rs['area_id']."');\">".$obj_rs['area_name']."</a>";
		$str_val=me_area_path($obj_rs['area_pid']).$str_val;
	}
	return $str_val;

}


?>
