<?
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("cache-control: no-store, no-cache, must-revalidate");
header("Pragma: no-cache");
header('Content-type: text/html; charset=iso-8859-1');
$pid=$_GET[id];
$user_id=$_GET[uid];

?><?
require 'include/databaseinfo.php';
	$sql=mysql_connect($dbhost,$dbuser,$dbpass);
 	if(!$sql) {
		echo "<h1>Unable to Establish Connection to the Server</h1><hr noshade size=2 color=#000000>";
		exit();
	}
	$db_sel=mysql_select_db($dbname,$sql);
	if(!$db_sel) {
		echo "<h1>Unable to Connect to the Database</h1><hr noshade size=2 color=#000000>";
		exit();
	}
$lang_query="select * from language where auto=1";
	$lang_result=mysql_query($lang_query);
	$lang_row=mysql_fetch_array($lang_result);
	$defaultlang =$lang_row['filename'];
require "language/$defaultlang";	

$feature_sql="select selling_method, min_bid_amount, bidincrement from auction_details where productid=".$pid;
$feature_res=mysql_query($feature_sql);
$feature_row=mysql_fetch_row($feature_res);
$min_bid_amount=$feature_row[1];
$bidincrement=$feature_row[2];
$selling_method=$feature_row[0];
?>
<?
$bid_sql2="select bidding_amount as bim, user_id as uid from site_bids where productid=".$pid." order by bidding_amount desc";
$bid_res2=mysql_query($bid_sql2);
$bid_row2=mysql_fetch_array($bid_res2);
$user_bid_amt2=$bid_row2['bim'];
$user_bid_id2=$bid_row2[uid];
$user_bid_amt2 = $user_bid_amt2 + $bidincrement;
if($user_bid_amt2==$bidincrement)
{
$user_bid_amt2 = $min_bid_amount;
}

$user_bid_amt2 = number_format($user_bid_amt2, 2, ".", "");

if($user_bid_id2!=""){
$highest_bidder_sql="select user_name as un from member_details where user_id=".$user_bid_id2;
$highest_bidder_res=mysql_query($highest_bidder_sql);
$highest_bidder_res=mysql_fetch_array($highest_bidder_res);
$user_bid_name2=$highest_bidder_res[un];
}
if($user_bid_id2==""){
$user_bid_name2="None";
}


$query="select currency, quick_buy_price, or_price, expire_date, totbid, selling_method from auction_details where productid=$pid";
$table=mysql_query($query);
$row=mysql_fetch_row($table);
$sale_price=$row[0];
$or_price=$row[2];
$quick_buy_price=$row[1];
$expiry_date = $row[3];
$totbid = $row[4];
$selling_method = $row[5];


$admin="select * from genaralsettings where set_id=58"; //sitename -> id=1
$admin_res=mysql_query($admin);
$admin_rec=mysql_fetch_array($admin_res);
$bid_cost=$admin_rec[set_value];

if($user_id!=""){
$bid_sql2="select productid from site_bids where productid=$pid and user_id=".$user_id;
$bid_res2=mysql_query($bid_sql2);
$bid_row2=mysql_num_rows($bid_res2);
$bid_rebate=$bid_row2*$bid_cost;
}
if($user_id==""){
$bid_rebate="0.00";
}

$buy_cost=$or_price-$bid_rebate;

$buy_cost = number_format($buy_cost, 2, ".", "");
$bid_rebate = number_format($bid_rebate, 2, ".", "");



$date2=strtotime($expiry_date);
$date2 = date("d-m-Y H:i:s",$date2); 
$dateTo = $date2;
$date1 = mktime(date("H"),date("i"),date("s"),date("n"),date("j"),date("Y"));
$dateToElements = split(' ', $dateTo);
$dateToDateElements = split('-', $dateToElements[0]);
$dateToTimeElements = split(':', $dateToElements[1]); 
$date2 = mktime($dateToTimeElements[0], $dateToTimeElements[1], $dateToTimeElements[2], $dateToDateElements[1], $dateToDateElements[0], $dateToDateElements[2]); 
$diff = $date2 - $date1;


$bid_sql2="select bidding_amount as bi, user_id as ud, bid_type as bt from site_bids where productid=$pid order by bidding_amount desc limit 10";
$bid_res2=mysql_query($bid_sql2);
while($bid_row2=mysql_fetch_array($bid_res2))
{
$user_bid_amt=$bid_row2[bi];
$user_id2 = $bid_row2[ud];
$bid_type = $bid_row2[bt];

$highest_bidder_sql="select user_name as un from member_details where user_id=".$user_id2;
$highest_bidder_res=mysql_query($highest_bidder_sql);
$highest_bidder_res=mysql_fetch_array($highest_bidder_res);
$user_bid_name=$highest_bidder_res[un];

$bidhis1="<TR><TD align=center width=30%>$sale_price$user_bid_amt</TD><TD align=center width=35%>$user_bid_name</TD><TD align=center width=35%>$bid_type</TD></TR>";
if($bidhis!=""){
$bidhis = "$bidhis$bidhis1";
}
if($bidhis==""){
$bidhis = "$bidhis1";
}
}
?>
<?
$bidhis="<table style=font-size:11px; cellpadding=0 cellspacing=0 width=100%>
<TR><TD style=background-color:#dadada; align=center width=30%>$lang_733</TD><TD style=background-color:#dadada; align=center width=35%>$lang_705</TD><TD style=background-color:#dadada; align=center width=35%>BID TYPE</TD></TR>$bidhis</table>"
?>
<?=$sale_price?><?=$user_bid_amt2?>##<?=$sale_price?><?=$bid_rebate?>##<?=$sale_price?><?=$buy_cost?>##<?=$user_bid_name2?>##<?=$diff?>##<?=$totbid?>##<?=$bidhis?>##