コード例 #1
0
 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;
 }
コード例 #2
0
    public function GetOutput($Db)
    {
        global $sort, $ord, $cols;
        // req for sorting
        $Contracts = new eveApiContracts($Db);
        $full_url = FULL_URL;
        // TODO
        $time_start = microtime_float();
        if (!$Contracts->fetch(CHAR_ID, USER_ID, API_KEY, CORP_MODE)) {
            $this->Output = $Contracts->Error;
            return false;
        }
        $time_end = microtime_float();
        $time_api = $time_end - $time_start;
        $Db->updateConqStations();
        $this->Updated = APITime($Contracts);
        $this->Title = "Contracts for " . USER_NAME;
        if (isset($_GET['testing'])) {
            die("<pre>" . print_r($Contracts->entries, true) . "</pre>");
        }
        $ord = "ASC";
        $cols = array("Type", "status", "System", "dateIssued", "dateFinished", "issuer", "contractor", "Price", "volume", "desc");
        $sort = null;
        $this->Output .= sort_ctrl();
        //$this->Output .= "<h5 style=\"display: inline\">### PAGE UNDER CONSTRUCTION - WATCH FOR ANVILS ###</h5>";
        if (count($Contracts->entries) > 0) {
            $this->Output .= <<<LEGENDEND
<table border="1" style="font-size: 80%; border-style: solid;">

<tr><th colspan="2">LEGEND</th></tr>
<tr><th>time format</th><td>[Month.Days.Years] Hours:Minutes</td></tr>
<tr><th>blue row:</th><td>this contract is on behalf of your corporation</td></tr>
<tr><th>orange volume:</th><td>volume is greater than 30,000 m3</td></tr>
<tr><th>yellow time:</th><td>less than 24hrs left on auction</td></tr>
<tr><th>red time:</th><td>less than 1 hour left on auction</td></tr>
<tr><th>red price:</th><td>this is the price that was/will be paid <b style="color:red">by</b> the contract acceptor</td></tr>
<tr><th>green price:</th><td>this is the price that was/will be paid <b style="color:#0f0">to</b> the contract acceptor</td></tr>
<tr><th>&lt;assignee&gt;</th><td>contract is assigned to assignee but has not been accepted</td></tr>
</table><br>
LEGENDEND;
            $this->Output .= count($Contracts->entries) . " entries. <b>Click an entry to get contract details.</b><br><br>";
            $this->Output .= "<table class=\"contracts_table\" style=\"font-size:83%;\" border=1>";
            $this->Output .= "<tr>";
            foreach ($cols as $col) {
                $this->Output .= "<th>";
                if (!isset($nosorting)) {
                    $this->Output .= "<a href=\"{$full_url}&view=contracts&sort={$col}&order=" . ($sort == $col && $ord == "ASC" ? "DESC" : "ASC") . "\">";
                }
                $this->Output .= $col;
                if (!isset($nosorting)) {
                    $this->Output .= "</a>";
                }
                $this->Output .= "</th>";
            }
            $this->Output .= "</tr>";
            $entries = $Contracts->entries;
            $ids = array();
            foreach ($entries as &$entry) {
                if ((string) $entry["availability"] == "Private" && $entry["acceptor"] == "") {
                    $entry["contractor"] = $entry["assignee"];
                } else {
                    if ($entry["acceptor"] == "") {
                        if (isset($entry["bidder"])) {
                            if ($entry["bidder"] == "") {
                                $entry["contractor"] = "";
                            } else {
                                $entry["contractor"] = "{$entry['bidder']}";
                            }
                        } else {
                            $entry["contractor"] = "";
                        }
                    } else {
                        $entry["contractor"] = $entry["acceptor"];
                    }
                }
                $entry["Price"] = ($entry["reward"] > 0 || $entry["reward"] == $entry["price"] ? -1 : 1) * (double) ($entry["price"] + (double) $entry["reward"]);
                $ids[] = (string) $entry['issuerID'];
                $ids[] = (string) $entry['assigneeID'];
            }
            $ids = array_unique($ids);
            $redIDS = GetRedIDS($ids, $Db);
            if (isset($redIDS[0]) && $redIDS[0] == 0) {
                $redIDS = array();
            }
            unset($entry);
            if ($sort != null && array_key_exists($sort, $entries[0])) {
                usort($entries, "globl_sortfunc");
            }
            $alt_b = false;
            $rowclass = " class=\"nohover" . (isset($_GET['expandall']) ? "" : " contractbody") . "\"";
            foreach ($entries as $entry) {
                $alt_b = !$alt_b;
                $hasItems = isset($entry["buying"]) && ($entry["sellingItems"] != "" || $entry["buyingItems"] != "");
                $this->Output .= "<tr onclick=\"toggle_row_visibility('contract" . $entry["contractID"] . "'); return false;\"";
                if (in_array($entry['issuerID'], $redIDS) || in_array($entry['assigneeID'], $redIDS)) {
                    if ($alt_b) {
                        $this->Output .= " class=\"redAlt";
                    } else {
                        $this->Output .= " class=\"redMain";
                    }
                } else {
                    if ($alt_b) {
                        $this->Output .= " class=\"alt";
                    } else {
                        $this->Output .= " class=\"main";
                    }
                }
                $this->Output .= ($entry["forCorp"] == 1 ? " corp_entry_row" : "") . " hover clickablerow\">";
                //$this->Output .= "<th scope=\"row\">" . $entry["contractID"] . "</th>";
                $this->Output .= "<th scope=\"row\">" . $entry["Type"] . "</th>";
                if (CONTRACT_ACTIVE($entry["status"])) {
                    $this->Output .= "<td class=\"pendingcontractstatus\">" . $entry["status"] . "</td>";
                } else {
                    if ($entry["status"] == "Failed") {
                        $this->Output .= "<td class=\"failedcontractstatus\">FAILED</td>";
                    } else {
                        if ($entry["status"] == "Rejected") {
                            $this->Output .= "<td class=\"failedcontractstatus\">Rejected</td>";
                        } else {
                            $this->Output .= "<td class=\"contractstatus\">" . $entry["status"] . "</td>";
                        }
                    }
                }
                $this->Output .= "<td>" . $entry["System"] . "</td>";
                $this->Output .= "<td>" . shortDateTime($entry["dateIssued"]) . "</td>";
                if (CONTRACT_ACTIVE((string) $entry["status"])) {
                    if ($entry["timeRemaining"] <= 3600 * 24) {
                        $this->Output .= "<td style=\"color: " . timeToColor($entry["timeRemaining"]) . "\">";
                    } else {
                        $this->Output .= "<td>";
                    }
                    $this->Output .= niceTime($entry["timeRemaining"], 2) . " left</td>";
                } else {
                    if ((string) $entry["status"] == "Failed") {
                        $this->Output .= "<td class=\"failedcontractstatus\">FAILED</td>";
                    } else {
                        if ($entry["status"] == "Rejected") {
                            $this->Output .= "<td class=\"failedcontractstatus\">Rejected</td>";
                        } else {
                            if ($entry["dateFinished"] != "") {
                                $this->Output .= "<td>" . shortDateTime($entry["dateFinished"]) . "</td>";
                            } else {
                                $this->Output .= "<td>&nbsp;</td>";
                            }
                        }
                    }
                }
                $this->Output .= "<td>" . $entry["issuer"] . "</td>";
                if ((string) $entry["availability"] == "Private" && $entry["acceptor"] == "") {
                    $this->Output .= "<td>&lt;" . $entry["assignee"] . "&gt;</td>";
                } else {
                    if ($entry["acceptor"] == "") {
                        if (isset($entry["bidder"])) {
                            if ($entry["bidder"] == "") {
                                $this->Output .= "<td style=\"color:grey;\">&lt;no bids&gt;</td>";
                            } else {
                                $this->Output .= "<td style=\"color:grey;\">&lt;bid {$entry['bidder']}&gt;</td>";
                            }
                        } else {
                            $this->Output .= "<td style=\"color:grey;\">&lt;public&gt;</td>";
                        }
                    } else {
                        $this->Output .= "<td>" . $entry["acceptor"] . "</td>";
                    }
                }
                $this->Output .= "<td align=right style=\"color: " . ($entry["reward"] > 0 || $entry["reward"] == $entry["price"] ? "#007700" : "#BB0000") . ";\">" . number_format((double) $entry["price"] + (double) $entry["reward"], 2) . " ISK</td>";
                if ($entry["volume"] > 30000) {
                    $this->Output .= "<td style=\"color: #FFA500\">" . shortVolume($entry["volume"]) . "</td>";
                } else {
                    $this->Output .= "<td>" . shortVolume($entry["volume"]) . "</td>";
                }
                $this->Output .= "<td width=\"500\"" . ">" . $entry["desc"];
                if ($hasItems) {
                    if ($entry["desc"] != "") {
                        $this->Output .= "<br>";
                    }
                    $this->Output .= "<span class=\"contract_items\">";
                    if ($entry["sellingItems"] != "") {
                        switch ($entry["Type"]) {
                            case "Trade":
                                $this->Output .= "<b>Offering:</b> ";
                                break;
                            case "Gift":
                                $this->Output .= "<b>Giving:</b> ";
                                break;
                            default:
                                $this->Output .= "<b>Selling:</b> ";
                                break;
                        }
                        $this->Output .= "{$entry['sellingItems']}<br>";
                    }
                    if ($entry["buyingItems"] != "") {
                        $this->Output .= ($entry["Type"] != "Trade" ? "<b>Buying:</b> " : "<b>Looking for:</b> ") . "{$entry['buyingItems']}";
                    }
                    $this->Output .= "</span>";
                }
                $this->Output .= "&nbsp;</td>\n";
                $this->Output .= "</tr>\n";
                /// BEGIN CONTRACT DETAILS
                $this->Output .= "<tr{$rowclass} id=\"contract" . $entry["contractID"] . "\"><td colspan=\"" . count($cols) . "\">";
                $this->Output .= "<a name=\"" . $entry["contractID"] . "\"></a><h3>";
                if ($entry["title"] != "") {
                    $this->Output .= "{$entry['title']} - ";
                }
                if ($entry["type"] == "ItemExchange") {
                    $this->Output .= "Item Exchange [{$entry["Type"]}]";
                } else {
                    $this->Output .= "{$entry["Type"]}";
                }
                $this->Output .= " - {$entry['status']}</h3>";
                $this->Output .= "<b>Location</b>: {$entry["startStation"]}<br>";
                if ($entry["type"] == "Courier") {
                    $this->Output .= "<b>Destination</b>: {$entry["endStation"]}({$entry["endStationID"]})<br>";
                }
                $this->Output .= "<b>Posted</b>: {$entry['dateIssued']}<br>";
                if ((double) $entry["acceptorID"] != 0 && $entry["type"] == "Courier") {
                    $this->Output .= "<b>Accepted</b>: {$entry['dateAccepted']}<br>";
                }
                if ((string) $entry["status"] != "Completed" && (string) $entry["status"] != "Deleted" && (string) $entry["status"] != "Failed") {
                    $this->Output .= "<b>Remaining</b>: <span";
                    if ($entry["timeRemaining"] <= 3600 * 24) {
                        $this->Output .= " style=\"color: " . timeToColor($entry["timeRemaining"]) . "\">";
                    } else {
                        $this->Output .= ">";
                    }
                    $this->Output .= niceTime($entry["timeRemaining"], 3) . "</span><br>";
                } else {
                    $this->Output .= "<b>Finished</b>: {$entry['dateFinished']}<br>";
                }
                $this->Output .= "<b>Contractor</b>: ";
                if ((string) $entry["availability"] == "Private" && $entry["acceptor"] == "") {
                    $this->Output .= "&lt;" . $entry["assignee"] . "&gt;";
                } else {
                    if ($entry["acceptor"] == "") {
                        if (isset($entry["bidder"])) {
                            if ($entry["bidder"] == "") {
                                $this->Output .= "<span style=\"color:grey;\">&lt;no bids&gt;</span>";
                            } else {
                                $this->Output .= "<span style=\"color:grey;\">&lt;bid {$entry['bidder']}&gt;</span>";
                            }
                        } else {
                            $this->Output .= "<span style=\"color:grey;\">&lt;public&gt;</span>";
                        }
                    } else {
                        $this->Output .= $entry["acceptor"];
                    }
                }
                $this->Output .= "<br>";
                if ($entry["reward"] > 0 || $entry["reward"] == $entry["price"]) {
                    $this->Output .= "<b>Reward</b>: <span style=\"color:007700\">";
                } else {
                    $this->Output .= "<b>Price</b>: <span style=\"color:BB0000\">";
                }
                $this->Output .= number_format((double) $entry["price"] + (double) $entry["reward"], 2) . " ISK</span></br>";
                if ((double) $entry["collateral"] != 0) {
                    $this->Output .= "<b>Collateral</b>: <span style=\"color:#f00;\">" . number_format((double) $entry["collateral"], 2) . " ISK</span></br>";
                }
                $this->Output .= "<b>Volume</b>: ";
                if ($entry["volume"] > 30000) {
                    $this->Output .= "<span style=\"color: #FFA500\">" . number_format($entry["volume"], 2) . " m3</span>";
                } else {
                    $this->Output .= number_format($entry["volume"], 2) . " m3";
                }
                $this->Output .= "<br>";
                if ($hasItems) {
                    $this->Output .= "<br><table class=\"contracts_wtt\"><tr>";
                    if ($entry["sellingItems"] != "") {
                        $this->Output .= "<th> " . ($entry["Type"] != "Trade" ? $entry["Type"] == "Gift" ? "<b>Giving</b>:" : "<b>Selling</b> " : "<b>Offering:</b> ") . "</th>";
                    }
                    if ($entry["buyingItems"] != "") {
                        $this->Output .= "<th> " . ($entry["Type"] != "Trade" ? "<b>Buying</b> " : "<b>Looking for:</b> ") . "</th>";
                    }
                    $this->Output .= "</tr><tr>";
                    if ($entry["sellingItems"] != "") {
                        $this->Output .= "<td>" . str_replace("\n", "<br>", $entry["sellingItemsList"]) . "</td>";
                    }
                    if ($entry["buyingItems"] != "") {
                        $this->Output .= "<td>" . str_replace("\n", "<br>", $entry["buyingItemsList"]) . "</td>";
                    }
                    $this->Output .= "</tr></table>";
                }
                $this->Output .= "";
                $this->Output .= "<br><h3 style=\"font-size: 150%; border-bottom: 0px;\"><a href=\"#\" onclick=\"toggle_row_visibility('contract" . $entry["contractID"] . "'); return false;\">[Hide]</a></h3>";
                $this->Output .= "";
                $this->Output .= "";
                $this->Output .= "</td></tr>\n";
            }
            $this->Output .= "</table>";
            if (isset($_GET['contract'])) {
                $this->Output .= "<script>toggle_row_visibility('contract{$_GET['contract']}'); location.hash='{$_GET['contract']}';</script>";
            }
        } else {
            $this->Output .= (CORP_MODE ? "Corporation" : "Character") . " has no Contracts in the last 3 months.<br>";
        }
        $this->Times = getPageTimes($Db, $time_api, microtime_float() - $time_start);
        return true;
    }