Guest

Untitled

By: a guest on May 25th, 2010  |  syntax: PHP  |  size: 8.74 KB  |  hits: 204  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. <?php
  2. function timeLeft($theTime){
  3.   $timeLeft = floatval($theTime) - time();
  4.   if($timeLeft > 0){
  5.     $days = floor($timeLeft/60/60/24);
  6.     $hours = $timeLeft/60/60%24;
  7.     $mins = $timeLeft/60%60;
  8.     $secs = $timeLeft%60;
  9.     if($days)
  10.       $theText .= "{$days}d";
  11.     if($hours)
  12.       $theText .= " {$hours}h";
  13.     if($mins)
  14.       $theText .= " {$mins}m";
  15.     if($secs)
  16.       $theText .= " {$secs}s";
  17.   } else
  18.     $theText = 'Auction ended';
  19.   return $theText;
  20. }
  21. function cmp($a, $b){
  22.   $sort = (isset($_GET['sortby']))?$_GET['sortby']:'end';
  23.   if($sort == 'title') //if sorting by the auction title do a string comparison
  24.     if($_GET['sort'] == 'asc')
  25.       return strcasecmp($a['title'], $b['title']);
  26.     else
  27.       return strcasecmp($b['title'], $a['title']);
  28.   if ($a == $b) //otherwise do a numerical comparison
  29.     return 0;
  30.   if($_GET['sort'] == 'desc')
  31.     return (floatval($a[$sort]) > floatval($b[$sort])) ? -1 : 1;
  32.   else
  33.     return (floatval($a[$sort]) < floatval($b[$sort])) ? -1 : 1;
  34. }
  35.  
  36. $xmlUser = 'user';
  37. $xmlPass = 'password';
  38. $serverUrl = 'localhost:9099';
  39.  
  40. if(isset($_GET['view'])){ //if viewing an auction grab the local jbidwatcher copy and remove the broken html then insert it in the correct place
  41.   $page = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/{$_GET['view']}");
  42.   preg_match('/(<!DOCTYPE.*)/s', $page, $page);
  43.   $start = strpos($page[1], '<div id="vi-container">');
  44.   $page = substr($page[1], 0, $start) . "<b>JBidwatcher View</b><br>Click here for the <a href=\"http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item={$_GET['view']}\">current page</a>.<br>" . substr($page[1], $start);
  45.   echo $page;
  46.   exit();
  47. }
  48. ?>
  49. <html>
  50. <head>
  51. <title>JBidwatcher</title>
  52. <style>
  53.   .winner{
  54.     color: green;
  55.   }
  56.   .notwinner{
  57.     color: red;
  58.   }
  59.   .unbid{
  60.     color: black;
  61.   }
  62.   .row1{
  63.     background-color: #CFCFCF;
  64.   }
  65.   .row0{
  66.     background-color: #EFEFEF;
  67.   }
  68.   td{
  69.     border-style: hidden;
  70.   }
  71.   th{
  72.     font-size: small;
  73.   }
  74. </style>
  75. </head>
  76. <body>
  77. <?
  78. if(isset($_GET['add'])){ //if adding an auction add it and check if the id is in the auction list, no point checking if the auction is already in the list because if it isnt you need 2 requests
  79.   $page = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/addAuction?id={$_GET['id']}&action=Add+Auction");
  80.   if(preg_match("#<a href=\"/{$_GET['id']}\">#", $page))
  81.     echo '<b>Auction added succesfully</b><br>';
  82.   else
  83.     echo '<b>Auction adding failed</b><br>';
  84. }
  85. ?>
  86. <div style="padding-bottom: 3px;">
  87.   <form name="Add Auction" method="GET" style="display: inline;">
  88.     <label for="id">Auction Id: </label>
  89.     <input name="id" size="20" value="">
  90.     <input type="submit" name="add" value="Add Auction">
  91.   </form> |
  92.   <form style="display: inline;" method="get">Select Tab to View:
  93.     <?=(isset($_GET['sortby']))?"<input type=\"hidden\" name=\"sort\" value=\"{$_GET['sort']}\"><input type=\"hidden\" name=\"sortby\" value=\"{$_GET['sortby']}\">":''?>
  94.     <select name="display" id="tabselect" onchange="this.parentNode.submit();">
  95.       <option value="all"<?=($_GET['display']=='all')?' selected="selected"':''?>>All</option>
  96.       <option value="current"<?=($_GET['display']=='current')?' selected="selected"':''?>>Current</option>
  97.       <option value="complete"<?=($_GET['display']=='complete')?' selected="selected"':''?>>Complete</option>
  98.     </select>
  99.     <input type="submit" value="Go">
  100.   </form>
  101. </div>
  102. <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor="#CCCCFF">
  103.   <tr>
  104.     <font size="2">
  105.       <th align="center" width="10%">
  106.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=title&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Item</a>&nbsp;
  107.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=id&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">(id)</a>
  108.       </th>
  109.       <th align="center" width="10%">
  110.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=current&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Start Price</a>
  111.       </th>
  112.       <th align="center" width="11%">
  113.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=current&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Current Price</a>
  114.       </th>
  115.       <th align="center" width="11%">
  116.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=snipe&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">My Max Snipe/Bid</a>
  117.       </th>
  118.       <th align="center" width="8%">
  119.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=bidcount&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>"># of Bids</a>
  120.       </th>
  121.       <!--<th align="center" width="11%">Start Date</th>-->
  122.       <th align="center" width="18%">
  123.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=end&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">End Date</a>
  124.       </th>
  125.       <th align="center" width="9%">
  126.         <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=end&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Time Left</a>
  127.       </th>
  128.     </font>
  129.   </tr>
  130. <?php
  131.  
  132. $xml = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/synchronize"); //grab the auctions from jbidwatcher and grab the wanted variables
  133. preg_match_all('#(<auction.*?</auction>)#s', $xml, $auctions);
  134.  
  135. $i = 0;
  136. foreach($auctions[1] as $auction){
  137.         preg_match('#<auction id="(.*?)">#', $auction, $match);
  138.   $clean_auctions[$i]['id'] = $match[1];
  139.   preg_match('#<title>(.*?)</title>#', $auction, $match);
  140.   $clean_auctions[$i]['title'] = $match[1];
  141.   preg_match('#<start>(\d{10})000</start>#', $auction, $match);
  142.   $clean_auctions[$i]['start'] = $match[1];
  143.   preg_match('#<end>(\d{10})000</end>#', $auction, $match);
  144.   $clean_auctions[$i]['end'] = $match[1];
  145.   preg_match('#<bidcount>(\d.*)</bidcount>#', $auction, $match);
  146.   $clean_auctions[$i]['bidcount'] = $match[1];
  147.   preg_match('#<currently price="(.*?)" currency="GBP"/>#', $auction, $match);
  148.   $clean_auctions[$i]['current'] = $match[1];
  149.   preg_match('#<shipping price="(.*?)" currency="GBP"/>#', $auction, $match);
  150.   $clean_auctions[$i]['shipping'] = $match[1];
  151.   preg_match('#<(bid|snipe).*?price="(.*?)" quantity=".*?" currency="GBP"/>#', $auction, $match);
  152.   $clean_auctions[$i]['snipe'] = $match[2];
  153.   $clean_auctions[$i]['complete'] = preg_match('#<complete/>#', $auction);
  154.   $i++;
  155. }
  156.  
  157. //depending on the auctions to display remove the unwanted ones from the auctions array then sort it by wahtever method, default is time ending with the earliest first
  158. if($_GET['display'] == 'current')
  159.   for($i = count($clean_auctions); $i >= 0; --$i)
  160.     if(floatval($clean_auctions[$i]['end']) < time())
  161.       unset($clean_auctions[$i]);
  162.  
  163. if($_GET['display'] == 'complete')
  164.   for($i = count($clean_auctions); $i > 0; --$i)
  165.     if(floatval($clean_auctions[$i]['end']) > time())
  166.       unset($clean_auctions[$i]);
  167.  
  168.  
  169. usort($clean_auctions, "cmp");
  170.  
  171. for($i = 0; $i < count($clean_auctions); $i++){
  172.   $row = $i % 2;
  173.   $clean_auctions[$i]['current'] = number_format(floatval($clean_auctions[$i]['current']), 2, '.', ''); //fix the prices so that trailing zeroes are added
  174.   if($clean_auctions[$i]['snipe'] == '')
  175.     $clean_auctions[$i]['snipe'] = '-.--';
  176. ?>
  177.  
  178.   <tr class="row<?=$row?>">
  179.     <td width="100%" colspan="7">
  180.       <font size="3"><strong><a href="<?="{$_SERVER['SCRIPT_NAME']}?view={$clean_auctions[$i]['id']}"?>"><?=$clean_auctions[$i]['title']?></a></strong></font>
  181.     </td>
  182.   </tr>
  183.   <tr class="row<?=$row?>" style="font-size: small">
  184.     <td width="10%" align="center" class="unbid"><a href="http://cgi.ebay.co.uk/ws/eBayISAPI.dll?ViewItem&item=<?=$clean_auctions[$i]['id']?>"><?=$clean_auctions[$i]['id']?></a></td>
  185.     <td width="10%" align="right" class="unbid">£<?=$clean_auctions[$i]['current']?></td>
  186.     <td width="11%" align="right" class="unbid">£<?=$clean_auctions[$i]['current']?></td>
  187.     <td width="11%" align="right" class="unbid">£<?=$clean_auctions[$i]['snipe']?></td>
  188.     <td width="8%" align="center" class="unbid"><?=$clean_auctions[$i]['bidcount']?></td>
  189.     <!--<td width="11%" align="center" class="unbid"><?=$clean_auctions[$i]['start']?></td>-->
  190.     <td width="18%" align="center" class="unbid"><?=date('d-F-Y H:i:s',$clean_auctions[$i]['end'])?></td>
  191.     <td width="9%" align="center" class="unbid"><?=timeLeft($clean_auctions[$i]['end'])?></td>
  192.   </tr>
  193. <?php
  194. }
  195. ?>
  196. </table>
  197. </body>
  198. </html>