Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Connects.php defines the database connection details and API keys
- * UpdatePrices2.php is a function that gets eve-central &/or eve-marketdata prices and updates a MySQL database
- */
- include 'Connects.php' ;
- include 'UpdatePrices2.php' ;
- $multiplier = 0.96 ; //Buyback rate
- $total = 0 ;
- /**
- * You can either display details for each item or just the headline contract figure
- */
- if($_GET['display'] == "tables") {
- $display = "1";
- } else {
- $display = "0";
- }
- /**
- * This is a simple test of eve-central's API - get the plex price
- */
- $url = "http://api.eve-central.com/api/marketstat?usesystem=30000142&typeid=29668" ;
- if (!$data = file_get_contents($url)) {
- $error = error_get_last();
- echo "eve-central request failed. Error was: " . $error['message'];
- $evecentralStatus = "down" ;
- } else {
- $evecentralStatus = "up" ;
- $pricexml = file_get_contents($url) ;
- $xml8 = new SimpleXMLElement($pricexml) ;
- $item = $xml8->xpath('/evec_api/marketstat/type[@id=29668]') ;
- $sellJita = (float) $item[0]->sell->min ;
- $buyJita = (float) $item[0]->buy->max ;
- print "Plex sell: ".number_format($sellJita)."<br />";
- print "Plex buy: ".number_format($buyJita)."<br /><br />";
- }
- /**
- * Get contracts from EVE API
- */
- $contractsxml = file_get_contents("https://api.eveonline.com/char/Contracts.xml.aspx?keyID=$Zappity_keyid&vcode=$Zappity_vcode&characterID=$Zappity_characterid") or die("EVE API failed") ;
- $xml = new SimpleXMLElement($contractsxml) ;
- /**
- * Loop through items in each contract if it is a good contract
- */
- foreach ($xml -> result -> rowset-> row as $row) {
- if ($row['type'] == 'ItemExchange' AND $row['status'] == 'Outstanding' AND $row['assigneeID'] == '92922536') { //Check if is the right type of contract assigned to Zappity
- $flagPI = 0 ;
- $flagPyerite = 0 ;
- $flagP4 = 0 ;
- $contractID = intval($row['contractID']) ;
- $issuerID = intval($row['issuerID']) ;
- $price = floatval($row['price']) ;
- $startStationID = intval($row['startStationID']) ;
- $dateIssued = $row['dateIssued'] ;
- //Check which station the contract is in. If it is not one of my stations then flag
- if ($startStationID == '61000647') {//61000647 = O1Y-ED, 61000896 = 8QMO-E
- $startStationName = 'O1Y-ED' ;
- } else if ($startStationID == '61000896') {
- $startStationName = '8QMO-E' ;
- } else {
- $startStationName = '***CHECK STATION***' ;
- }
- //Get the name of the issuer
- $namexml = file_get_contents("https://api.eveonline.com/eve/CharacterName.xml.aspx?ids=$issuerID") or die("EVE API failed") ;
- $xml2 = new SimpleXMLElement($namexml) ;
- foreach ($xml2 -> result -> rowset-> row as $row2) {
- $issuerName = strval($row2['name']) ;
- }
- /**
- * Now get item rows from the current contract. If new typeID, add to prices table then run update_prices function
- */
- $contractItems = array();
- $contractItemsxml = file_get_contents("https://api.eveonline.com/char/ContractItems.xml.aspx?keyID=$Zappity_keyid&vcode=$Zappity_vcode&characterID=$Zappity_characterid&contractID=$contractID") or die("EVE API failed") ;
- $xml3 = new SimpleXMLElement($contractItemsxml) ;
- // For each contract item row
- foreach ($xml3 -> result -> rowset-> row as $row3) {
- $typeID = intval($row3['typeID']) ;
- $quantity = intval($row3['quantity']) ;
- /**
- * If it is a new item, add typeID to prices table
- */
- $resultCount=$db->query("SELECT count(*) as total from prices WHERE typeID = $typeID");
- $rowCount = $resultCount->fetch(PDO::FETCH_ASSOC);
- if ( $rowCount['total'] == '0') {
- $db->query(" INSERT INTO prices (
- typeID,
- updated,
- sellJita,
- buyJita)
- VALUES (
- $typeID,
- '2000-01-01 00:00:00',
- '0.00',
- '0.00') ")
- or die("ContractValues.php error 6391842354") ;
- }
- /**
- * This is the function in the UpdatePrices2 file
- */
- update_price($typeID) ;
- //Get the typeName and group for the item
- $result4 = $db->query("SELECT typeName, groupID FROM invTypes WHERE typeID = $typeID");
- $row4 = $result4->fetch(PDO::FETCH_ASSOC);
- $contractItems[$typeID]['typeName'] = $row4['typeName'];
- $contractItems[$typeID]['groupID'] = $row4['groupID'];
- //Get the prices from the local database
- $result5 = $db->query("SELECT sellJita, buyJita, source FROM prices WHERE typeID = $typeID");
- $row5 = $result5->fetch(PDO::FETCH_ASSOC);
- $contractItems[$typeID]['sellJita'] = $row5['sellJita'];
- $contractItems[$typeID]['buyJita'] = $row5['buyJita'];
- $contractItems[$typeID]['source'] = $row5['source'];
- // Now build array of items for this specific contract for sorting and display
- // Consolidate quantity if the contract has multiple rows for each typeID (i.e. not stacked)
- if (array_key_exists($typeID, $contractItems)) {
- $contractItems[$typeID]['quantity'] = $contractItems[$typeID]['quantity'] + $quantity ;
- } else {
- // Add typeID to the array for the first time
- $contractItems[$typeID]['typeID'] = $typeID ;
- $contractItems[$typeID]['quantity'] = $quantity ;
- }
- /**
- * Planetary interaction materials flag
- */
- $groupID = $contractItems[$typeID]['groupID'] ;
- if ($groupID == 1031 OR $groupID == 1032 OR $groupID == 1033 OR $groupID == 1034 OR $groupID == 1035 OR $groupID == 1042 OR $groupID == 465) {
- $flagPI = 1 ;
- }
- /**
- * Pay less for pyerite
- */
- if ($typeID == 35) {
- $adjust = 0.9 ;
- $flagPyerite = 1 ;
- } else {
- if (
- ($startStationName == '8QMO-E' AND $groupID >= 450 AND $groupID <= 462)
- OR
- ($startStationName == '8QMO-E' AND $groupID >= 467 AND $groupID <= 469) ) { // if it is an ore, compressed or otherwise
- if (strpos($contractItems[$typeID]['typeName'], 'Compressed ') !== false) {
- $adjust = 1.01 ;
- } else {
- $adjust = 1 ;
- }
- } else {
- $adjust = $multiplier ;
- }
- if ($groupID == 1041) { // P4
- $adjust = 1 ;
- $flagP4 = 1 ;
- }
- }
- // Calculate total price sums and add to array
- $contractItems[$typeID]['sellAmount'] = $contractItems[$typeID]['sellJita'] * $contractItems[$typeID]['quantity'] ;
- $contractItems[$typeID]['buyAmount'] = $contractItems[$typeID]['buyJita'] * $contractItems[$typeID]['quantity'] ;
- $contractItems[$typeID]['adjustedAmount'] = $contractItems[$typeID]['buyAmount'] * $adjust ;
- }
- // Build a separate array of the buy values and then use it to array_multisort $contractItems
- $buySort = array();
- foreach ($contractItems as $typeID) {
- $buySort[] = $typeID['buyAmount'];
- }
- array_multisort($buySort, SORT_DESC, $contractItems);
- if ($display == "1") {
- $tableSetup = "
- <table class='tableLeft'>
- <tr>
- <th>Item</th>
- <th>Quantity</th>
- <th>Jita Sell</th>
- <th>Jita Buy</th>
- <th>Total J Sell</th>
- <th>Total J Buy</th>
- <th>Adjusted</th>
- <th>Source</th>
- </tr>";
- print $tableSetup ;
- }
- // New variables for contract totals
- $totalSell = 0;
- $totalBuy = 0;
- $totalAdjusted = 0;
- // Loop through items in this contract and display
- foreach ($contractItems as $value2) {
- $typeID = intval($value2['typeID']) ;
- if ($display == "1") {
- $highlightBuy = "" ;
- if ($value2['buyJita'] == '0') {
- $highlightBuy = " class = 'highlight'" ;
- }
- $tableRow = "
- <tr>
- <td>".$value2['typeName']."</td>
- <td>".number_format($value2['quantity'],0)."</td>
- <td>".number_format($value2['sellJita'],2)."</td>
- <td>".number_format($value2['buyJita'],2)."</td>
- <td>".number_format($value2['sellAmount'],0)."</td>
- <td $highlightBuy>".number_format($value2['buyAmount'],0)."</td>
- <td >".number_format($value2['adjustedAmount'],0)."</td>
- <td >".$value2['source']."</td>
- </tr>";
- print $tableRow;
- }
- $totalSell = $totalSell + $value2['sellAmount'] ;
- $totalBuy = $totalBuy + $value2['buyAmount'] ;
- $totalAdjusted = $totalAdjusted + $value2['adjustedAmount'] ;
- }
- if ($display == "1") {
- print "</table><br />";
- }
- if ($startStationName == '***CHECK STATION***') {
- $highlightStation = " class = 'red'" ;
- } else {
- $highlightStation = "" ;
- }
- if ($price > 0 AND $price > $totalAdjusted*1.01) {
- $highlightPrice = " class = 'red'" ;
- } else {
- $highlightPrice = " class = 'green'" ;
- }
- if ($flagPI == 1) {
- print "<p class = 'red'>***Ice or PI materials***</p>";
- }
- if ($flagPyerite == 1) {
- print "<p class = 'green'>***Pyerite***</p>";
- }
- if ($flagP4 == 1) {
- print "<p class = 'green'>***P4***</p>";
- }
- print "<p>Contractor: $issuerName, $dateIssued</p>";
- print "<p $highlightStation>Station: $startStationName</p>";
- print "<p>Total Jita Sell: ".number_format($totalSell,0)."</p>";
- print "<p>Total Jita Buy: ".number_format($totalBuy,0)."</p>";
- print "<p $highlightPrice>Contract Price: ".number_format($price,0)."</p>";
- print "<p class='bold'>Adjusted Total = ".number_format($totalAdjusted)."</p><br /><br />" ;
- $total = $total + $totalAdjusted ;
- } // End if a good contract
- }
- print "<p class='bold'>Total = ".number_format($total)."</p><br /><br />" ;
- print "<br />End<br /><br />" ;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement