<?php
require 'inc.php';
$obj_tab_page=new cls_tab_sys_admin_page();

$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"){
	$arr_return=$obj_tab_page->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_page->on_del($get_pageid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="sort_up"){
	$arr_return=$obj_tab_page->on_sort_act($get_id,"up");
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="sort_down"){
	$arr_return=$obj_tab_page->on_sort_act($get_id,"down");
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		$arr_fields["page_id"]=$get_id;
		$arr_fields["page_model_id"]=$get_page_model_id;
		$arr_fields["page_name"]=$get_page_name;
		$arr_fields["page_act"]=$get_page_act;
		$arr_fields["page_url"]=$get_page_url;
		$arr_fields["page_ismenu"]=(int)$get_page_ismenu;
		$arr_msg=$obj_tab_page->on_save($arr_fields);
		if($arr_msg["err"]=="") $get_id=$arr_msg["id"];
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'edit':
	{
		$arr_page=array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_admin_page where page_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_page = $obj_rs;
		}
		include 'tpl/admin_page.edit.tpl.php';
		break;
	}
	case 'add':
	{
		$get_id=0;
		include "tpl/admin_page.add.tpl.php";
		break;
	}
	default:
	{
		//·ÖÒ³
		$str_where=" where page_model_id='".$get_model_id."'";
		$arr_page=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."sys_admin_page".$str_where);
		$int_total=$obj_rs["num"];
		$int_pages= ceil($int_total/$int_pagesize);
		$get_page = min($int_pages, $get_page);
		$get_page = max($get_page, 1);
		$page_split_page=get_pages($int_total, $get_page, $int_pagesize);
		$int_offset = $int_pagesize*($get_page-1);
		$str_limit = " limit ".$int_offset.",".$int_pagesize;
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_admin_page a left join ".DB_PRE."sys_model b on a.page_model_id=b.model_id".$str_where." order by page_sort,page_id".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_page[] = $obj_rs;
		}
		include "tpl/admin_page.tpl.php";

	}
}


?>
