<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//友情链接控制器
class LinkAction extends Action {
	public function __construct(){
		parent::__construct();
	}	
	public function index(){
		parent::page();
		$AllLink=$this->_model->findAll();			
		if ($AllLink) {
				foreach ($AllLink as $_value) {
					switch ($_value->type) {
						case 1 :
							$_value->type = '文字链接';
							break;
						case 2 :
							$_value->type = 'Logo链接';
							break;
					}
					if (empty($_value->state)) {
						$_value->state = '<span class="red">[未审核]</span> | <a href="link.php?action=state&type=ok&id='.$_value->id.'">通过</a>';
					} else {
						$_value->state = '<span class="green">[已通过]</span> | <a href="link.php?action=state&type=cancel&id='.$_value->id.'">取消</a>';
					}
				}
			}		
		$this->_tpl->assign('AllLink',$AllLink);
		$this->_tpl->display(SMARTY_ADMIN.'link/show.tpl');
	}
		
	public function add(){
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=link', '友情链接新增成功！') : $this->_redirect->error('友情链接新增失败！');		
		$this->_tpl->display(SMARTY_ADMIN.'link/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('?a=link', '友情链接名称修改成功！') : $this->_redirect->error('友情链接名称修改失败！');
		if (isset($_GET['id'])) {
			$this->_tpl->assign('OneLink', $this->_model->findOne());
			$this->_tpl->display(SMARTY_ADMIN.'link/update.tpl');
		}
	}
	public function sort() {
		if (isset($_POST['send'])) $this->_model->sort() ? $this->_redirect->succ(Tool::getPrevPage()) : $this->_redirect->error('排序失败！');
	}	
}
?>