コード例 #1
0
ファイル: Where.php プロジェクト: solution10/sql
 /**
  * Returns an array of all the parameter that have been passed to where()
  * ready to be thrown at PDO.
  *
  * @return  array
  */
 public function getWhereParams()
 {
     return isset($this->whereBuilder) ? $this->whereBuilder->getConditionParameters() : [];
 }
コード例 #2
0
 /**
  * @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);
 }
コード例 #3
0
ファイル: Having.php プロジェクト: solution10/sql
 /**
  * Returns an array of all the parameter that have been passed to having()
  * ready to be thrown at PDO.
  *
  * @return  array
  */
 public function getHavingParams()
 {
     return isset($this->havingBuilder) ? $this->havingBuilder->getConditionParameters() : [];
 }
コード例 #4
0
 /**
  * @see Form::save()
  */
 public function save()
 {
     parent::save();
     // build conditions
     $this->conditions = new ConditionBuilder();
     // static fields
     if (!empty($this->username)) {
         $this->conditions->add("user.username LIKE '%" . addcslashes(escapeString($this->username), '_%') . "%'");
     }
     if (!empty($this->email)) {
         $this->conditions->add("user.email LIKE '%" . addcslashes(escapeString($this->email), '_%') . "%'");
     }
     if (count($this->groupIDArray) > 0) {
         $this->conditions->add("user.userID " . ($this->invertGroupIDs == 1 ? 'NOT ' : '') . "IN (SELECT userID FROM wcf" . WCF_N . "_user_to_groups WHERE groupID IN (" . implode(',', $this->groupIDArray) . "))");
     }
     if (count($this->languageIDArray) > 0) {
         $this->conditions->add("user.languageID IN (" . implode(',', $this->languageIDArray) . ")");
     }
     // dynamic fields
     foreach ($this->activeOptions as $name => $option) {
         $value = isset($this->values[$option['optionName']]) ? $this->values[$option['optionName']] : null;
         $condition = $this->getTypeObject($option['optionType'])->getCondition($option, $value, isset($this->matchExactly[$name]));
         if ($condition !== false) {
             $this->conditions->add($condition);
         }
     }
     // call buildConditions event
     EventHandler::fireAction($this, 'buildConditions');
     // execute action
     switch ($this->action) {
         case 'sendMail':
             WCF::getUser()->checkPermission('admin.user.canMailUser');
             // get user ids
             $userIDArray = array();
             $sql = "SELECT\t\tuser.userID\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\t" . $this->conditions->get();
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 $userIDArray[] = $row['userID'];
                 $this->affectedUsers++;
             }
             // save config in session
             $userMailData = WCF::getSession()->getVar('userMailData');
             if ($userMailData === null) {
                 $userMailData = array();
             }
             $mailID = count($userMailData);
             $userMailData[$mailID] = array('action' => '', 'userIDs' => implode(',', $userIDArray), 'groupIDs' => '', 'subject' => $this->subject, 'text' => $this->text, 'from' => $this->from, 'enableHTML' => $this->enableHTML);
             WCF::getSession()->register('userMailData', $userMailData);
             $this->saved();
             // show worker template
             WCF::getTPL()->assign(array('pageTitle' => WCF::getLanguage()->get('wcf.acp.user.sendMail'), 'url' => 'index.php?action=UserMail&mailID=' . $mailID . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED));
             WCF::getTPL()->display('worker');
             exit;
             break;
         case 'exportMailAddress':
             WCF::getUser()->checkPermission('admin.user.canMailUser');
             // send content type
             header('Content-Type: text/' . $this->fileType . '; charset=' . CHARSET);
             header('Content-Disposition: attachment; filename="export.' . $this->fileType . '"');
             if ($this->fileType == 'xml') {
                 echo "<?xml version=\"1.0\" encoding=\"" . CHARSET . "\"?>\n<addresses>\n";
             }
             // get users
             $sql = "SELECT\t\tuser.email\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\t" . $this->conditions->get() . "\n\t\t\t\t\tORDER BY\tuser.email";
             $result = WCF::getDB()->sendQuery($sql);
             $i = 0;
             $j = WCF::getDB()->countRows($result) - 1;
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if ($this->fileType == 'xml') {
                     echo "<address><![CDATA[" . StringUtil::escapeCDATA($row['email']) . "]]></address>\n";
                 } else {
                     echo $this->textSeparator . $row['email'] . $this->textSeparator . ($i < $j ? $this->separator : '');
                 }
                 $i++;
                 $this->affectedUsers++;
             }
             if ($this->fileType == 'xml') {
                 echo "</addresses>";
             }
             $this->saved();
             exit;
             break;
         case 'assignToGroup':
             WCF::getUser()->checkPermission('admin.user.canEditUser');
             $userIDArray = array();
             $sql = "SELECT\t\tuser.*,\n\t\t\t\t\t\t\tGROUP_CONCAT(groupID SEPARATOR ',') AS groupIDs\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_to_groups groups\n\t\t\t\t\tON\t\t(groups.userID = user.userID)\n\t\t\t\t\t" . $this->conditions->get() . "\t\t\n\t\t\t\t\tGROUP BY\tuser.userID";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!Group::isAccessibleGroup(explode(',', $row['groupIDs']))) {
                     throw new PermissionDeniedException();
                 }
                 $user = new UserEditor(null, $row);
                 $user->addToGroups($this->assignToGroupIDArray, false, false);
                 $userIDArray[] = $row['userID'];
                 $this->affectedUsers++;
             }
             Session::resetSessions($userIDArray);
             break;
         case 'delete':
             WCF::getUser()->checkPermission('admin.user.canDeleteUser');
             $userIDArray = array();
             $sql = "SELECT\t\tuser.*,\n\t\t\t\t\t\t\tGROUP_CONCAT(groupID SEPARATOR ',') AS groupIDs\n\t\t\t\t\tFROM\t\twcf" . WCF_N . "_user user\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_option_value option_value USING (userID)\n\t\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_user_to_groups groups\n\t\t\t\t\tON\t\t(groups.userID = user.userID)\n\t\t\t\t\t" . $this->conditions->get() . "\t\t\n\t\t\t\t\tGROUP BY\tuser.userID";
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!Group::isAccessibleGroup(explode(',', $row['groupIDs']))) {
                     throw new PermissionDeniedException();
                 }
                 $userIDArray[] = $row['userID'];
                 $this->affectedUsers++;
             }
             UserEditor::deleteUsers($userIDArray);
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedUsers', $this->affectedUsers);
 }
