<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//文章列表条控制器
class ArtileAction extends Action {	
	public function __construct() {
		parent::__construct();	
		$this->_artilenav=new ArtilenavModel();			
	}
	
	public function index() {
		parent::page();	
		$Allartile=$this->_model->findAll();			
		if ($Allartile) {
				foreach ($Allartile as $_value) {
					if ($_value->ontop=='1'){
						$_value->ontop='<span style="color:red;">【置顶】</span>';
					}
					else{
						$_value->ontop='';
					}
					if ($_value->hot=='1'){
						$_value->hot='<span style="color:red;">【推荐】</span>';
					}
					else{
						$_value->hot='';
					}				
					
				}
			}	
		$this->_tpl->assign('AllArtile',$Allartile);
		$this->_tpl->display(SMARTY_ADMIN.'artile/artile_show.tpl');
	}		
	public function add() {
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=artile', '文章新增成功！') : $this->_redirect->error('导航新增失败！');
		$this->_tpl->assign('ArtileNav', Tool::setFormItem($this->_artilenav->findAllNoLimit(),'id','name'));		
		$this->_tpl->display(SMARTY_ADMIN.'artile/artile_add.tpl');
	}	
	
	public function update(){
		if (isset($_POST['send'])) $this->_model->update() ? $this->_redirect->succ('?a=artile', '文章修改成功！') : $this->_redirect->error('导航名称修改失败！');
		if (isset($_GET['id'])) {			
			$oneArtile=$this->_model->findOne();
			if($oneArtile[0]->ontop=='1'){
					$oneArtile[0]->ontop='<input type="checkbox" value="1" name="ontop" checked="checked">';					
			}
			else{
				$oneArtile[0]->ontop='<input type="checkbox" value="1" name="ontop">';	
			}
			if($oneArtile[0]->hot=='1'){
				$oneArtile[0]->hot='<input type="checkbox" value="1" name="hot" checked="checked">';
			}
			else{
				$oneArtile[0]->hot='<input type="checkbox" value="1" name="hot">';
			}	

			
			
			$this->_tpl->assign('OneArtile',$oneArtile);	
			$this->_tpl->assign('ArtileNav', Tool::setFormItem($this->_artilenav->findAllNoLimit(),'id','name'));		
			$this->_tpl->display(SMARTY_ADMIN.'artile/artile_update.tpl');
		}
	}	
	public function delete(){
		if (isset($_GET['id'])) $this->_model->delete() ? $this->_redirect->succ(Tool::getPrevPage(), '文章删除成功！') : $this->_redirect->error('导航名称删除失败！');
	}		
	public function isName() {
		$this->_model->isName();
	}
	
}
?>