<?
ini_set('max_execution_time',60);
for($i=0;$i<60;$i++) {
$datecheck=date("Y-m-d H:i:s");

$feature_sqlb="select * from auction_details where reserve_price!='0.00' and (expire_date > '$datecheck') and date_add('$datecheck',INTERVAL 30 SECOND)>expire_date";
$feature_resb=mysql_query($feature_sqlb);
//$feature_count=mysql_num_rows($feature_resb);
while($feature_rowb=mysql_fetch_array($feature_resb))
{

$rand=rand(5,20);
$diff=strtotime($feature_rowb['expire_date'])-strtotime($datecheck);
if($diff<$rand ) {
$reserve_price = $feature_rowb['reserve_price'];
$expire_date = $feature_rowb['expire_date']; 
$timetoadd = $feature_rowb['timetoadd'];
$min_bid_amount=$feature_rowb['min_bid_amount'];
$bidincrement=$feature_rowb['bidincrement'];
$productid=$feature_rowb['productid']; 
if($productid!=""){
$bid_sql2="select bidding_amount as um, user_id as uid from site_bids where productid=".$productid." order by bidding_amount desc";
$bid_res2=mysql_query($bid_sql2);
$bid_row2=mysql_fetch_array($bid_res2);
$user_bid_amt=$bid_row2[um];
$user_bid_id=$bid_row2[uid];

if($user_bid_amt!=""){
$max_bid = $user_bid_amt+$bidincrement;
}
if($user_bid_amt==""){
$max_bid = $min_bid_amount;
}

$man_bid="select bid_id from site_bids where productid=".$productid." and bot_bid='no'";
$man_bid_res2=mysql_query($man_bid);
$man_bid_row2=mysql_num_rows($man_bid_res2);


$s_title="SELECT * FROM `genaralsettings` WHERE set_id=58";
$s_title_row=mysql_query($s_title);
$s_title_res=mysql_fetch_array($s_title_row);
$bidcost=$s_title_res['set_value'];

$tot_bid_cost=$man_bid_row2*$bidcost;



if($tot_bid_cost<$reserve_price){

 $date = "$expire_date"; 
  $first = explode(" ", $date); 

  $elts1 = explode("-", $first[0]);
  $elts2 = explode(":", $first[1]);
  $dcour=mktime($elts2[0],$elts2[1],$elts2[2],$elts1[1],$elts1[2],$elts1[0]); 
  $dres=$dcour+$timetoadd; 
  $new_expir_date=date("Y-m-j G:i:s",$dres);




if($user_bid_amt!=""){
$max_bid = $user_bid_amt+$bidincrement;
}
if($user_bid_amt==""){
$max_bid = $min_bid_amount;
}



//end

$qty=1;

$fsql="select user_id as ui from member_details where user_id!='$user_bid_id' and user_type='bot' order by rand() limit 1";
$fres=mysql_query($fsql) or die ("Query failed: " . mysql_error());
$frow=mysql_fetch_array($fres);
$user_id = $frow[ui];

$bid_ins="insert into site_bids(productid,user_id,bidding_amount,bidding_date,quantity,bot_bid) values($productid,$user_id,$max_bid,now(),$qty,'yes')";
$ins=mysql_query($bid_ins) or die ("Query failed: " . mysql_error());
$f_sql="update auction_details set expire_date='$new_expir_date',totbid=totbid+1 where productid=$productid";
$f_res=mysql_query($f_sql) or die ("Query failed: " . mysql_error());
autobids($productid);

}
}}}
sleep(1);
}
?>