<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//导航条控制器
class SellercateAction extends Action {	
	public function __construct() {
		parent::__construct();		
	}
	
	public function index() {
		parent::page();		
		$AllCate=$this->_model->findAll();				
		$this->_tpl->assign('AllCate',$AllCate);
		$this->_tpl->display(SMARTY_ADMIN.'seller/category/show.tpl');
	}
	public function addb2ccate(){				
		$this->_model->addb2ccate()?$this->_redirect->succ('?a=sellercate', '恭喜您同步成功！') : $this->_redirect->error('对不起同步失败！');		
	}
	public function add() {
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=sellercate', '商家分类新增成功！') : $this->_redirect->error('商家分类新增失败！');		
		$this->_tpl->display(SMARTY_ADMIN.'seller/category/add.tpl');
	}	
	public function update() {		
		if (isset($_POST['send'])) $this->_model->update() ? $this->_redirect->succ(Tool::getPrevPage(), '商家分类修改成功！') : $this->_redirect->error('商家分类修改失败！');
		if (isset($_GET['id'])){			
			$OneCate=$this->_model->findOne();		
			switch ($OneCate[0]->state){
				case 1 :
					$OneCate[0]->state = '<option value="1" selected="selected">显示</option>						
						<option value="0">隐藏</option>	';
					break;
				case 0 :
					$OneCate[0]->state = '<option value="1">显示</option>						
						<option value="0" selected="selected">隐藏</option>';
					break;
			
			}		
			$this->_tpl->assign('OneCate',$OneCate[0]);		
			$this->_tpl->display(SMARTY_ADMIN.'seller/category/update.tpl');
		}
	}	
	public function delete() {
		if (isset($_GET['id'])) $this->_model->delete() ? $this->_redirect->succ(Tool::getPrevPage(), '商家分类删除成功！') : $this->_redirect->error('商家分类删除失败！');
	}
	
	public function sort() {
		if (isset($_POST['send'])) $this->_model->sort() ? $this->_redirect->succ(Tool::getPrevPage()) : $this->_redirect->error('排序失败！');
	}
	
}
?>