Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function timeLeft($theTime){
- $timeLeft = floatval($theTime) - time();
- if($timeLeft > 0){
- $days = floor($timeLeft/60/60/24);
- $hours = $timeLeft/60/60%24;
- $mins = $timeLeft/60%60;
- $secs = $timeLeft%60;
- if($days)
- $theText .= "{$days}d";
- if($hours)
- $theText .= " {$hours}h";
- if($mins)
- $theText .= " {$mins}m";
- if($secs)
- $theText .= " {$secs}s";
- } else
- $theText = 'Auction ended';
- return $theText;
- }
- function cmp($a, $b){
- $sort = (isset($_GET['sortby']))?$_GET['sortby']:'end';
- if($sort == 'title') //if sorting by the auction title do a string comparison
- if($_GET['sort'] == 'asc')
- return strcasecmp($a['title'], $b['title']);
- else
- return strcasecmp($b['title'], $a['title']);
- if ($a == $b) //otherwise do a numerical comparison
- return 0;
- if($_GET['sort'] == 'desc')
- return (floatval($a[$sort]) > floatval($b[$sort])) ? -1 : 1;
- else
- return (floatval($a[$sort]) < floatval($b[$sort])) ? -1 : 1;
- }
- $xmlUser = 'user';
- $xmlPass = 'password';
- $serverUrl = 'localhost:9099';
- 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
- $page = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/{$_GET['view']}");
- preg_match('/(<!DOCTYPE.*)/s', $page, $page);
- $start = strpos($page[1], '<div id="vi-container">');
- $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);
- echo $page;
- exit();
- }
- ?>
- <html>
- <head>
- <title>JBidwatcher</title>
- <style>
- .winner{
- color: green;
- }
- .notwinner{
- color: red;
- }
- .unbid{
- color: black;
- }
- .row1{
- background-color: #CFCFCF;
- }
- .row0{
- background-color: #EFEFEF;
- }
- td{
- border-style: hidden;
- }
- th{
- font-size: small;
- }
- </style>
- </head>
- <body>
- <?
- 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
- $page = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/addAuction?id={$_GET['id']}&action=Add+Auction");
- if(preg_match("#<a href=\"/{$_GET['id']}\">#", $page))
- echo '<b>Auction added succesfully</b><br>';
- else
- echo '<b>Auction adding failed</b><br>';
- }
- ?>
- <div style="padding-bottom: 3px;">
- <form name="Add Auction" method="GET" style="display: inline;">
- <label for="id">Auction Id: </label>
- <input name="id" size="20" value="">
- <input type="submit" name="add" value="Add Auction">
- </form> |
- <form style="display: inline;" method="get">Select Tab to View:
- <?=(isset($_GET['sortby']))?"<input type=\"hidden\" name=\"sort\" value=\"{$_GET['sort']}\"><input type=\"hidden\" name=\"sortby\" value=\"{$_GET['sortby']}\">":''?>
- <select name="display" id="tabselect" onchange="this.parentNode.submit();">
- <option value="all"<?=($_GET['display']=='all')?' selected="selected"':''?>>All</option>
- <option value="current"<?=($_GET['display']=='current')?' selected="selected"':''?>>Current</option>
- <option value="complete"<?=($_GET['display']=='complete')?' selected="selected"':''?>>Complete</option>
- </select>
- <input type="submit" value="Go">
- </form>
- </div>
- <table border="1" cellpadding="0" cellspacing="0" width="100%" bgcolor="#CCCCFF">
- <tr>
- <font size="2">
- <th align="center" width="10%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=title&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Item</a>
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=id&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">(id)</a>
- </th>
- <th align="center" width="10%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=current&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Start Price</a>
- </th>
- <th align="center" width="11%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=current&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Current Price</a>
- </th>
- <th align="center" width="11%">
- <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>
- </th>
- <th align="center" width="8%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=bidcount&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>"># of Bids</a>
- </th>
- <!--<th align="center" width="11%">Start Date</th>-->
- <th align="center" width="18%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=end&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">End Date</a>
- </th>
- <th align="center" width="9%">
- <a href="<? echo "{$_SERVER['SCRIPT_NAME']}?",(isset($_GET['display']))?"display={$_GET['display']}&":'','sortby=end&sort=',($_GET['sort']=='asc')?'desc':'asc' ?>">Time Left</a>
- </th>
- </font>
- </tr>
- <?php
- $xml = file_get_contents("http://$xmlUser:$xmlPass@$serverUrl/synchronize"); //grab the auctions from jbidwatcher and grab the wanted variables
- preg_match_all('#(<auction.*?</auction>)#s', $xml, $auctions);
- $i = 0;
- foreach($auctions[1] as $auction){
- preg_match('#<auction id="(.*?)">#', $auction, $match);
- $clean_auctions[$i]['id'] = $match[1];
- preg_match('#<title>(.*?)</title>#', $auction, $match);
- $clean_auctions[$i]['title'] = $match[1];
- preg_match('#<start>(\d{10})000</start>#', $auction, $match);
- $clean_auctions[$i]['start'] = $match[1];
- preg_match('#<end>(\d{10})000</end>#', $auction, $match);
- $clean_auctions[$i]['end'] = $match[1];
- preg_match('#<bidcount>(\d.*)</bidcount>#', $auction, $match);
- $clean_auctions[$i]['bidcount'] = $match[1];
- preg_match('#<currently price="(.*?)" currency="GBP"/>#', $auction, $match);
- $clean_auctions[$i]['current'] = $match[1];
- preg_match('#<shipping price="(.*?)" currency="GBP"/>#', $auction, $match);
- $clean_auctions[$i]['shipping'] = $match[1];
- preg_match('#<(bid|snipe).*?price="(.*?)" quantity=".*?" currency="GBP"/>#', $auction, $match);
- $clean_auctions[$i]['snipe'] = $match[2];
- $clean_auctions[$i]['complete'] = preg_match('#<complete/>#', $auction);
- $i++;
- }
- //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
- if($_GET['display'] == 'current')
- for($i = count($clean_auctions); $i >= 0; --$i)
- if(floatval($clean_auctions[$i]['end']) < time())
- unset($clean_auctions[$i]);
- if($_GET['display'] == 'complete')
- for($i = count($clean_auctions); $i > 0; --$i)
- if(floatval($clean_auctions[$i]['end']) > time())
- unset($clean_auctions[$i]);
- usort($clean_auctions, "cmp");
- for($i = 0; $i < count($clean_auctions); $i++){
- $row = $i % 2;
- $clean_auctions[$i]['current'] = number_format(floatval($clean_auctions[$i]['current']), 2, '.', ''); //fix the prices so that trailing zeroes are added
- if($clean_auctions[$i]['snipe'] == '')
- $clean_auctions[$i]['snipe'] = '-.--';
- ?>
- <tr class="row<?=$row?>">
- <td width="100%" colspan="7">
- <font size="3"><strong><a href="<?="{$_SERVER['SCRIPT_NAME']}?view={$clean_auctions[$i]['id']}"?>"><?=$clean_auctions[$i]['title']?></a></strong></font>
- </td>
- </tr>
- <tr class="row<?=$row?>" style="font-size: small">
- <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>
- <td width="10%" align="right" class="unbid">£<?=$clean_auctions[$i]['current']?></td>
- <td width="11%" align="right" class="unbid">£<?=$clean_auctions[$i]['current']?></td>
- <td width="11%" align="right" class="unbid">£<?=$clean_auctions[$i]['snipe']?></td>
- <td width="8%" align="center" class="unbid"><?=$clean_auctions[$i]['bidcount']?></td>
- <!--<td width="11%" align="center" class="unbid"><?=$clean_auctions[$i]['start']?></td>-->
- <td width="18%" align="center" class="unbid"><?=date('d-F-Y H:i:s',$clean_auctions[$i]['end'])?></td>
- <td width="9%" align="center" class="unbid"><?=timeLeft($clean_auctions[$i]['end'])?></td>
- </tr>
- <?php
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment