<?
$total_per_ini2 = 10;
$max_pages2=100;
$items_per_page2 = 5;

	if($_GET["aid"]!=""){$id=$_GET["aid"];}
	if($_GET["id"]!=""){$id=$_GET["id"];}
	//$PRODUCTSPERPAGE2 = 1;
		if(!$_GET['pgno2'])
		{
			$PageNo2 = 1;
		}
		else
		{
			$PageNo2 = $_GET['pgno2'];
		}
		//QUery First
		if($_GET["aid"]==3)
		{
		$qryselC2 = "select Count(*) as total2 from auction a left join products p on a.productID=p.productID  left join categories c on p.categoryID=c.categoryID left join registration r on r.id=a.buy_user where a.auc_status=".$id." order by a.auctionID desc";
		}
		else
		{
		$qryselC2 = "select Count(*) as total2 from auction a left join products p on a.productID=p.productID left join categories c on p.categoryID=c.categoryID  left join registration r on r.id=a.buy_user where a.auc_status=3 and a.categoryID='".$id."' order by a.auctionID desc";
		}
		$resultC2=mysql_query($qryselC2) or die ("1:====".mysql_error());
		$rowC2 = mysql_fetch_array($resultC2);
		$newpage2 = 1;	
	
		if($PageNo2 == 1){
			$newpage2 = '' ;	
			$inc2 =  $PageNo2.$newpage2;
			$newinc2 = $items_per_page2;
		}else{
			$nxtpage2 = $PageNo2 -1 ;
			$inc2 =  $nxtpage2.$newpage2;
			$newinc2 = $inc2 + 9;
		}
		$totalC2 = $rowC2['total2'];
		//echo "TotalC3".$totalC3;
		//echo "<br>";
		
		$from2 = ($PageNo2-1)*$items_per_page2;
		//End Query First
		if($_GET["aid"]==3)
		{
		$qrysel2 = "select *, p.".$lng_prefix."name as prdname,".$lng_prefix."short_desc as short_desc from auction a left join products p on a.productID=p.productID  left join categories c on p.categoryID=c.categoryID left join registration r on r.id=a.buy_user where a.auc_status=".$id." order by a.auc_final_end_date desc";
		}
		else
		{
		$qrysel2 = "select *, c.".$lng_prefix."name as catname, p.".$lng_prefix."name as prdname,".$lng_prefix."short_desc as short_desc from auction a left join products p on a.productID=p.productID left join categories c on p.categoryID=c.categoryID  left join registration r on r.id=a.buy_user where a.auc_status=3 and a.categoryID='".$id."' order by a.auc_final_end_date desc";
		}
		$qrysel2 .= " limit $from2, $items_per_page2";
		//echo $qrysel3;
		//echo "<br>";
		$ressel2=mysql_query($qrysel2) or die ("2:====".mysql_error());
		$totalrecords2 = mysql_num_rows($ressel2);
		//$answers = $rs->getrows();
		
		$start_num2 = $from2 + 1;
		$end_num2 = $from2 + $totalrecords2;
		/*$ressel2 = mysql_query($qrysel2);
		$total2 = mysql_num_rows($ressel2);
		$totalpage2=ceil($total2/$PRODUCTSPERPAGE2);

		if($totalpage2>=2)
		{
		$startrow2=$PRODUCTSPERPAGE2*($PageNo2-1);
		$qrysel2.=" LIMIT $startrow2,$PRODUCTSPERPAGE2";
		//echo $qrysel2;
		$ressel2=mysql_query($qrysel2);
		$total2=mysql_num_rows($ressel2);
		}*/
		//QUery Third
		if($_GET["aid"]==3)
		{
		$qryselC2 = "select Count(*) as total2 from auction a left join products p on a.productID=p.productID  left join categories c on p.categoryID=c.categoryID left join registration r on r.id=a.buy_user where a.auc_status=".$id." order by a.auctionID desc";
		}
		else
		{
		$qryselC2 = "select Count(*) as total2 from auction a left join products p on a.productID=p.productID left join categories c on p.categoryID=c.categoryID  left join registration r on r.id=a.buy_user where a.auc_status=3 and a.categoryID='".$id."' order by a.auctionID desc";
		}
		$total_results2 = mysql_result(mysql_query("$qryselC2"),0);
		if (ceil($total_results2 / $items_per_page2) < $total_per_ini2)
		{
			$no_of_page_numbers2 = ceil($total_results2 / $items_per_page2);
		}
		else
		{
			$no_of_page_numbers2 = $total_per_ini2;
		}
		// Figure out the total number of pages. Always round up using ceil()
		$nextval2 = $PageNo2+$total_per_ini2;
		$total_pages2 = ceil($total_results2 / $items_per_page2);
		if($total_pages2>=$nextval2)
		{
			$start2 = $PageNo2;
			$stop2 = $nextval2;
		}
		elseif($total_pages2<$nextval2)
		{
			if($total_pages2>$total_per_ini2)
			{
				$start2 = $total_pages2-$total_per_ini2+1;
				$stop2 = $total_pages2+1;		
			}
			else
			{
				$start2 = 1;
				$stop2 = $total_pages2+1;
			}
		}
		$max2 = $stop2;
