/**
  * @see	Page::assignVariables()
  */
 public function readParameters()
 {
     parent::readParameters();
     if (!count($_POST)) {
         // refresh package database
         PackageUpdate::refreshPackageDatabase();
     }
     // get updatable packages
     $this->availableUpdates = PackageUpdate::getAvailableUpdates();
 }
 /**
  * @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);
     }
 }