<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DeleteThreadAction extends BbsAction
{
    public function run()
    {
        $tid = S::getGP('tid','G');
        $thread = $this->getExistsThread($tid);
        
        $allows = $this->getAllows($thread);
        !$allows['delete'] && $this->NoPermission();

        $this->confirm('deletetd', $thread);
        if (!$_GET['confirm'])
        {
            $message[] = '确定要删除吗？删除后将不可恢复！';
            $message[] = $this->getController()->link('删除',$this->getController()->url('system',array('s'=>'bbs','c'=>'manage','a'=>'deletethread','tid'=>$tid,'confirm'=>1))).'|'.$this->getController()->link('取消',$this->getController()->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$tid)));
            $this->showMessage($message);
        }
        Threads::single()->delete($tid);
        
        $forum = $this->getController()->getForumCache($thread['fid']);
        $this->updateCredits($thread['uid'],$thread['username'],$forum['creditset'],'deletepost');
        
        iforward($this->getController()->url('system',array('s'=>'bbs','a'=>'forum','fid'=>$thread['fid'])));
    }
}