<?php
require('path.inc.php');
$cmap = new CityareaMap($query);
$page->name = 'cityareaList';
if ($page->action=='edit') {
	$page->name = 'cityareaList';
	$id = $_GET['id'];
	$cmapInfo = $cmap->getInfo($id,'*');
	$page->tpl->assign('dataInfo', $cmapInfo);		
}elseif($page->action=='save'){
	if($_POST['id']){
			//编辑
			try {
		     	$cmap->save($_POST);
	         	} catch (Exception $e) {
		     	$page->goto('?action=edit&id=' . $_GET['id'], $e->getMessage());
	            }
			}else{
				try {
		     	$cmap->save($_POST);
	         	} catch (Exception $e) {
		     	$page->goto('?action=edit&id=' . $_GET['id'], $e->getMessage());
	            }
		}
	
	}
elseif($page->action=='delete'){
	$back_to = $_SERVER['HTTP_REFERER'];
	$ids = $_POST['ids'];
	if(!is_array($ids) || empty($ids)){
		$page->back('没有选择删除条目');
	}
	try{
		$cmap->delete($ids);
		$page->goto('index.php','删除成功');
	}catch (Exception $e){
		$page->back($e->getMessage());
		//$page->back('删除失败');
	}
	
	exit;
	
	}
//
require($cfg['path']['lib'] . 'classes/Pages.class.php');
	$pages = new Pages($cmap->getCount('1=1'));
	$pageLimit = $pages->getLimit();
    $list = $cmap->getList('*','1=1',' order by sort asc ');
	$page->tpl->assign('list', $list);
	$page->tpl->assign('pagePanel', $pages->showCtrlPanel());//分页条
	
$page->show();
?>