<?php
require('path.inc.php');
$trend = new Trend($query);
$page->name = 'sellTrend';
if ($page->action=='edit') {
	if($_POST){
		if($_POST['id']){
			//编辑
			try {
		     	$trend->save($_POST);
	         	} catch (Exception $e) {
		     	$page->goto('?action=edit&id=' . $_GET['id'], $e->getMessage());
	            }
			}else{
				
				$trendCount = $trend->getCount('time = "'.$_POST['timestr'].'"');
		if($trendCount != 0){
			$page->back('该月份已经存在');
			}else{
				try {
		     	$trend->save($_POST);
	         	} catch (Exception $e) {
		     	$page->goto('?action=edit&id=' . $_GET['id'], $e->getMessage());
	            }
			}
				
				
	}
		
	}else{
	$id = $_GET['id'];
	$trendInfo = $trend->getInfo($id,'*');
	$page->tpl->assign('dataInfo', $trendInfo);
	}
}elseif($page->action=='delete'){
	$back_to = $_SERVER['HTTP_REFERER'];
	$ids = $_POST['ids'];
	if(!is_array($ids) || empty($ids)){
		$page->back('没有选择删除条目');
	}
	try{
		$trend->delete($ids);
		$page->goto('sell.php','删除成功');
	}catch (Exception $e){
		$page->back($e->getMessage());
		//$page->back('删除失败');
	}
	
	exit;
	
	}
//
require($cfg['path']['lib'] . 'classes/Pages.class.php');
	$pages = new Pages($trend->getCount('1=1'));
	$pageLimit = $pages->getLimit();
    $list = $trend->getList($pageLimit,'*','1=1',' order by time desc ');
	$page->tpl->assign('list', $list);
	$page->tpl->assign('pagePanel', $pages->showCtrlPanel());//分页条
	
$page->show();
?>