?>
<a name="EndedAuction" id="EndedAuction"></a>
<div class="openAuction_bar_mainDIV">
	<div class="openAction_bar-left"></div>
	<div class="openAction_bar-middle"><div class="page_title_font"><?=$lng_endedauc;?></div></div>
	<div class="openAction_bar-right"></div>
 </div>
 	
 <div class="openAuction_bar_mainDIV2">
		<?
		if($totalC2>0)
		{
		?>
	 	<div style="height: 15px;">&nbsp;</div>
			<div class="H_beit">
				<div class="h_beit_image"><?=$lng_image;?></div>
				<div class="h_beit_desc_ended"><?=$lng_description;?></div>
				<div class="h_beit_price_ended"><?=$lng_price;?></div>
				<div class="h_beit_bidder_ended"><?=$lng_bidder;?></div>
				<div class="h_beit_countdown_ended"><?=$lng_endtime;?></div>
				<div class="h_beit_countdown_ended"><?=$lng_savings;?></div>
			</div>
					   <?
						  $i = 1;
						  while($obj = mysql_fetch_array($ressel2))
							{
								$qrybid = "select *,sum(bid_count) as bidcount from bid_account where bid_flag='d' and auction_id=".$obj['auctionID']." and user_id=".$obj["buy_user"]." group by auction_id";
								$resbid = mysql_query($qrybid);
								$total = mysql_num_rows($resbid);
								$objbid = mysql_fetch_object($resbid);
								$totbid = $objbid->bidcount; 
								$totbidprice = $totbid * $minbiddingprice;
					
								$price = $obj["price"];
								if($obj["fixedpriceauction"]==1) { $fprice = $obj["auc_fixed_price"];}
								elseif($obj["offauction"]==1) { $fprice = "0.01"; }
								else { $fprice = $obj["auc_final_price"];}
								$saving_price = $price-$totbidprice-$fprice;
								$saving_percent = ($saving_price*100/$price);

								if($i==1 && $_GET["aid"]!="")
								{	  
						 ?>
								<div class="product-title"><? if($obj["catname"]==""){ echo $lng_endedauc; } else { echo $obj["catname"]; }?></div>						 
						<?
								}
						?>
							<div class="descripton_box"> 
											<div class="decription">
													<div class="body_inner_img" style="padding: 0px; width: 155px;"><div style="float: left; clear:both; padding-left: 15px; padding-top:9px;"><a href="auction_<?=str_replace(" ","_",strtolower(stripslashes($obj["prdname"])));?>_<?=$obj["auctionID"];?>.html"><img src="uploads/products/thumbs_big/thumbbig_<?=$obj["picture1"];?>" border="0" /></a></div><div style="float: left; padding-top: 14px; width: 153px;"><img src="<?=$lng_imagepath;?>zoom1.jpg" align="left" border="0" /><img src="<?=$lng_imagepath;?>zoom2.jpg" align="right" border="0" onclick="javascript: hidedisplayzoom('prd_image_large_<?=$obj['auctionID'];?>');" style="cursor: pointer;"/></div></div>
												  <div class="auction_decri_ended" style="width: 360px;"><span style="font-size:12px; color:#000000;"><a href="auction_<?=str_replace(" ","_",strtolower(stripslashes($obj["prdname"])));?>_<?=$obj["auctionID"];?>.html" class="black_link"><?=stripslashes($obj["prdname"]);?></a></span><br />
														<br />
														<? echo stripslashes(choose_short_desc($obj["short_desc"],165));?><a href="auction_<?=str_replace(" ","_",strtolower(stripslashes($obj["prdname"])));?>_<?=$obj["auctionID"];?>.html" class="black_link"><?=$lng_linkmore;?></a>
													</div>
												  <div class="auction_price_ended"><span class="body_inner_box_price">
														<span style="font-size:15px; font-weight: bold"><span class="price" id="currencysymbol_<?=$obj["auctionID"];?>"></span><span class="price" id="price_index_page_<?=$obj["auctionID"];?>"><?=$Currency;?><?=$obj["auc_final_price"];?></span>
														</span>
														<br />
														<?=$lng_insteadof;?><?=$Currency;?><?=$obj["price"];?>)</span></div>
												  <div class="auction_bidder_ended">
													<span id="product_bidder_<?=$obj["auctionID"];?>"><?=$obj["username"]!=""?$obj["username"]:"---";?></span>
												  </div>
												  <div class="auction_countdown_ended"><?=substr($obj["auc_final_end_date"],10);?></div>
												  <div class="auction_ended_saving"><span class="greenfont"><strong><?=number_format($saving_percent,2)."%";?></strong></span></div>
									</div>
								</div>	

								<div id="prd_image_large_<?=$obj['auctionID'];?>" style="width: 360px; height:330px; background-color: #FFFFFF; border: 2px solid; position:absolute; float:left; margin-top: -108px; margin-left: 170px; display: none;">
									<div style="height: 25px; text-align: right; width: 350px;"><img src="<?=$lng_imagepath;?>btn_closezoom.png" onclick="closezoomimage('prd_image_large_<?=$obj['auctionID'];?>')" style="cursor: pointer"/></div>
								<div id="cleaner"></div>
								<div class="zoomimagemargin">
								<img src="uploads/products/<?=$obj["picture1"];?>" style="padding-left: 5px;"/>
								</div>
								</div>					
						 <div id="cleaner"></div>
						<?
								$i++;
							}
						?>
					<div class="H_beit_full" align="center">
					  <div style="padding-top: 3px;">
							<? if($PageNo2>1){ ?>
                                      <? $npage2 = $PageNo2-1;
									  	if($_GET['aid']==3)
										{
									  ?>
                                      <span class="paging_page"><a class="page_link" href="all_ended_auctions_<?=$_GET['aid'];?>_1_EndedAuction.html" style="text-decoration: none;">&lt;&lt; </a></span> <span class="style8"><a class="page_link" href="all_ended_auctions_<?=$_GET['aid'];?>_<?=$npage2;?>_EndedAuction.html" style="text-decoration: none;">&lt; </a></span>
                                      <?
									  	}
										else
										{
										?>
                                      <span  class="paging_page"><a class="page_link" href="all_auctions_<?=$id?>_1_EndedAuction.html" style="text-decoration: none;">&lt;&lt; </a></span> <span class="style8"><a class="page_link" href="all_auctions_<?=$id?>_<?=$npage2;?>_EndedAuction.html" style="text-decoration: none;">&lt; </a></span>
                                      <?
										} 
									  }else{?>
                                      <span class="paging_page">&lt;&lt; </span> <span class="paging_page"> &lt; </span>
                                      <? }?>
                                      <span class="paging_page">
									  <? for($j=$start2;$j<$max2;$j++)
									  {
										if($j==$PageNo2)
										{
									  ?>
										| <span class="paging_page"><?=$j?></span>
									 <? }
										else
										{
											if($_GET['aid']==3)
											{
									?>	
											<span class="paging_page"> | <a class="page_link" href="all_ended_auctions_<?=$_GET['aid'];?>_<?=$j;?>_EndedAuction.html" style="text-decoration: none;"><?=$j;?></a></span>
									<?	
											}
											else
											{
									?>	
											<span class="paging_page"> | <a class="page_link" href="all_auctions_<?=$id?>_<?=$j;?>_EndedAuction.html" style="text-decoration: none;"><?=$j;?></a></span>
									<?		
											}	
										} 
									  } ?>
                                      <? if($PageNo2 < $total_pages2){?>
                                      <? $npage2 = $PageNo2+1;
									  	if($_GET['aid']==3)
										{
									  ?>
                                      <span  class="paging_page"> |<a class="page_link" href="all_ended_auctions_<?=$_GET['aid'];?>_<?=$npage2;?>_EndedAuction.html" style="text-decoration: none;"> &gt;</a></span> <a class="page_link" href="all_ended_auctions_<?=$_GET['aid'];?>_<?=$total_pages2;?>_EndedAuction.html" style="text-decoration: none;"> &gt;&gt; </a>
                                      <? }
									     else
									  	 {
										?>
                                       <span class="paging_page"> |<a class="page_link" href="all_auctions_<?=$id?>_<?=$npage2;?>_EndedAuction.html" style="text-decoration: none;"> &gt;</a></span> <a class="page_link" href="all_auctions_<?=$id?>_<?=$total_pages2;?>_EndedAuction.html" style="text-decoration: none;"> &gt;&gt; </a>
                                      <? 
										 }	
									  
									  }else{?>
                                      | &gt; &gt;&gt;
                                      <? }?>
                                      </span>
							</div>						
						</div>						
		<?
		}
		else
		{
		?>
				<div style="height: 15px;">&nbsp;</div>
				<div align="center" class="noauction_message"><? if($_GET["id"]!="") { echo $lng_noendedauctioncat; } else { echo $lng_noendedauction; } ?></div>
				<div style="height: 15px;">&nbsp;</div>
		<?
		}
		?>
 </div>
 <div class="openAuction_bar_bottom">
	<div class="openAuction_leftcorner"></div>
	<div class="openAuction_bar_middle"></div>
	<div class="openAuction_rightcorner"></div>
 </div>
