<?php
/*
* 项目: iOrange(橘子)
* 作者: 离家出走(yzxh24)
* Email: yzxh24@gmail.com
* 主页: www.iorange.cc
*/
/* vim: set ts=4 sw=4: */
class OpenAction extends ForumAction
{
    public function run()
    {
        $bookInfo = $this->bookInfo();
        if ($bookInfo['bookforum'])
        {
            iforward(url('system',array('s'=>'forum','id'=>$this->id())));
        }
        
        $book = fetchBookInfo($this->id());
        if (empty($book))
        {
            throw new iSystemException('不存在的小说');
        }
        $this->db()->query('INSERT INTO `'.BookForum::table()."` (`bookid`, `forumname`, `createdate`) VALUES ('{$this->id()}', '{$bookInfo['bookname']}', NOW())");
        $this->db()->query('UPDATE `'.Book::table()."` SET `bookforum` = 1 WHERE `bookid` = {$this->id()}");
     
        updateBookInfo($this->id());
        updateBookForum($this->id());
        $message[] = '太好了！《'. $bookInfo['bookname'] . '》书友会正式成立了！^_^<br/>' . ilink('马上进入',url('system',array('s'=>'forum','id'=>$this->id()))) . '.'.ilink('回到书页',url('bookshow',array('bid'=>$this->id())));
        $this->showMessage($message);
    }
}