コード例 #5
0
 /**
  * @see Form::save()
  */
 public function save()
 {
     // build conditions
     $this->conditions = new ConditionBuilder();
     parent::save();
     // boardIDs
     if (count($this->boardIDs)) {
         $this->conditions->add("threadID IN (SELECT threadID FROM wbb" . WBB_N . "_thread WHERE boardID IN (" . implode(',', $this->boardIDs) . "))");
     }
     // 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);
         }
     }
     // 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) . "')");
     }
     // status
     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");
     }
     // execute action
     $conditions = $this->conditions->get();
     switch ($this->action) {
         case 'delete':
             $postIDs = '';
             $sql = "SELECT\tpostID\n\t\t\t\t\tFROM\twbb" . WBB_N . "_post\n\t\t\t\t\t" . $conditions;
             $result = WCF::getDB()->sendQuery($sql);
             while ($row = WCF::getDB()->fetchArray($result)) {
                 if (!empty($postIDs)) {
                     $postIDs .= ',';
                 }
                 $postIDs .= $row['postID'];
                 $this->affectedPosts++;
             }
             // get thread ids
             $threadIDs = PostEditor::getThreadIDs($postIDs);
             // delete posts
             PostEditor::deleteAllCompletely($postIDs);
             // check threads
             ThreadEditor::checkVisibilityAll($threadIDs);
             break;
         case 'trash':
         case 'restore':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisDeleted = " . ($this->action == 'trash' ? 1 : 0) . "\n\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" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
         case 'disable':
         case 'enable':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisDisabled = " . ($this->action == 'disable' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
         case 'close':
         case 'open':
             $sql = "UPDATE\twbb" . WBB_N . "_post\n\t\t\t\t\tSET\tisClosed = " . ($this->action == 'close' ? 1 : 0) . "\n\t\t\t\t\t" . $conditions;
             WCF::getDB()->sendQuery($sql);
             $this->affectedPosts = WCF::getDB()->getAffectedRows();
             break;
     }
     $this->saved();
     WCF::getTPL()->assign('affectedPosts', $this->affectedPosts);
 }
