<?
	include("config/connect.php");
	include("functions.php");
	include("session.php");

	if($_GET["prid"]!="" && $_GET["uid"] && $_GET["aid"])
	{
		$prid = $_GET["prid"];
		$uid = $_SESSION["userid"];
		$aid = $_GET["aid"];

//for bid management for minus		
		
		
		$q = "select * from auc_due_table adt left join auction a on adt.auction_id=a.auctionID left join auction_management am on a.time_duration=am.auc_manage where auction_id=$aid";
		$r = mysql_query($q);
		$ob = mysql_fetch_object($r);


    $qrysel = "select final_bids from registration where id=$uid";
		$ressel = mysql_query($qrysel);
		$obj = mysql_fetch_object($ressel);
		
		
		$bal = $obj->final_bids;
		if($bal==0&&$ob->is_exprice==0)
		{
			echo '[{"result":"unsuccess"}]';
			exit;
		}

	$now=time();	
	if($ob->auc_start_time<$now && $ob->auc_end_time>$now)
	{	
		$oldtime = $ob->auc_due_time;
		$oldprice = $ob->auc_due_price;
		$plusprice = $ob->auc_plus_price;
		$plustime = $ob->auc_plus_time;
		
		if($ob->auc_end_time-$now<11)
		{
          $newtime = $oldtime + $plustime;
		}
		else{
		    $newtime = $oldtime;
		}
		$newprice = $oldprice + $plusprice;
		
		
		
		begin();
		
		$qupd = "update auc_due_table set auc_due_time=$newtime,auc_due_price=$newprice where auction_id=$aid";
		$result1 = mysql_query($qupd);
		
		if(!$result1)
		{
			rollback();
			echo "Failed";
			exit;
		}	
		$final_bal = $bal-1;
				
     if($ob->is_exprice==0){
		$qryupd = "update registration set final_bids=".$final_bal." where id=$uid";
		$result2 = mysql_query($qryupd);
//end bidmanagement
		if(!$result2)
		{
			rollback();
			echo "Failed";
			exit;
		}
	}
		
		$qryins = "Insert into bid_account (user_id,bidpack_id,bidpack_buy_date,bid_count,auction_id,product_id,bid_flag,bidding_price,bidding_type,recharge_type,referer_id,bidding_time,credit_description,cn_credit_description) values('$uid','0','".date("Y-m-d H:i:s",time()-$TimeDifference)."','1','$aid','$prid','d',$newprice,'s','','0',".$oldtime.",' ',' ')";
		//echo $qryins;
		$result3 = mysql_query($qryins);

		if(!$result3)
		{
			rollback();
			echo "Failed";
			exit;
		}
		commit();
		echo '[{"result":"success"}]';
	 }

	}
?>