<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class DeleteReplyAction extends BbsAction
{
    public function run()
    {
        $pid = S::gp('pid', 'G', 2);

        try
        {
            $post = Posts::single()->getOne($pid);
        }
        catch (PostsException $exce)
        {
            throw new iSystemException($exce->getMessage());
        }

        $thread = $this->getExistsThread($post['tid']);
        $allows = $this->getAllows($thread);
        !$allows['deleterp'] && $this->NoPermission();

        $colone = $thread;
        $post['content'] = preg_replace('/\[[a-z]{3}=\d+\]/i', '', $post['content']);
        $post['content'] = preg_replace('/\[bf=\d+:\d+\]/i', '', $post['content']);
        $colone['subject'] = iSubstr($post['content'], 0, 30, '...');
        $colone['uid'] = $post['uid'];
        $this->confirm('deleterp', $colone);
        $this->db()->update(Posts::table())->value(array('isdelete'=>1))->where('id='.$pid)->q();
        $this->db()->update(Threads::table())->decrField(array('replies'=>1))->where('id='.$post['tid'])->q();
        
        $forum = $this->getController()->getForumCache($thread['fid']);
        
        $this->updateCredits($post['uid'],$post['username'],$forum['creditset'],'deleterp');
        
        iforward($this->getController()->url('system',array('s'=>'bbs','a'=>'thread','tid'=>$thread['tid'])));
    }
}