SHARE
TWEET

Contracts_PUB.php

Zappity Aug 6th, 2016 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /**
  4. * Connects.php defines the database connection details and API keys
  5. * UpdatePrices2.php is a function that gets eve-central &/or eve-marketdata prices and updates a MySQL database
  6. */
  7. include 'Connects.php' ;
  8. include 'UpdatePrices2.php' ;
  9.  
  10. $multiplier = 0.96 ; //Buyback rate
  11. $total = 0 ;
  12.  
  13. /**
  14. * You can either display details for each item or just the headline contract figure
  15. */
  16. if($_GET['display'] == "tables") {
  17.   $display = "1";
  18. } else {
  19.   $display = "0";
  20. }
  21.  
  22. /**
  23. * This is a simple test of eve-central's API - get the plex price
  24. */
  25. $url = "http://api.eve-central.com/api/marketstat?usesystem=30000142&typeid=29668" ;
  26. if (!$data = file_get_contents($url)) {
  27.   $error = error_get_last();
  28.   echo "eve-central request failed. Error was: " . $error['message'];
  29.   $evecentralStatus = "down" ;
  30. } else {
  31.   $evecentralStatus = "up" ;
  32.   $pricexml = file_get_contents($url) ;
  33.   $xml8 = new SimpleXMLElement($pricexml) ;
  34.   $item = $xml8->xpath('/evec_api/marketstat/type[@id=29668]') ;
  35.        
  36.   $sellJita = (float) $item[0]->sell->min ;
  37.   $buyJita = (float) $item[0]->buy->max ;
  38.   print "Plex sell: ".number_format($sellJita)."<br />";
  39.   print "Plex buy: ".number_format($buyJita)."<br /><br />";
  40. }
  41.  
  42. /**
  43. * Get contracts from EVE API
  44. */
  45. $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") ;
  46. $xml = new SimpleXMLElement($contractsxml) ;
  47. /**
  48. * Loop through items in each contract if it is a good contract
  49. */
  50. foreach ($xml -> result -> rowset-> row as $row) {
  51.   if ($row['type'] == 'ItemExchange' AND $row['status'] == 'Outstanding' AND $row['assigneeID'] == '92922536') { //Check if is the right type of contract assigned to Zappity
  52.     $flagPI = 0 ;
  53.     $flagPyerite = 0 ;
  54.     $flagP4 = 0 ;
  55.    
  56.     $contractID = intval($row['contractID']) ;
  57.     $issuerID = intval($row['issuerID']) ;
  58.     $price = floatval($row['price']) ;
  59.     $startStationID = intval($row['startStationID']) ;
  60.     $dateIssued = $row['dateIssued'] ;
  61.    
  62.     //Check which station the contract is in. If it is not one of my stations then flag
  63.     if ($startStationID == '61000647') {//61000647 = O1Y-ED, 61000896 = 8QMO-E
  64.       $startStationName = 'O1Y-ED' ;
  65.     } else if ($startStationID == '61000896') {
  66.       $startStationName = '8QMO-E' ;
  67.     } else {
  68.       $startStationName = '***CHECK STATION***' ;
  69.     }
  70.    
  71.     //Get the name of the issuer
  72.     $namexml = file_get_contents("https://api.eveonline.com/eve/CharacterName.xml.aspx?ids=$issuerID") or die("EVE API failed") ;
  73.     $xml2 = new SimpleXMLElement($namexml) ;
  74.     foreach ($xml2 -> result -> rowset-> row as $row2) {
  75.       $issuerName = strval($row2['name']) ;
  76.     }
  77.    
  78.     /**
  79.     * Now get item rows from the current contract. If new typeID, add to prices table then run update_prices function
  80.     */
  81.     $contractItems = array();
  82.     $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") ;
  83.     $xml3 = new SimpleXMLElement($contractItemsxml) ;
  84.     // For each contract item row
  85.     foreach ($xml3 -> result -> rowset-> row as $row3) {
  86.       $typeID = intval($row3['typeID']) ;
  87.       $quantity = intval($row3['quantity']) ;
  88.       /**
  89.       * If it is a new item, add typeID to prices table
  90.       */
  91.       $resultCount=$db->query("SELECT count(*) as total from prices WHERE typeID = $typeID");
  92.       $rowCount = $resultCount->fetch(PDO::FETCH_ASSOC);
  93.       if ( $rowCount['total'] == '0') {
  94.         $db->query(" INSERT INTO prices (
  95.          typeID,
  96.          updated,
  97.          sellJita,
  98.          buyJita)
  99.          VALUES (
  100.          $typeID,
  101.          '2000-01-01 00:00:00',
  102.          '0.00',
  103.          '0.00') ")
  104.         or die("ContractValues.php error 6391842354") ;
  105.       }
  106.      
  107.       /**
  108.       * This is the function in the UpdatePrices2 file
  109.       */
  110.       update_price($typeID) ;
  111.      
  112.       //Get the typeName and group for the item
  113.       $result4 = $db->query("SELECT typeName, groupID FROM invTypes WHERE typeID = $typeID");
  114.       $row4 = $result4->fetch(PDO::FETCH_ASSOC);
  115.       $contractItems[$typeID]['typeName'] = $row4['typeName'];
  116.       $contractItems[$typeID]['groupID'] = $row4['groupID'];
  117.      
  118.       //Get the prices from the local database
  119.       $result5 = $db->query("SELECT sellJita, buyJita, source FROM prices WHERE typeID = $typeID");
  120.       $row5 = $result5->fetch(PDO::FETCH_ASSOC);
  121.       $contractItems[$typeID]['sellJita'] = $row5['sellJita'];
  122.       $contractItems[$typeID]['buyJita'] = $row5['buyJita'];
  123.       $contractItems[$typeID]['source'] = $row5['source'];
  124.      
  125.       // Now build array of items for this specific contract for sorting and display
  126.       // Consolidate quantity if the contract has multiple rows for each typeID (i.e. not stacked)
  127.       if (array_key_exists($typeID, $contractItems)) {
  128.         $contractItems[$typeID]['quantity'] = $contractItems[$typeID]['quantity'] + $quantity ;
  129.       } else {
  130.         // Add typeID to the array for the first time
  131.         $contractItems[$typeID]['typeID'] = $typeID ;
  132.         $contractItems[$typeID]['quantity'] = $quantity ;
  133.       }
  134.      
  135.       /**
  136.       * Planetary interaction materials flag
  137.       */
  138.       $groupID = $contractItems[$typeID]['groupID'] ;
  139.       if ($groupID == 1031 OR $groupID == 1032 OR $groupID == 1033 OR $groupID == 1034 OR $groupID == 1035 OR $groupID == 1042 OR $groupID == 465) {
  140.         $flagPI = 1 ;
  141.       }  
  142.          
  143.       /**
  144.       * Pay less for pyerite
  145.       */
  146.       if ($typeID == 35) {
  147.         $adjust = 0.9 ;
  148.         $flagPyerite = 1 ;
  149.       } else {
  150.         if (
  151.         ($startStationName == '8QMO-E' AND $groupID >= 450 AND $groupID <= 462)
  152.         OR
  153.         ($startStationName == '8QMO-E' AND $groupID >= 467 AND $groupID <= 469) ) { // if it is an ore, compressed or otherwise
  154.           if (strpos($contractItems[$typeID]['typeName'], 'Compressed ') !== false) {
  155.             $adjust = 1.01 ;
  156.           } else {
  157.             $adjust = 1 ;
  158.           }
  159.         } else {
  160.           $adjust = $multiplier ;
  161.         }
  162.         if ($groupID == 1041) { // P4
  163.             $adjust = 1 ;
  164.             $flagP4 = 1 ;
  165.         }
  166.       }
  167.       // Calculate total price sums and add to array
  168.       $contractItems[$typeID]['sellAmount'] = $contractItems[$typeID]['sellJita'] * $contractItems[$typeID]['quantity'] ;
  169.       $contractItems[$typeID]['buyAmount'] = $contractItems[$typeID]['buyJita'] * $contractItems[$typeID]['quantity'] ;
  170.       $contractItems[$typeID]['adjustedAmount'] = $contractItems[$typeID]['buyAmount'] * $adjust ;
  171.     }
  172.     // Build a separate array of the buy values and then use it to array_multisort $contractItems
  173.     $buySort = array();
  174.     foreach ($contractItems as $typeID) {
  175.       $buySort[] = $typeID['buyAmount'];
  176.     }
  177.     array_multisort($buySort, SORT_DESC, $contractItems);
  178.  
  179.     if ($display == "1") {
  180.       $tableSetup = "
  181.      <table class='tableLeft'>
  182.        <tr>
  183.          <th>Item</th>
  184.          <th>Quantity</th>
  185.          <th>Jita Sell</th>
  186.          <th>Jita Buy</th>
  187.          <th>Total J Sell</th>
  188.          <th>Total J Buy</th>
  189.          <th>Adjusted</th>
  190.          <th>Source</th>
  191.        </tr>";
  192.       print $tableSetup ;
  193.     }
  194.    
  195.     // New variables for contract totals
  196.     $totalSell = 0;
  197.     $totalBuy = 0;
  198.     $totalAdjusted = 0;
  199.    
  200.     // Loop through items in this contract and display
  201.     foreach ($contractItems as $value2) {
  202.      
  203.       $typeID = intval($value2['typeID']) ;
  204.      
  205.       if ($display == "1") {
  206.         $highlightBuy = "" ;
  207.         if ($value2['buyJita'] == '0') {
  208.           $highlightBuy = " class = 'highlight'" ;
  209.         }
  210.        
  211.         $tableRow = "
  212.        <tr>
  213.          <td>".$value2['typeName']."</td>
  214.          <td>".number_format($value2['quantity'],0)."</td>
  215.          <td>".number_format($value2['sellJita'],2)."</td>
  216.          <td>".number_format($value2['buyJita'],2)."</td>
  217.          <td>".number_format($value2['sellAmount'],0)."</td>
  218.          <td $highlightBuy>".number_format($value2['buyAmount'],0)."</td>
  219.          <td >".number_format($value2['adjustedAmount'],0)."</td>
  220.          <td >".$value2['source']."</td>
  221.        </tr>";
  222.         print $tableRow;
  223.        
  224.       }
  225.       $totalSell = $totalSell + $value2['sellAmount'] ;
  226.       $totalBuy = $totalBuy + $value2['buyAmount'] ;
  227.       $totalAdjusted = $totalAdjusted + $value2['adjustedAmount'] ;
  228.     }
  229.     if ($display == "1") {
  230.       print "</table><br />";
  231.     }
  232.    
  233.     if ($startStationName == '***CHECK STATION***') {
  234.       $highlightStation = " class = 'red'" ;
  235.     } else {
  236.       $highlightStation = "" ;
  237.     }
  238.    
  239.     if ($price > 0 AND $price > $totalAdjusted*1.01) {
  240.       $highlightPrice = " class = 'red'" ;
  241.     } else {
  242.       $highlightPrice = " class = 'green'" ;
  243.     }
  244.    
  245.     if ($flagPI == 1) {
  246.       print "<p class = 'red'>***Ice or PI materials***</p>";
  247.     }
  248.     if ($flagPyerite == 1) {
  249.       print "<p class = 'green'>***Pyerite***</p>";
  250.     }
  251.     if ($flagP4 == 1) {
  252.       print "<p class = 'green'>***P4***</p>";
  253.     }
  254.     print "<p>Contractor: $issuerName, $dateIssued</p>";
  255.     print "<p $highlightStation>Station: $startStationName</p>";
  256.     print "<p>Total Jita Sell: ".number_format($totalSell,0)."</p>";
  257.     print "<p>Total Jita Buy: ".number_format($totalBuy,0)."</p>";
  258.     print "<p $highlightPrice>Contract Price: ".number_format($price,0)."</p>";
  259.     print "<p class='bold'>Adjusted Total = ".number_format($totalAdjusted)."</p><br /><br />" ;
  260.    
  261.     $total = $total + $totalAdjusted ;
  262.    
  263.   } // End if a good contract
  264. }
  265.  
  266. print "<p class='bold'>Total = ".number_format($total)."</p><br /><br />" ;
  267.  
  268. print "<br />End<br /><br />" ;
  269.  
  270. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top