<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class ReplyAction extends ForumAction
{
    public function run()
    {
        $bookpost = BookPost::single();
        if ($bookpost->isCanPost($this->id()))
        {
            $postId = S::gp('cid','G',2);
            $data = array(
                'uid' => $this->uid(),
                'username' => $this->userName(),
                'postid' => $postId,
                'content' => trim(S::gp('content', 'P')),
            );
            BookPostReply::single()->create($this->id(), $data);
            $bookpost->updateUser($this->id(), $this->userName());
            $sql = 'UPDATE '.BookPostReply::table().' SET `replycount` = `replycount` + 1, lastreply='.CTIME.' WHERE postid='.$postId.' AND isfirst=1';
            $this->db()->query($sql);
    
            $bookpost->update($postId, $this->id(), array('lastpost'=>CTIME));
    
            $url = url('system',array('s'=>'forum','c'=>'advance','a'=>'read','id'=>$this->id(),'cid'=>$postId));
            iforward($url);
        }
    }
}