<?php
	require_once('lib/common.php');		
	require_once(DIR_WS_LANG.'index.php');
	
	$sort = @$_GET['sort']; // highest_value, lowest_value, endingsoon
	
	
	$rowsPerPage = 8;
	$pageNum = 1;
	if(isset($_GET['page'])){  $pageNum = $_GET['page']; }
	$offset = ($pageNum - 1) * $rowsPerPage;
	$limit = " LIMIT $offset, $rowsPerPage";
	
	$orderBy = 'a.end_time ASC';
	if($sort == 'highest_value'){
		$orderBy = 'a.price DESC';
	}if($sort == 'lowest_value'){
		$orderBy = 'a.price ASC';
	}
 
 $query = "SELECT i.image, a.id ,a.time_inc ,p.title,p.rrp,p.buy_now,a.end_time,a.start_time,a.leader_id,a.price,a.closed , u.username
		 
		FROM auctions a 
		LEFT JOIN users u on u.id = a.leader_id   
		LEFT JOIN products p on p.id = a.product_id   
		LEFT JOIN images i on i.product_id = p.id AND i.is_default = 1  
		   
			WHERE    a.closed = '1' and a.deleted = '0' ORDER BY a.end_time DESC $limit ";
$result = ww_db_query($query);
 
 



$p_query   = "SELECT count(a.id) as numrows FROM auctions a WHERE a.closed = '1' ";
$p_result  = ww_db_query($p_query) or die('Error, query failed');
$row     = ww_db_fetch_array($p_result, MYSQLI_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$Pagging  = '';
$Pagging  = create_paging_html($page,$pageNum, $maxPage,$self);

 
?>
<?php require_once(DIR_WS_TEMPLATE.'closed.tpl.php');	?>