コード例 #6
0
 /**
  * @see Form::validate()
  */
 public function validate()
 {
     parent::validate();
     // refresh package database
     PackageUpdate::refreshPackageDatabase($this->packageUpdateServerIDs);
     // build conditions
     require_once WCF_DIR . 'lib/system/database/ConditionBuilder.class.php';
     $conditions = new ConditionBuilder();
     // update servers
     if (count($this->packageUpdateServerIDs)) {
         $conditions->add('packageUpdateServerID IN (' . implode(',', $this->packageUpdateServerIDs) . ')');
     }
     // name
     if (!empty($this->packageName)) {
         $condition = "packageName LIKE '%" . escapeString($this->packageName) . "%'";
         if ($this->searchDescription == 1) {
             $condition .= " OR packageDescription LIKE '%" . escapeString($this->packageName) . "%'";
         }
         $conditions->add('(' . $condition . ')');
     }
     // author
     if (!empty($this->author)) {
         $conditions->add("author LIKE '" . escapeString($this->author) . "%'");
     }
     // ignore already installed uniques
     if ($this->ignoreUniques == 1) {
         $conditions->add("package NOT IN (SELECT package FROM wcf" . WCF_N . "_package WHERE isUnique = 1)");
     }
     // package type
     if (($this->plugin == 0 || $this->standalone == 0 || $this->other == 0) && ($this->plugin == 1 || $this->standalone == 1 || $this->other == 1)) {
         if ($this->standalone == 1) {
             $condition = 'standalone = 1';
             if ($this->plugin == 1) {
                 $condition .= " OR plugin IN (SELECT package FROM wcf" . WCF_N . "_package)";
             } else {
                 if ($this->other == 1) {
                     $condition .= " OR plugin = ''";
                 }
             }
             $conditions->add('(' . $condition . ')');
         } else {
             if ($this->plugin == 1) {
                 $condition = "plugin IN (SELECT package FROM wcf" . WCF_N . "_package)";
                 if ($this->other == 1) {
                     $condition .= " OR standalone = 0";
                 }
                 $conditions->add('(' . $condition . ')');
             } else {
                 if ($this->other) {
                     $conditions->add("(standalone = 0 AND plugin = '')");
                 }
             }
         }
     }
     // search package database
     $packages = array();
     $packageUpdateIDs = '';
     $sql = "SELECT\tpackage, packageUpdateID\n\t\t\tFROM\twcf" . WCF_N . "_package_update\n\t\t\t" . $conditions->get();
     $result = WCF::getDB()->sendQuery($sql, 1000);
     while ($row = WCF::getDB()->fetchArray($result)) {
         if (!empty($packageUpdateIDs)) {
             $packageUpdateIDs .= ',';
         }
         $packageUpdateIDs .= $row['packageUpdateID'];
         if (!isset($packages[$row['package']])) {
             $packages[$row['package']] = array();
         }
         $packages[$row['package']][$row['packageUpdateID']] = array();
     }
     if (empty($packageUpdateIDs)) {
         throw new UserInputException('packageName');
     }
     // remove duplicates
     $sql = "SELECT\t\tpuv.packageVersion, pu.package, pu.packageUpdateID\n\t\t\tFROM\t\twcf" . WCF_N . "_package_update_version puv\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_package_update pu\n\t\t\tON\t\t(pu.packageUpdateID = puv.packageUpdateID)\n\t\t\tWHERE\t\tpuv.packageUpdateID IN (" . $packageUpdateIDs . ")";
     $result = WCF::getDB()->sendQuery($sql);
     while ($row = WCF::getDB()->fetchArray($result)) {
         $packages[$row['package']][$row['packageUpdateID']][] = $row['packageVersion'];
     }
     foreach ($packages as $identifier => $packageUpdates) {
         if (count($packageUpdates) > 1) {
             foreach ($packageUpdates as $packageUpdateID => $versions) {
                 usort($versions, array('Package', 'compareVersion'));
                 $packageUpdates[$packageUpdateID] = array_pop($versions);
             }
             uasort($packageUpdates, array('Package', 'compareVersion'));
         }
         $keys = array_keys($packageUpdates);
         if (!empty($this->packageUpdateIDs)) {
             $this->packageUpdateIDs .= ',';
         }
         $this->packageUpdateIDs .= array_pop($keys);
     }
 }
 protected function buildConditions(ConditionBuilder $conditions)
 {
     // registration date
     if ($this->registrationDateAfterDay && $this->registrationDateAfterMonth && $this->registrationDateAfterYear) {
         $time = @gmmktime(0, 0, 0, $this->registrationDateAfterMonth, $this->registrationDateAfterDay, $this->registrationDateAfterYear);
         if ($time !== false && $time !== -1) {
             $conditions->add("user.registrationDate > " . $time);
         }
     }
     if ($this->registrationDateBeforeDay && $this->registrationDateBeforeMonth && $this->registrationDateBeforeYear) {
         $time = @gmmktime(0, 0, 0, $this->registrationDateBeforeMonth, $this->registrationDateBeforeDay, $this->registrationDateBeforeYear);
         if ($time !== false && $time !== -1) {
             $conditions->add("user.registrationDate < " . $time);
         }
     }
     // last activity
     if ($this->lastActivityAfterDay && $this->lastActivityAfterMonth && $this->lastActivityAfterYear) {
         $time = @gmmktime(0, 0, 0, $this->lastActivityAfterMonth, $this->lastActivityAfterDay, $this->lastActivityAfterYear);
         if ($time !== false && $time !== -1) {
             $conditions->add("user.lastActivityTime > " . $time);
         }
     }
     if ($this->lastActivityBeforeDay && $this->lastActivityBeforeMonth && $this->lastActivityBeforeYear) {
         $time = @gmmktime(0, 0, 0, $this->lastActivityBeforeMonth, $this->lastActivityBeforeDay, $this->lastActivityBeforeYear);
         if ($time !== false && $time !== -1) {
             $conditions->add("user.lastActivityTime < " . $time);
         }
     }
     // posts
     if ($this->postsGreaterThan !== '' || $this->postsLessThan !== '') {
         $postsCondition = '';
         if ($this->postsGreaterThan !== '') {
             $postsCondition .= "posts > " . $this->postsGreaterThan;
         }
         if ($this->postsLessThan !== '') {
             if (!empty($postsCondition)) {
                 $postsCondition .= " AND ";
             }
             $postsCondition .= "posts < " . $this->postsLessThan;
         }
         $conditions->add("user.userID IN (SELECT userID FROM wbb" . WBB_N . "_user WHERE " . $postsCondition . ")");
     }
     // ip address
     if ($this->registrationIpAddress1 !== '' || $this->registrationIpAddress2 !== '' || $this->registrationIpAddress3 !== '' || $this->registrationIpAddress4 !== '') {
         $ipAddress = ($this->registrationIpAddress1 !== '' ? $this->registrationIpAddress1 : '%') . '.' . ($this->registrationIpAddress2 !== '' ? $this->registrationIpAddress2 : '%') . '.' . ($this->registrationIpAddress3 !== '' ? $this->registrationIpAddress3 : '%') . '.' . ($this->registrationIpAddress4 !== '' ? $this->registrationIpAddress4 : '%');
         $conditions->add("user.registrationIpAddress LIKE '" . escapeString($ipAddress) . "'");
     }
     // status
     if ($this->enabled) {
         $conditions->add("user.activationCode = 0");
     }
     if ($this->notEnabled) {
         $conditions->add("user.activationCode <> 0");
     }
     if ($this->banned) {
         $conditions->add("user.banned <> 0");
     }
     if ($this->notBanned) {
         $conditions->add("user.banned = 0");
     }
     if ($this->hasSpecialPermissions) {
         $conditions->add("user.userID IN (SELECT userID FROM wbb" . WBB_N . "_board_to_user)");
     }
 }
