public function LoadAPI()
 {
     $Bookmarks = $this->api->xpath("/eveapi/result/rowset[@name='folders']/row");
     foreach ($Bookmarks as $folder) {
         foreach ($folder->rowset->row as $bookmark) {
             $this->Bookmarks[] = $bookmark;
             $this->BookmarksByLocation[(int) locationTranslate($bookmark['locationID'])][] = count($this->Bookmarks) - 1;
         }
     }
     uksort($this->BookmarksByLocation, "sortfunc_bookmarklocname");
     return true;
 }
 public function loadAPI()
 {
     $result = $this->api->xpath("/eveapi/result/rowset[@name='assets']/row");
     $this->assets = array();
     foreach ($result as $entry) {
         $contents = getContents($entry);
         uasort($contents, "sortfunc_contents");
         $this->assets[(double) $entry["itemID"]] = $contents;
     }
     $itemTypes = array();
     $itemGroups = array();
     $allLocs = array();
     foreach ($this->assets as $item) {
         $itemTypes = add_items($itemTypes, $item);
         $allLocs[locationTranslate($item["locationID"])] = 1;
     }
     $this->Db->cacheItemTypes(array_keys($itemTypes));
     $this->Db->cacheLocationIds(array_keys($allLocs));
     foreach ($this->assets as $item) {
         $itemGroups = add_groups($this->Db, $itemGroups, $item);
     }
     $this->Db->cacheGroupTypes(array_keys($itemGroups));
     global $sortDb;
     $sortDb = $this->Db;
     uasort($this->assets, "sortfunc_locname");
     $this->assetsByLocation = array();
     foreach ($this->assets as $itemId => $item) {
         $locid = locationTranslate($item["locationID"]);
         if (!isset($this->assetsByLocation[$locid])) {
             $this->assetsByLocation[locationTranslate($locid)] = array($item['itemID'] => $item);
         } else {
             $this->assetsByLocation[locationTranslate($locid)][$item['itemID']] = $item;
         }
     }
     $this->totalCt = count($this->api->xpath("//row"));
     //print_r($this->assets);
     return true;
 }
 public function loadAPI()
 {
     $result = $this->api->xpath("/eveapi/result/rowset/row");
     usort($result, "contracts_default_sortfunc");
     if ($this->corp) {
         $filtered = array();
         foreach ($result as $entry) {
             if ($entry["issuerCorpID"] == CORP_ID && $entry["forCorp"] == "1" || $entry["acceptorID"] == CORP_ID || $entry["assigneeID"] == CORP_ID) {
                 // TODO: should not depend on CORP_ID - api should be unaware of audit.php
                 $filtered[] = $entry;
             }
         }
         $result = $filtered;
     }
     $result = array_slice($result, $this->start, $this->limit);
     $idsTR = array();
     $locations = array();
     $ctrctids = array();
     $nonCourierIDs = array();
     $this->count = count($result);
     foreach ($result as $entry) {
         $ctrctids[] = (double) $entry["contractID"];
         if ($entry["type"] != "Courier") {
             $nonCourierIDs[] = (double) $entry["contractID"];
         }
     }
     if ($this->getItems && $nonCourierIDs) {
         $items = $this->fetchItems($nonCourierIDs);
     }
     foreach ($result as $entry) {
         $idsTR[(double) $entry["issuerID"]] = "1";
         $idsTR[(double) $entry["issuerCorpID"]] = "1";
         if ((double) $entry["assigneeID"] != 0) {
             $idsTR[(double) $entry["assigneeID"]] = "1";
         }
         if ((double) $entry["acceptorID"] != 0) {
             $idsTR[(double) $entry["acceptorID"]] = "1";
         }
         if ((string) $entry["type"] == "Auction") {
             if (!$this->hasAuctions) {
                 $this->fetchBids($ctrctids);
                 if (count($this->bids) > 0) {
                     foreach ($this->bids as $bidset) {
                         foreach ($bidset as $bid) {
                             $idsTR[$bid["bidderID"]] = "1";
                         }
                     }
                 }
             }
         }
         $locations[locationTranslate((double) $entry["startStationID"])] = "1";
         $locations[locationTranslate((double) $entry["endStationID"])] = "1";
     }
     $ids = idlookup($this->Db->link, array_keys($idsTR));
     $this->Db->cacheLocationIds(array_keys($locations));
     // ensuring only one lookup of each
     $locations = array();
     foreach ($result as $entry) {
         $locations[$this->Db->getSystemFromStationId(locationTranslate((double) $entry["startStationID"]))] = "1";
         $locations[$this->Db->getSystemFromStationId(locationTranslate((double) $entry["endStationID"]))] = "1";
     }
     $this->Db->cacheLocationIds(array_keys($locations));
     // system names
     $entries = array();
     foreach ($result as $entry) {
         $new = array();
         foreach ($entry->attributes() as $name => $value) {
             // copy item attributes
             $new[(string) $name] = (string) $value;
         }
         // todo
         $cid = (double) $entry["contractID"];
         $new["issuer"] = $ids[(double) $entry["issuerID"]];
         $new["issuerCorp"] = $ids[(double) $entry["issuerCorpID"]];
         $new["assignee"] = (double) $entry["assigneeID"] != 0 ? $ids[(double) $entry["assigneeID"]] : "";
         $new["acceptor"] = (double) $entry["acceptorID"] != 0 ? $ids[(double) $entry["acceptorID"]] : "";
         $new["startStation"] = $this->Db->getLocationNameFromId(locationTranslate((double) $entry["startStationID"]));
         $new["endStation"] = $this->Db->getLocationNameFromId(locationTranslate((double) $entry["endStationID"]));
         $new["startSystemID"] = $this->Db->getSystemFromStationId(locationTranslate((double) $entry["startStationID"]));
         $new["endSystemID"] = $this->Db->getSystemFromStationId(locationTranslate((double) $entry["endStationID"]));
         $new["startSystem"] = $this->Db->getLocationNameFromId($new["startSystemID"]);
         $new["System"] = $new["startSystem"];
         $new["endSystem"] = $this->Db->getLocationNameFromId($new["endSystemID"]);
         if ((string) $new["status"] == "CompletedByContractor") {
             $new["status"] = "Unclaimed";
         }
         if (!CONTRACT_ACTIVE((string) $entry["status"])) {
             if ((string) $entry["status"] == "Failed") {
                 $new["dateFinished"] = "FAILED";
             } else {
                 $new["dateFinished"] = (string) $entry["dateCompleted"];
             }
             $new["timeRemaining"] = 0;
         } else {
             if ((string) $entry["type"] == "Courier" && (string) $entry["status"] == "InProgress") {
                 $new["dateFinished"] = "";
                 // $entry["dateExpired"];
                 $new["timeRemaining"] = (int) (string) $entry["numDays"] * 3600 * 24 - (strtotime((string) $this->api->currentTime) - strtotime((string) $entry["dateAccepted"]));
             } else {
                 $new["timeRemaining"] = strtotime((string) $entry["dateExpired"]) - strtotime((string) $this->api->currentTime);
                 if ($new["timeRemaining"] < 0) {
                     $new["dateFinished"] = (string) $entry["dateExpired"];
                     $new["timeRemaining"] = 0;
                     $new["status"] = "Expired";
                 } else {
                     $new["dateFinished"] = "";
                 }
                 // $entry["dateExpired"];
             }
         }
         if ($entry["title"] != "") {
             $new["desc"] = "<b>Title: </b>{$entry['title']}";
         } else {
             $new["desc"] = "";
         }
         if ((string) $entry["type"] == "Courier") {
             $new["desc"] .= ($new["desc"] = "" ? "<br>" : "") . "<b>Destination: </b>{$new['endStation']}";
             if ((double) $entry["collateral"] != 0) {
                 $new["desc"] .= "<br><b>Collateral: <span style=\"color:#aa0;\">" . number_format((double) $entry["collateral"], 2) . " ISK</span></b>";
             }
             if ((double) $entry["acceptorID"] != 0) {
                 $new["desc"] .= "<br><b>Accepted:</b> {$entry['dateAccepted']}</span>";
             }
         }
         if ((string) $entry["type"] == "ItemExchange") {
             if ((double) $entry["reward"] > 0) {
                 $new["Type"] = "WTB";
             } else {
                 if ((double) $entry["reward"] == (double) $entry["price"]) {
                     $new["Type"] = "Gift";
                 } else {
                     $new["Type"] = "WTS";
                 }
             }
         } else {
             $new["Type"] = (string) $entry["type"];
             if ((string) $entry["type"] == "Auction") {
                 if (isset($this->bids[$cid])) {
                     $bid = $this->bids[$cid][0];
                     $new["price"] = $bid["amount"];
                     $new["desc"] .= "<br><b>Last Bid:</b> " . $bid["bidTime"] . "</span>";
                     $new["bidder"] = "#" . count($this->bids[$cid]) . ", " . $ids[$bid["bidderID"]];
                 } else {
                     $new["bidder"] = "";
                 }
             }
         }
         if ($this->getItems && (string) $entry["type"] != "Courier") {
             $buying = $items[(double) $entry["contractID"]]["buying"];
             $selling = $items[(double) $entry["contractID"]]["selling"];
             if (count($buying) > 0 && count($selling) > 0) {
                 $new["Type"] = "Trade";
             }
             $new["buying"] = $buying;
             $new["selling"] = $selling;
         }
         $entries[] = $new;
     }
     if ($this->getItems) {
         if (count($this->typesToCache) > 0) {
             $types = array_keys($this->typesToCache);
             $this->Db->cacheItemTypes($types);
             $groupsToCache = array();
             foreach ($types as $typeID) {
                 $type = $this->Db->getTypeFromTypeId($typeID);
                 $groupsToCache[] = $type["groupID"];
             }
             $this->Db->cacheGroupTypes($groupsToCache);
             $this->Db->cacheMetaLevelsIDs($types);
         }
         foreach ($entries as &$entry) {
             $entry["buyingItems"] = "";
             $entry["buyingItemsList"] = "";
             $entry["sellingItems"] = "";
             $entry["sellingItemsList"] = "";
             if (isset($entry["buying"])) {
                 listItems($this->Db, $entry["buying"], $entry["buyingItems"], $entry["buyingItemsList"]);
                 listItems($this->Db, $entry["selling"], $entry["sellingItems"], $entry["sellingItemsList"]);
             } else {
                 $entry["buying"] = array();
                 $entry["selling"] = array();
             }
         }
     }
     usort($entries, "contracts_default_sortfunc");
     $this->entries = $entries;
     return true;
 }
 public function cacheLocationIds($locations)
 {
     $sqlStations = array();
     $sqlSystems = array();
     foreach ($locations as $location) {
         if ($location < 60000000) {
             // items in space
             $sqlSystems[$location] = 1;
         } else {
             $sqlStations[locationTranslate($location)] = 1;
         }
     }
     $Locations = array();
     if (count($sqlStations) != 0) {
         $result = $this->query("SELECT stationID, stationName, solarSystemID FROM " . DB_PREFIX . "staStations WHERE stationID IN (" . implode(",", array_keys($sqlStations)) . ")");
         while ($row = mysql_fetch_assoc($result)) {
             $this->locationCache[$row['stationID']] = $row['stationName'];
             $this->stationToSystemCache[$row['stationID']] = $row['solarSystemID'];
         }
         mysql_free_result($result);
     }
     if (count($sqlSystems) != 0) {
         $result = $this->query("SELECT solarSystemID, solarSystemName FROM " . DB_PREFIX . "mapSolarSystems WHERE solarSystemID IN ('" . implode("','", array_keys($sqlSystems)) . "')");
         while ($row = mysql_fetch_assoc($result)) {
             $this->locationCache[$row['solarSystemID']] = $row['solarSystemName'];
         }
         mysql_free_result($result);
     }
 }
