/**
  * @see Form::save()
  */
 public function save()
 {
     // set the language temporarily to the thread language
     if ($this->languageID && $this->languageID != WCF::getLanguage()->getLanguageID()) {
         $this->setLanguage($this->languageID);
     }
     parent::save();
     // search for double posts
     if ($postID = PostEditor::test($this->subject, $this->text, WCF::getUser()->userID, $this->username)) {
         HeaderUtil::redirect('index.php?page=Thread&postID=' . $postID . SID_ARG_2ND_NOT_ENCODED . '#post' . $postID);
         exit;
     }
     // save poll
     if ($this->showPoll) {
         $this->pollEditor->save();
     }
     // save thread in database
     $this->newThread = ThreadEditor::create($this->board->boardID, $this->languageID, $this->prefix, $this->subject, $this->text, WCF::getUser()->userID, $this->username, intval($this->isImportant == 1), intval($this->isImportant == 2), $this->closeThread, $this->getOptions(), $this->subscription, $this->attachmentListEditor, $this->pollEditor, intval($this->disableThread || !$this->board->getPermission('canStartThreadWithoutModeration')));
     if ($this->isImportant == 2) {
         $this->newThread->assignBoards($this->boardIDs);
     }
     // save tags
     if (MODULE_TAGGING && THREAD_ENABLE_TAGS && $this->board->getPermission('canSetTags')) {
         $tagArray = TaggingUtil::splitString($this->tags);
         if (count($tagArray)) {
             $this->newThread->updateTags($tagArray);
         }
     }
     // reset language
     if ($this->userInterfaceLanguageID !== null) {
         $this->setLanguage($this->userInterfaceLanguageID, true);
     }
     if (!$this->disableThread && $this->board->getPermission('canStartThreadWithoutModeration')) {
         // update user posts
         if (WCF::getUser()->userID && $this->board->countUserPosts) {
             require_once WBB_DIR . 'lib/data/user/WBBUser.class.php';
             WBBUser::updateUserPosts(WCF::getUser()->userID, 1);
             if (ACTIVITY_POINTS_PER_THREAD) {
                 require_once WCF_DIR . 'lib/data/user/rank/UserRank.class.php';
                 UserRank::updateActivityPoints(ACTIVITY_POINTS_PER_THREAD);
             }
         }
         // refresh counter and last post
         $this->board->addThreads();
         $this->board->setLastPost($this->newThread);
         // reset stat cache
         WCF::getCache()->clearResource('stat');
         WCF::getCache()->clearResource('boardData');
         // send notifications
         $this->newThread->sendNotification(new Post(null, array('postID' => $this->newThread->firstPostID, 'message' => $this->text, 'enableSmilies' => $this->enableSmilies, 'enableHtml' => $this->enableHtml, 'enableBBCodes' => $this->enableBBCodes)), $this->attachmentListEditor);
         $this->saved();
         // forward to post
         HeaderUtil::redirect('index.php?page=Thread&threadID=' . $this->newThread->threadID . SID_ARG_2ND_NOT_ENCODED);
     } else {
         $this->saved();
         if ($this->disableThread) {
             // forward to post
             HeaderUtil::redirect('index.php?page=Thread&threadID=' . $this->newThread->threadID . SID_ARG_2ND_NOT_ENCODED);
         } else {
             WCF::getTPL()->assign(array('url' => 'index.php?page=Board&boardID=' . $this->boardID . SID_ARG_2ND_NOT_ENCODED, 'message' => WCF::getLanguage()->get('wbb.threadAdd.moderation.redirect'), 'wait' => 5));
             WCF::getTPL()->display('redirect');
         }
     }
     exit;
 }
 /**
  * Copies all SQL data of the posts with the given posts ids. 
  */
 public static function copyAll($postIDs, $threadID, $threadMapping = null, $boardID = 0, $updateUserStats = true)
 {
     if (empty($postIDs)) {
         return;
     }
     // copy 'post' data
     $postMapping = array();
     $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $post = new PostEditor(null, $row);
         $postMapping[$post->postID] = $post->copy($threadID ? $threadID : $threadMapping[$row['threadID']]);
     }
     // refresh first post ids
     require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
     ThreadEditor::refreshFirstPostIDAll($threadID ? $threadID : implode(',', $threadMapping));
     // update user posts and activity points
     if ($updateUserStats) {
         self::updateUserStats(implode(',', $postMapping), 'copy', $boardID);
     }
     // copy 'post_cache' data
     $sql = "SELECT\t*\n\t\t\tFROM \twbb" . WBB_N . "_post_cache\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $sql = "INSERT INTO \twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\t(postID, threadID, messageCache)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . ($threadID ? $threadID : $threadMapping[$row['threadID']]) . ",\n\t\t\t\t\t\t'" . escapeString($row['messageCache']) . "')";
         WCF::getDB()->sendQuery($sql);
     }
     // copy 'post_report' data
     $sql = "SELECT \t*\n\t\t\tFROM \twbb" . WBB_N . "_post_report\n\t\t\tWHERE \tpostID IN (" . $postIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $sql = "INSERT INTO \twbb" . WBB_N . "_post_report\n\t\t\t\t\t\t(postID, userID, report, reportTime)\n\t\t\t\tVALUES\t\t(" . $postMapping[$row['postID']] . ",\n\t\t\t\t\t\t" . $row['userID'] . ",\n\t\t\t\t\t\t'" . escapeString($row['report']) . "',\n\t\t\t\t\t\t" . $row['reportTime'] . ")";
         WCF::getDB()->sendQuery($sql);
     }
     // copy polls
     require_once WCF_DIR . 'lib/data/message/poll/PollEditor.class.php';
     $pollMapping = PollEditor::copyAll($postIDs, $postMapping);
     if (is_array($pollMapping)) {
         foreach ($pollMapping as $oldPollID => $newPollID) {
             $sql = "UPDATE\t\twbb" . WBB_N . "_post\n\t\t\t\t\tSET \t\tpollID = " . $newPollID . "\n\t\t\t\t\tWHERE \t\tpollID = " . $oldPollID . "\n\t\t\t\t\t\t\tAND postID NOT IN (SELECT messageID FROM wcf" . WCF_N . "_poll WHERE pollID = " . $oldPollID . ")";
             WCF::getDB()->sendQuery($sql);
         }
     }
     // copy attachments
     require_once WCF_DIR . 'lib/data/message/attachment/AttachmentsEditor.class.php';
     $attachment = new AttachmentsEditor($postIDs);
     $attachmentMapping = $attachment->copyAll($postMapping);
     // update inline attachments
     if (count($attachmentMapping) > 0) {
         $sql = "SELECT\tpostID, message\n\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\tWHERE\tpostID IN (" . implode(',', array_keys($attachmentMapping)) . ")\n\t\t\t\t\tAND message LIKE '%[attach%'";
         $result = WCF::getDB()->sendQuery($sql);
         while ($row = WCF::getDB()->fetchArray($result)) {
             $messageChanged = false;
             foreach ($attachmentMapping[$row['postID']] as $oldAttachmentID => $newAttachmentID) {
                 $row['message'] = StringUtil::replaceIgnoreCase('[attach=' . $oldAttachmentID . ']', '[attach=' . $newAttachmentID . ']', $row['message']);
                 $row['message'] = StringUtil::replaceIgnoreCase('[attach]' . $oldAttachmentID . '[/attach]', '[attach]' . $newAttachmentID . '[/attach]', $row['message']);
                 $messageChanged = true;
             }
             if ($messageChanged) {
                 // update message
                 $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\t\tSET\tmessage = '" . escapeString($row['message']) . "'\n\t\t\t\t\t\tWHERE\tpostID = " . $row['postID'];
                 WCF::getDB()->sendQuery($sql);
                 // delete post cache
                 $sql = "DELETE FROM\twbb" . WBB_N . "_post_cache\n\t\t\t\t\t\tWHERE\t\tpostID = " . $row['postID'];
                 WCF::getDB()->sendQuery($sql);
             }
         }
     }
 }