<?php
/**
 * 广告
 *
 * @package user
 * @author 王岩 yandy@yanwee.com
 * @version 1.0
 */

require('path.inc.php');

$user->allow('advertise');
$adsPlace = new AdsPlace($query);

if ($page->action=='edit') {
	$page->action = 'add';
}
if ($page->action=='add') {
	$page->name = 'adsEdit'; //页面名字,和文件名相同
	$page->addJs('FormValid.js');
	$place_id = intval($_GET['id']);
	if($place_id){
		$dataInfo=$adsPlace->getInfo($place_id);
		$page->tpl->assign('dataInfo', $dataInfo);
	}

}elseif ($page->action=='save') {
	try{
		$adsPlace->save($_POST);
		$page->goto('index.php','保存成功');
	}catch (Exception $e){
		$page->back($e->getMessage());
	}
	exit;
}elseif ($page->action=='delete') {
	$ids = $_POST['ids'];
	if(!is_array($ids) || empty($ids)){
		$page->back('没有选择删除条目');
	}
	
	try{
		//删除自己的条目
		$adsPlace->delete($ids);
		$page->goto('index.php','删除成功');
	}catch (Exception $e){
		$page->back($e->getMessage());
	}

	exit;
}else{
	$page->name = 'adsList'; //页面名字,和文件名相同
	
	$where = ' is_del = 0';
	
	require($cfg['path']['lib'] . 'classes/Pages.class.php');
	$pages = new Pages($adsPlace->getCount($where));
	$pageLimit = $pages->getLimit();
	$adsList = $adsPlace->getList($pageLimit,'*',$where,' order by place_name desc ');

	$page->tpl->assign('dataList', $adsList);
	$page->tpl->assign('pagePanel', $pages->showCtrlPanel());//分页条
}
$page->show();
?>