<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//首页数据条控制器
class HomenavAction extends Action {
	private $_apiaction='';
	public function __construct() {
		parent::__construct();
		$this->_apiaction=new ApiModel();
	}
	
	public function index() {
		parent::page();
		if (isset($_GET['sid']))
		{ 
			$this->_tpl->assign('OneNav', $this->_model->findOne());			
			
		}
		$AllNav=$this->_model->findAll();			
		if ($AllNav) {
				foreach ($AllNav as $_value) {
					switch ($_value->state) {
						case 0 :
							$_value->state = '显示';
							break;
						case 1 :
							$_value->state = '<span style="color:red;">隐藏</span>';
							break;
					}					
					
				}
			}			
		$this->_tpl->assign('AllNav',$AllNav);
		$this->_tpl->display(SMARTY_ADMIN.'homenav/show.tpl');
	}
	
	public function add() {		
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=homenav', '首页数据新增成功！') : $this->_redirect->error('首页数据新增失败！');
		if (isset($_GET['id'])) $this->_tpl->assign('OneNav', $this->_model->findOne());		
		$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->api59miao(),'cid','name'));  //调取api数据
		$this->_tpl->display(SMARTY_ADMIN.'homenav/add.tpl');
	}	
	public function update() {
		if (isset($_POST['send'])) $this->_model->update() ? $this->_redirect->succ(Tool::getPrevPage(), '首页数据名称修改成功！') : $this->_redirect->error('首页数据名称修改失败！');
		if (isset($_GET['id'])) {
			
			$OneNav=$this->_model->findOne();
			switch ($OneNav[0]->state){
				case 0 :
					$OneNav[0]->state = '<option value="0" selected="selected">显示</option>						
						<option value="1">隐藏</option>	';
					break;
				case 1 :
					$OneNav[0]->state = '<option value="0">显示</option>						
						<option value="1" selected="selected">隐藏</option>';
					break;
			
			}		
			$this->_tpl->assign('OneNav',$OneNav);
			$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->api59miao(),'cid','name'));  //调取api数据
			$this->_tpl->display(SMARTY_ADMIN.'homenav/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('排序失败！');
	}
	
	public function isName() {
		$this->_model->isName();
	}
	
}
?>