<?php

include("include/db.inc.php"); 

include("include/functions.php"); 

   $db1=new db;

   $db1->open();

   mysql_query("SET NAMES 'utf8'"); 		





set_time_limit (0);

/*$bidres=mysql_query("SELECT total_price/total_bid as bidrate FROM `t123go_bidpackage` order by bidrate limit 1");

if(mysql_num_rows($bidres) > 0)

{

$bid_rec=mysql_fetch_array($bidres);

$bid_r=$bid_rec[0];

}

else

{

$bid_r=1;

}

*/

$bid_r=0.1;



$q=1;

while($q < 61)

{

dummy_bidbutler($bid_r);

sleep(1);

$q++;

}







function dummy_bidbutler($bid_rate)

{

//$r=rand(1,1);

$r=1;



 $res=mysql_query("SELECT pid,type1,bid_price,date_format(end_time,'%Y-%m-%d %H:%i:%s')as et,bider_id,total_bids,fixed_price,

 break_even_point,dummy_user_from,dummy_user_to,bider_id FROM t123go_product  WHERE   TIME_TO_SEC( TIMEDIFF( end_time,NOW() ) ) <= $r and end_time >= NOW()");

 

 if(mysql_num_rows($res)>0)

 {

	while($prec=mysql_fetch_array($res))

	{	

	$placebid=0;

			//   For Normal & Penny type products   //

		if($prec['type1']=='4' or $prec['type1']=='2')

		 {

//		 	$revenue=$prec['bid_price'] + ($prec['total_bids']*$bid_rate);

$revenue=($prec['total_bids']*$bid_rate);

			if($prec['break_even_point'] > $revenue)

			$placebid=1;

		 }   //   For 100% off products   //

		 else if($prec['type1']=='3')

		 {

			$revenue= $prec['total_bids']*$bid_rate;

			if($prec['break_even_point'] > $revenue)

			$placebid=1;

		 }  //   For Fixed price products   //

		 else if($prec['type1']=='1')

		 {

		   // $revenue=$prec['fixed_price'] + ($prec['total_bids']*$bid_rate);

	   $revenue=($prec['total_bids']*$bid_rate);

			if($prec['break_even_point'] > $revenue)

			$placebid=1;

		 }

	

	   $numdummy=mysql_num_rows(mysql_query("select id from user where id='$prec[bider_id]' and dummy='1'"));

	   

	 // if($placebid==1 && $numdummy==0)

	   if($placebid==1 )

	   {

		$bid_incr=get_increment($prec['type1'],$prec['total_bids']);	  	

	 	$price=$prec['bid_price'] + $bid_incr[0];	

		$dummy_res=mysql_query("select id from user where dummy='1' and blocked='0' and dummy_order <= $prec[dummy_user_to] and 

		dummy_order >= $prec[dummy_user_from] and $prec[bider_id]<>id order by rand() limit 1");

			if(mysql_num_rows($dummy_res) > 0)

			{

			$dummyrec=mysql_fetch_array($dummy_res);

		 	mysql_query("insert into t123go_bid set uid='$dummyrec[id]',pid='$prec[pid]',product_price='$price',bid_time=now(),

		 	type='single'");

		 

		 	mysql_query("update t123go_product set end_time=DATE_ADD('$prec[et]', INTERVAL $bid_incr[1] SECOND),

		 	  bid_price='$price',bider_id='$dummyrec[id]',bid_type='single' where pid='$prec[pid]'")or die(mysql_error());

		    }

	    }

	

	

	

	}  

  } 

}



//   * * * * * /home/influx/public_html/ butler_dummy.php               //

?>



