<?
error_reporting(0);
$datecheck=date("Y-m-d H:i:s");
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();
	}

  function AddDays2($date,$interval) 
{ 
  if (!isset($date)) 
  $date = date("Y-m-d H:i:s"); 
  $first = explode(" ", $date); 

  $elts1 = explode("-", $first[0]);
  $elts2 = explode(":", $first[1]);
  $inter=$interval; 
  $dcour=mktime($elts2[0],$elts2[1],$elts2[2],$elts1[1],$elts1[2],$elts1[0]); 
  $dres=$dcour+$inter; 
  $date1=date("Y-m-d H:i:s",$dres);
  $ret_date="$date1";
  return $ret_date; 
}



$datecheck=date("Y-m-d H:i:s");
$currdate = date("H:i:s");
$sql=mysql_query("select * from closing where auto=1");
$fromto=mysql_fetch_array($sql);
$totime = $fromto['totime'];
$fromtime = $fromto['fromtime'];
if(($currdate>$fromtime)&&($currdate<$totime))
{
$stp_query="update auction_details set stopped='yes', closetime='$datecheck' where status='Active' and stopped='no'";
mysql_query($stp_query);
}
else
{

$feature_sql="select * from auction_details where status='Active' and stopped='yes'";
$modifyres=mysql_query($feature_sql);

while($modifyrow=mysql_fetch_array($modifyres))
   {
$productid=$modifyrow[productid]; 
$closetime=$modifyrow[closetime]; 
$expire_date=$modifyrow[expire_date];

$date2=strtotime($closetime);
$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 = $date1 - $date2;
$new_expire_date = AddDays2($expire_date,$diff); 
$stp_query="update auction_details set stopped='no',expire_date = '$new_expire_date', closetime='0000-00-00 00:00:00' where productid=$productid";
mysql_query($stp_query);
}
}
?>
