<?php
if (!defined('IN_59MIAO'))
{
	exit('Access Defined');
}
//关键字控制器
class KeywordsAction extends Action{
	public function __construct(){
		parent::__construct();
		$this->_apiaction=new ApiModel();
	}	
	public function index(){
		parent::page();
		$AllKeywords=$this->_model->findAll();				
		$this->_tpl->assign('AllKeywords',$AllKeywords);
		$this->_tpl->display(SMARTY_ADMIN.'keywords/show.tpl');
	}		
	public function add(){
		if (isset($_POST['send'])) $this->_model->add() ? $this->_redirect->succ('?a=keywords', '关键字新增成功！'): $this->_redirect->error('关键字新增失败！');		
		$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->api59miao(),'cid','name'));  //调取api数据
		$this->_tpl->display(SMARTY_ADMIN.'keywords/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(Tool::getPrevPage(), '关键字名称修改成功！') : $this->_redirect->error('关键字名称修改失败！');
		if (isset($_GET['id'])) {
			$this->_tpl->assign('OneKeywords', $this->_model->findOne());
			$this->_tpl->assign('category',Tool::setFormApiItem($this->_apiaction->api59miao(),'cid','name'));  //调取api数据
			$this->_tpl->display(SMARTY_ADMIN.'keywords/update.tpl');
		}
	}	
	//排序
	public function sort() {
		if (isset($_POST['send'])) $this->_model->sort() ? $this->_redirect->succ(Tool::getPrevPage()) : $this->_redirect->error('排序失败！');
	}
}
?>