<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//导航条控制器
class NavAction 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;
					}
					switch ($_value->target) {
						case '_self' :
							$_value->target = '本页面';
							break;
						case '_black' :
							$_value->target = '弹出式';
							break;
					}
					
				}
			}	
		$this->_tpl->assign('AllNav',$AllNav);
		$this->_tpl->display(SMARTY_ADMIN.'nav/show.tpl');
	}
	
	public function add() {
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=nav', '导航新增成功！') : $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->assign('tao_category',Tool::setFormApiItem($this->_apiaction->taoapicategory(),'cid','name'));  //调取api数据
		$this->_tpl->display(SMARTY_ADMIN.'nav/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;
			
			}
			switch ($OneNav[0]->target){
				case '_self' :
					$OneNav[0]->target = '<option value="_self" selected="selected">本页面</option>
						<option value="_black">弹出式</option>';
					break;
				case '_black' :
					$OneNav[0]->target= '<option value="_self">本页面</option>
						<option value="_black" selected="selected">弹出式</option>';
					break;
			
			}
			$this->_tpl->assign('OneNav',$OneNav);
			$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->api59miao(),'cid','name'));  //调取api数据
			//调用淘宝数据
			$this->_tpl->assign('tao_category',Tool::setFormApiItem($this->_apiaction->taoapicategory(),'cid','name'));  //调取api数据
			$this->_tpl->display(SMARTY_ADMIN.'nav/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();
	}
	
}
?>