<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//皇冠店铺控制器
class ShopcategoryAction extends Action{
	public function __construct(){
		parent::__construct();
		$this->_apiaction=new ApiModel();
	}	
	public function index(){
		parent::page();
		$AllCategory=$this->_model->findAll();			
		$this->_tpl->assign('Allshopcategory',$AllCategory);
		$this->_tpl->display(SMARTY_ADMIN.'shopcategory/show.tpl');
	}		
	public function add(){
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=shopcategory', '皇冠店铺新增成功！'): $this->_redirect->error('皇冠店铺新增失败！');		
		$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->taoapicategory(),'cid','name'));  //调取api数据
		$this->_tpl->display(SMARTY_ADMIN.'shopcategory/add.tpl');
	}	
	public function delete() {
		if (isset($_GET['id'])) $this->_model->delete() ? $this->_redirect->succ(Tool::getPrevPage(), '皇冠店铺名称删除成功！') : $this->_redirect->error('皇冠店铺名称删除失败！');
	}
	public function update() {
		if (isset($_POST['send'])) $this->_model->update() ? $this->_redirect->succ(Tool::getPrevPage(), '皇冠店铺名称修改成功！') : $this->_redirect->error('皇冠店铺名称修改失败！');
		if (isset($_GET['id'])) {
			$this->_tpl->assign('Oneshopcategory', $this->_model->findOne());
			$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->taoapicategory(),'cid','name'));  //调取api数据
			$this->_tpl->display(SMARTY_ADMIN.'shopcategory/update.tpl');
		}
	}	
	//排序
	public function sort() {
		if (isset($_POST['send'])) $this->_model->sort() ? $this->_redirect->succ(Tool::getPrevPage()) : $this->_redirect->error('排序失败！');
	}
}
?>