$novel = DB::fetch_first("SELECT * FROM " . DB::table("pdnovel_view") . (" WHERE novelid=" . $novelid . " AND display=0 LIMIT 1"));
 if (!$novel) {
     showmessage($lang['pdnovel_error']);
 }
 if (!checkperm('pdnovelstar')) {
     showmessage("group_nopermission", NULL, array("grouptitle" => $_G['group']['grouptitle']), array("login" => 1));
 }
 if ($novel['posterid'] == $_G['uid']) {
     showmessage("click_no_self");
 }
 if ($_G['gp_op'] == "add") {
     $find = DB::result_first("SELECT uid FROM " . DB::table("pdnovel_star") . (" WHERE uid='" . $_G['uid'] . "' AND novelid='{$novelid}'"));
     if ($find) {
         showmessage($lang['star_haven']);
     }
     pdupdatecredit('pdnovelstar', $lang['credit_shortage'], '');
     $clickid = $_G['gp_clickid'];
     $setarr = array("novelid" => $novelid, "clickid" => $clickid, "uid" => $_G['uid'], "dateline" => $_G['timestamp']);
     DB::insert("pdnovel_star", $setarr);
     DB::query("UPDATE " . DB::table("pdnovel_view") . (" SET click=click+1, click" . $clickid . "=click{$clickid}+1 WHERE novelid={$novelid}"));
     showmessage($lang['star_succeed']);
 } else {
     if ($_G['gp_op'] == "show") {
         $percentage = $width = array();
         $i = 1;
         for (; $i < 6; ++$i) {
             $percentage[$i] = round($novel["click" . $i] * 100 / $novel[click], 1);
             $width[$i] = ceil($percentage[$i] * 0.7) + 1;
             $sum_score += $novel["click" . $i] * $i;
         }
         $novel_score = round($sum_score * 2 / $novel[click], 1);
     $novel = DB::fetch_first("SELECT * FROM " . DB::table("pdnovel_view") . (" WHERE novelid='" . $novelid . "'"));
     if (empty($novel)) {
         showmessage("comment_comment_noexist");
     }
     require_once libfile("function/spacecp");
     ckrealname("comment");
     cknewuser();
     $waittime = interval_check("post");
     if (0 < $waittime) {
         showmessage("operating_too_fast", "", array("waittime" => $waittime), array("return" => TRUE));
     }
     $message = getstr($_POST['message'], 0, 1, 1, 1, 0);
     if (strlen($message) < 2) {
         showmessage("content_is_too_short");
     }
     pdupdatecredit('pdnovelcomment', $lang['common_no_credit']);
     $message = censor($message);
     if (censormod($message)) {
         $comment_status = 1;
     } else {
         $comment_status = 0;
     }
     $setarr = array("uid" => $_G['uid'], "username" => $_G['username'], "novelid" => $novelid, "postip" => $_G['onlineip'], "dateline" => $_G['timestamp'], "status" => $comment_status, "message" => $message);
     DB::insert("pdnovel_comment", $setarr);
     if ($_G['uid'] != $novel['posterid']) {
         DB::insert("home_notification", array("uid" => $novel['posterid'], "type" => 'comment', "new" => '1', "authorid" => $_G['uid'], "author" => $_G['username'], "note" => '<a href="home.php?mod=space&uid="' . $_G['uid'] . '">' . $_G['username'] . '</a> 评论了您的小说 <a href="pdnovel.php?mod=view&novelid=' . $novelid . '" target="_blank">' . $novel['name'] . '</a> &nbsp; <a href="pdnovel.php?mod=comment&novelid=' . $novelid . '" target="_blank" class="lit">查看</a>', "dateline" => $_G['timestamp'], "from_id" => 0, "from_num" => 1));
     }
     DB::query("UPDATE " . DB::table("pdnovel_view") . (" SET comments=comments+1 WHERE novelid=" . $novelid));
     DB::update("common_member_status", array("lastpost" => $_G['timestamp']), array("uid" => $_G['uid']));
     showmessage("do_success", $_POST['referer'] ? $_POST['referer'] : "pdnovel.php?mod=view&novelid=" . $novelid . "#comment");
 }
             $imgid = DB::insert_id();
             $subimgid = floor($imgid / 1000);
             $subsubimgid = floor($subimgid / 1000);
             dmkdir($imgpath . $subsubimgid . '/' . $subimgid);
             @rename($v, $imgpath . $subsubimgid . '/' . $subimgid . '/' . $imgid . '.jpg');
             $content = str_replace($v, 'data/attachment/pdnovel/img/' . $subsubimgid . '/' . $subimgid . '/' . $imgid . '.jpg', $content);
         }
         $content = str_replace(array('[upimg]', '[/upimg]'), array('[img]', '[/img]'), $content);
         $subid2 = rand(100, 999);
         $chaptercontent = $subsubchapterid . "/" . $subchapterid . "/" . $chapterid . "-" . rand(100, 999) . ".txt";
         $content = str_replace('\'', "’", $content);
         DB::insert('pdnovel_text_' . $tableid, array('id' => $chapterid, 'subid1' => $subsubchapterid, 'subid2' => $subid2, 'text' => addslashes($content)));
         DB::update("pdnovel_chapter", array("chaptercontent" => $chaptercontent), "chapterid=" . $chapterid);
         DB::query("UPDATE " . DB::table("pdnovel_volume") . (" SET volumechapters=volumechapters+1, volumewords=volumewords+" . $chapterwords . (" WHERE volumeid=" . $volumeid)));
         DB::query("UPDATE " . DB::table("pdnovel_view") . (" SET chapters=chapters+1, words=words+" . $chapterwords . (", lastupdate=" . $time . ", lastchapter='{$chaptername}', lastchapterid={$chapterid}, lastchaptercontent='{$lastchaptercontent}' WHERE novelid={$volume['novelid']}")));
         pdupdatecredit('pdnovelchapter');
         showmessage("do_success", "pdnovel.php?mod=home&do=manage&novelid=" . $volume['novelid'] . ("#chapterid" . $chapterid));
     }
 } else {
     if ($ac == "edit") {
         if (!checkperm("pdnovelpost")) {
             showmessage("group_nopermission", NULL, array("grouptitle" => $_G['group']['grouptitle']), array("login" => 1));
         }
         $chapterid = $_G['gp_chapterid'];
         $chapter = DB::fetch_first("SELECT * FROM " . DB::table("pdnovel_chapter") . (" WHERE chapterid=" . $chapterid));
         if (!$chapter) {
             showmessage("章节ID出错");
         }
         if (submitcheck("postsubmit")) {
             $chapterorder = intval($_G['gp_chapterorder']);
             $volumeid = intval($_G['gp_volumeid']);
    showmessage($lang['novelid_error']);
}
$novel = DB::fetch_first("SELECT * FROM " . DB::table('pdnovel_view') . " WHERE novelid={$novelid} AND display=0 LIMIT 1");
if (!$novel) {
    showmessage($lang['novel_error']);
}
if ($novel['vip'] == 0) {
    if (!checkperm('pdnovelread')) {
        showmessage("group_nopermission", NULL, array("grouptitle" => $_G['group']['grouptitle']), array("login" => 1));
    }
    pdupdatecredit('pdnovelread', $lang['read_no_credit']);
} else {
    if (!checkperm('pdnovelvipread')) {
        showmessage("group_nopermission", NULL, array("grouptitle" => $_G['group']['grouptitle']), array("login" => 1));
    }
    pdupdatecredit('pdnovelvipread', $lang['vipread_no_credit']);
}
$catname = $ncc[$novel['catid']]['catname'];
$novel['upid'] = $ncc[$novel['catid']]['upid'];
$upname = $ncc[$novel['upid']]['catname'];
$novel['lastupdate'] = strftime("%Y-%m-%d %X", $novel['lastupdate']);
if ($chapterid) {
    $read = DB::fetch_first("SELECT * FROM " . DB::table("pdnovel_chapter") . (" WHERE chapterid=" . $chapterid . " LIMIT 1"));
} else {
    $read = DB::fetch_first("SELECT * FROM " . DB::table("pdnovel_chapter") . (" WHERE novelid=" . $novelid . " LIMIT 1"));
}
if (!$read) {
    showmessage($lang['novel_error']);
}
$chapterid = $read['chapterid'];
$read['lastupdate'] = strftime("%Y-%m-%d %X", $read['lastupdate']);