/**
  * @see Action::execute()
  */
 public function execute()
 {
     parent::execute();
     // check permissions
     $boardIDs = Board::getModeratedBoards('canDeleteThreadCompletely');
     if (empty($boardIDs)) {
         throw new PermissionDeniedException();
     }
     // delete threads
     $threadIDArray = array();
     $sql = "SELECT\tthreadID\n\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\tWHERE\tisDeleted = 1\n\t\t\t\tAND boardID IN (" . $boardIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $threadIDArray[] = $row['threadID'];
     }
     if (count($threadIDArray)) {
         ThreadEditor::deleteAllCompletely(implode(',', $threadIDArray));
     }
     $this->executed();
     // forward
     HeaderUtil::redirect('index.php?page=ModerationDeletedThreads' . SID_ARG_2ND_NOT_ENCODED);
     exit;
 }
 /**
  * @see Cronjob::execute()
  */
 public function execute($data)
 {
     if (THREAD_ENABLE_RECYCLE_BIN && THREAD_EMPTY_RECYCLE_BIN_CYCLE > 0) {
         // delete threads first
         $sql = "SELECT\tthreadID\n\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\tWHERE\tisDeleted = 1\n\t\t\t\t\tAND deleteTime < " . (TIME_NOW - THREAD_EMPTY_RECYCLE_BIN_CYCLE * 86400);
         $result = WCF::getDB()->sendQuery($sql);
         if (WCF::getDB()->countRows($result) > 0) {
             require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
             $threadIDs = '';
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($threadIDs)) {
                     $threadIDs .= ',';
                 }
                 $threadIDs .= $row['threadID'];
             }
             ThreadEditor::deleteAllCompletely($threadIDs);
         }
         // delete posts
         $sql = "SELECT\tpostID\n\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\tWHERE\tisDeleted = 1\n\t\t\t\t\tAND deleteTime < " . (TIME_NOW - THREAD_EMPTY_RECYCLE_BIN_CYCLE * 86400);
         $result = WCF::getDB()->sendQuery($sql);
         if (WCF::getDB()->countRows($result) > 0) {
             require_once WBB_DIR . 'lib/data/post/PostEditor.class.php';
             $postIDs = '';
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($postIDs)) {
                     $postIDs .= ',';
                 }
                 $postIDs .= $row['postID'];
             }
             PostEditor::deleteAllCompletely($postIDs);
         }
     }
     if (THREAD_DELETE_LINK_CYCLE > 0) {
         $sql = "DELETE FROM\twbb" . WBB_N . "_thread\n\t\t\t\tWHERE\t\tmovedTime > 0\n\t\t\t\t\t\tAND movedTime < " . (TIME_NOW - THREAD_DELETE_LINK_CYCLE * 86400);
         WCF::getDB()->sendQuery($sql);
     }
 }
 /**
  * @see Form::save()
  */
 public function save()
 {
     // build conditions
     $this->conditions = new ConditionBuilder();
     parent::save();
     // time
     if ($this->timeAfterDay && $this->timeAfterMonth && $this->timeAfterYear) {
         $time = @gmmktime(0, 0, 0, $this->timeAfterMonth, $this->timeAfterDay, $this->timeAfterYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("time > " . $time);
         }
     }
     if ($this->timeBeforeDay && $this->timeBeforeMonth && $this->timeBeforeYear) {
         $time = @gmmktime(0, 0, 0, $this->timeBeforeMonth, $this->timeBeforeDay, $this->timeBeforeYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("time < " . $time);
         }
     }
     // last post time
     if ($this->lastPostTimeAfterDay && $this->lastPostTimeAfterMonth && $this->lastPostTimeAfterYear) {
         $time = @gmmktime(0, 0, 0, $this->lastPostTimeAfterMonth, $this->lastPostTimeAfterDay, $this->lastPostTimeAfterYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("lastPostTime > " . $time);
         }
     }
     if ($this->lastPostTimeBeforeDay && $this->lastPostTimeBeforeMonth && $this->lastPostTimeBeforeYear) {
         $time = @gmmktime(0, 0, 0, $this->lastPostTimeBeforeMonth, $this->lastPostTimeBeforeDay, $this->lastPostTimeBeforeYear);
         if ($time !== false && $time !== -1) {
             $this->conditions->add("lastPostTime < " . $time);
         }
     }
     // replies
     if ($this->repliesMoreThan !== '') {
         $this->conditions->add('replies > ' . $this->repliesMoreThan);
     }
     if ($this->repliesLessThan !== '') {
         $this->conditions->add('replies < ' . $this->repliesLessThan);
     }
     // username
     if ($this->createdBy != '') {
         $users = preg_split('/\\s*,\\s*/', $this->createdBy, -1, PREG_SPLIT_NO_EMPTY);
         $users = array_map('escapeString', $users);
         $this->conditions->add("username IN ('" . implode("','", $users) . "')");
     }
     if ($this->postsBy != '') {
         $users = preg_split('/\\s*,\\s*/', $this->postsBy, -1, PREG_SPLIT_NO_EMPTY);
         $users = array_map('escapeString', $users);
         $this->conditions->add("threadID IN (SELECT DISTINCT threadID FROM wbb" . WBB_N . "_post WHERE username IN ('" . implode("','", $users) . "'))");
     }
     // prefix
     if ($this->prefix != '') {
         $this->conditions->add("prefix = '" . escapeString($this->prefix) . "'");
     }
     // boardIDs
     if (count($this->boardIDs)) {
         $this->conditions->add("boardID IN (" . implode(',', $this->boardIDs) . ")");
     }
     // language ids
     if (count($this->languageIDs)) {
         $this->conditions->add("languageID IN (" . implode(',', $this->languageIDs) . ")");
     }
     if ($this->deleted) {
         $this->conditions->add("isDeleted = 1");
     }
     if ($this->notDeleted) {
         $this->conditions->add("isDeleted = 0");
     }
     if ($this->disabled) {
         $this->conditions->add("isDisabled = 1");
     }
     if ($this->notDisabled) {
         $this->conditions->add("isDisabled = 0");
     }
     if ($this->closed) {
         $this->conditions->add("isClosed = 1");
     }
     if ($this->open) {
         $this->conditions->add("isClosed = 0");
     }
     if ($this->redirect) {
         $this->conditions->add("movedThreadID <> 0");
     }
     if ($this->notRedirect) {
         $this->conditions->add("movedThreadID = 0");
     }
     if ($this->announcement) {
         $this->conditions->add("isAnnouncement = 1");
     }
     if ($this->sticky) {
         $this->conditions->add("isSticky = 1");
     }
     if ($this->normal) {
         $this->conditions->add("isAnnouncement = 0 AND isSticky = 0");
     }
     // execute action
     $conditions = $this->conditions->get();
     switch ($this->action) {
         case 'move':
             $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\tSET\tboardID = " . $this->moveTo . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'delete':
             $threadIDs = '';
             $sql = "SELECT\tthreadID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t" . $conditions;
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($threadIDs)) {
                     $threadIDs .= ',';
                 }
                 $threadIDs .= $row['threadID'];
                 $this->affectedThreads++;
             }
             require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
             ThreadEditor::deleteAllCompletely($threadIDs);
             break;
         case 'trash':
         case 'restore':
             $threadIDs = '';
             $sql = "SELECT\tthreadID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t" . $conditions;
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($threadIDs)) {
                     $threadIDs .= ',';
                 }
                 $threadIDs .= $row['threadID'];
             }
             if (!empty($threadIDs)) {
                 // trash/restore posts
                 $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\t\tSET\tisDeleted = " . ($this->action == 'trash' ? 1 : 0) . "\n\t\t\t\t\t\t\t" . ($this->action == 'trash' ? ",deleteTime = " . TIME_NOW . ", deletedBy = '" . escapeString(WCF::getUser()->username) . "', deletedByID = " . WCF::getUser()->userID : '') . "\n\t\t\t\t\t\tWHERE\tthreadID IN (" . $threadIDs . ")";
                 WCF::getDB()->sendQuery($sql);
                 // trash/restore threads
                 $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\t\tSET\tisDeleted = " . ($this->action == 'trash' ? 1 : 0) . "\n\t\t\t\t\t\t\t" . ($this->action == 'trash' ? ",deleteTime = " . TIME_NOW . ", deletedBy = '" . escapeString(WCF::getUser()->username) . "', deletedByID = " . WCF::getUser()->userID : '') . "\n\t\t\t\t\t\tWHERE\tthreadID IN (" . $threadIDs . ")";
                 WCF::getDB()->sendQuery($sql);
                 $this->affectedThreads = WCF::getDB()->getAffectedRows();
             }
             break;
         case 'disable':
         case 'enable':
             $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\tSET\tisDisabled = " . ($this->action == 'disable' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'close':
         case 'open':
             $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\tSET\tisClosed = " . ($this->action == 'close' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'deleteSubscriptions':
             $sql = "DELETE FROM\twbb" . WBB_N . "_thread_subscription\n\t\t\t\t\tWHERE\t\tthreadID IN (\n\t\t\t\t\t\t\t\tSELECT\tthreadID\n\t\t\t\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t\t\t\t" . $conditions . "\t\n\t\t\t\t\t\t\t)";
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'changeLanguage':
             $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\tSET\tlanguageID = " . $this->newLanguageID . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'changePrefix':
             $sql = "UPDATE\twbb" . WBB_N . "_thread\n\t\t\t\t\tSET\tprefix = '" . escapeString($this->newPrefix) . "'\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedThreads = WCF::getDB()->getAffectedRows();
             break;
         case 'deleteLinks':
             $threadIDs = '';
             $sql = "SELECT\tthreadID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t" . $conditions;
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($threadIDs)) {
                     $threadIDs .= ',';
                 }
                 $threadIDs .= $row['threadID'];
                 $this->affectedThreads++;
             }
             if (!empty($threadIDs)) {
                 $sql = "DELETE FROM\twbb" . WBB_N . "_thread\n\t\t\t\t\t\tWHERE\t\tmovedThreadID IN (" . $threadIDs . ")";
                 WCF::getDB()->sendQuery($sql);
                 $this->affectedThreads = WCF::getDB()->getAffectedRows();
             }
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedThreads', $this->affectedThreads);
 }
 /**
  * Deletes this board.
  */
 public function delete()
 {
     // empty board
     // get alle thread ids
     $threadIDs = '';
     $sql = "SELECT\tthreadID\n\t\t\tFROM\twbb" . WBB_N . "_thread\n\t\t\tWHERE\tboardID = " . $this->boardID;
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!empty($threadIDs)) {
             $threadIDs .= ',';
         }
         $threadIDs .= $row['threadID'];
     }
     if (!empty($threadIDs)) {
         // delete threads
         require_once WBB_DIR . 'lib/data/thread/ThreadEditor.class.php';
         ThreadEditor::deleteAllCompletely($threadIDs);
     }
     $this->removePositions();
     // update sub boards
     $sql = "UPDATE\twbb" . WBB_N . "_board\n\t\t\tSET\tparentID = " . $this->parentID . "\n\t\t\tWHERE\tparentID = " . $this->boardID;
     WCF::getDB()->sendQuery($sql);
     $sql = "UPDATE\twbb" . WBB_N . "_board_structure\n\t\t\tSET\tparentID = " . $this->parentID . "\n\t\t\tWHERE\tparentID = " . $this->boardID;
     WCF::getDB()->sendQuery($sql);
     // delete board
     self::deleteData($this->boardID);
 }