<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ToppedAction extends BbsAction
{
    public function run()
    {
        $tid = $this->getTid();
        $thread = $this->getExistsThread($tid);
        
        $allowTop = array(1,3);
        $allows = $this->getAllows($thread);
        $topValue = S::gp('v','G',2);
        if (!in_array($topValue, $allowTop) || !$allows['top'.$topValue])
        {
            $this->NoPermission();
        }

        $this->confirm('top'.$topValue, $thread);
        
        $this->db()->update(Threads::table())->value(array('topped'=>$topValue))->where('id='.$tid)->q();
        Threads::single()->updateTopped();
        
        $message[] = '操作成功';
        $message[] = '返回'.ilink('帖子',url('system',array('s'=>'bbs','a'=>'thread','tid'=>$tid))).'.'.ilink('版块',url('system',array('s'=>'bbs','a'=>'forum','fid'=>$thread['fid'])));
        $this->showMessage($message);
    }
}