Beispiel #5
0
 public function cacheLocationIds($locations)
 {
     $sqlStations = array();
     $sqlSystems = array();
     foreach ($locations as $location) {
         if ($location < 60000000) {
             // items in space
             $sqlSystems[$location] = 1;
         } else {
             $sqlStations[locationTranslate($location)] = 1;
         }
     }
     $Locations = array();
     if (count($sqlStations) != 0) {
         //$result = $this->query("SELECT stationID, stationName, solarSystemID FROM ".DB_PREFIX."staStations WHERE stationID IN (".implode(",",array_keys($sqlStations)).")");
         $result = $this->selectWhere("staStations", ['stationID' => ['IN', array_keys($sqlStations)]], ['stationID', 'stationName', 'solarSystemID']);
         foreach ($result->results as $row) {
             $this->locationCache[$row['stationID']] = $row['stationName'];
             $this->stationToSystemCache[$row['stationID']] = $row['solarSystemID'];
         }
     }
     if (count($sqlSystems) != 0) {
         // $result = $this->query("SELECT solarSystemID, solarSystemName FROM ".DB_PREFIX."mapSolarSystems WHERE solarSystemID IN ('".implode("','",array_keys($sqlSystems))."')");
         $result = $this->selectWhere("mapSolarSystems", ['solarSystemID' => ['IN', array_keys($sqlSystems)]], ['solarSystemID', 'solarSystemName']);
         foreach ($result->results as $row) {
             $this->locationCache[$row['solarSystemID']] = $row['solarSystemName'];
         }
     }
 }