コード例 #8
0
 /**
  * Returns the conditions for a search in the table of this search type.
  */
 public function getConditions($form = null)
 {
     $this->readFormParameters($form);
     $boardIDs = $this->boardIDs;
     if (count($boardIDs) && $boardIDs[0] == '*') {
         $boardIDs = array();
     }
     // remove empty elements
     foreach ($boardIDs as $key => $boardID) {
         if ($boardID == '-') {
             unset($boardIDs[$key]);
         }
     }
     // get all boards from cache
     require_once WBB_DIR . 'lib/data/board/Board.class.php';
     $this->boards = WCF::getCache()->get('board', 'boards');
     $this->boardStructure = WCF::getCache()->get('board', 'boardStructure');
     $this->selectedBoards = array();
     // check whether the selected board does exist
     foreach ($boardIDs as $boardID) {
         if (!isset($this->boards[$boardID]) || !$this->boards[$boardID]->searchable) {
             throw new UserInputException('boardIDs', 'notValid');
         }
         if (!isset($this->selectedBoards[$boardID])) {
             $this->selectedBoards[$boardID] = $this->boards[$boardID];
             // include children
             $this->includeSubBoards($boardID);
         }
     }
     if (count($this->selectedBoards) == 0) {
         $this->selectedBoards = $this->boards;
     }
     // check permission of the active user
     foreach ($this->selectedBoards as $board) {
         if (WCF::getUser()->isIgnoredBoard($board->boardID) || !$board->getPermission() || !$board->getPermission('canEnterBoard') || !$board->getPermission('canReadThread') || !$board->searchable) {
             unset($this->selectedBoards[$board->boardID]);
         }
     }
     if (count($this->selectedBoards) == 0) {
         throw new PermissionDeniedException();
     }
     // build board id list
     $selectedBoardIDs = '';
     if (count($this->selectedBoards) != count($this->boards)) {
         foreach ($this->selectedBoards as $board) {
             if (!empty($selectedBoardIDs)) {
                 $selectedBoardIDs .= ',';
             }
             $selectedBoardIDs .= $board->boardID;
         }
     }
     // build final condition
     require_once WCF_DIR . 'lib/system/database/ConditionBuilder.class.php';
     $condition = new ConditionBuilder(false);
     // board ids
     if (!empty($selectedBoardIDs)) {
         $this->threadTableJoin = true;
         $condition->add('thread.threadID = messageTable.threadID');
         $condition->add('thread.boardID IN (' . $selectedBoardIDs . ')');
     } else {
         if ($this->findThreads || count(WCF::getSession()->getVisibleLanguageIDArray()) || $this->threadTableJoin) {
             $condition->add('thread.threadID = messageTable.threadID');
         }
     }
     // find user threads
     if ($this->findUserThreads && $form !== null && ($userIDs = $form->getUserIDs())) {
         $condition->add('thread.userID IN (' . implode(',', $userIDs) . ')');
     }
     // thread id
     if ($this->threadID != 0) {
         $condition->add('messageTable.threadID = ' . $this->threadID);
     }
     $condition->add('messageTable.isDeleted = 0');
     $condition->add('messageTable.isDisabled = 0');
     // find attachments
     if ($this->findAttachments) {
         $condition->add('messageTable.attachments > 0');
     }
     // find polls
     if ($this->findPolls) {
         $condition->add('messageTable.pollID > 0');
     }
     // language
     if (count(WCF::getSession()->getVisibleLanguageIDArray())) {
         $condition->add('thread.languageID IN (' . implode(',', WCF::getSession()->getVisibleLanguageIDArray()) . ')');
     }
     // return sql condition
     return '(' . $condition->get() . ')' . ($this->findThreads ? '/* findThreads */' : '') . ($this->findUserThreads ? '/* findUserThreads */' : '');
 }