<?php
include 'common.php';

function ExpBoostList($account_id, $login_key, $time_now){
	//Connect DB
	$dbhandle = DB_Connect();
	
	
	$db_selected = mysqli_select_db($dbhandle, DB_NAME)
	or die("Could not select db");

	
	if(!CheckLoginKey($dbhandle, $account_id, $login_key))
	{
		PrintLoginKeyError();
		mysqli_close($dbhandle);
		return;
	}
	
	//$now = new DateTime();
	//$now->setTimezone(new DateTimeZone('UTC'));
	//$time_now =  date_format($now, "Y-m-d H:i:s");
	
	//$strQuery = "delete from owned_boost where user_id='".$account_id."' and  end_date <= str_to_date('".$time_now."', '%Y-%m-%d %H:%i:%s') order by uid asc";
	//if($result = mysqli_query($dbhandle, $strQuery))
	//{
		
	//}
	
	$strQuery = "select * from owned_boost where user_id='".$account_id."' and  end_date > str_to_date('".$time_now."', '%Y-%m-%d %H:%i:%s') order by uid asc";
	

	
	//Query Result
	if($result = mysqli_query($dbhandle, $strQuery))
	{
		$count = 0;
		$list = "";
		while($row=mysqli_fetch_array($result, MYSQLI_ASSOC))
		{
			$count++;
			$dataArray[] = $row["item_uid"] .",".$row["exp_increase"].",".$row["duration"].",".$row["start_date"].",".$row["end_date"].",".$row["boost_type"];
		}
		
	}
	else
	{
		
	}
	mysqli_free_result($result);

	
	if($count <= 0  )
	{
		$return = "NOT_EXIST_BOOST";
		
		$response = array('result'=>$return,'error'=>"",'list'=>null);
	}
	else
	{
		$return = "BOOST_LIST_OK";
		$response = array('result'=>$return,'error'=>"",'list'=>$dataArray);
	}
	
	$isXmlHttpRequest = (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) ?
	(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false: false;
	($isXmlHttpRequest) ? header('Content-type: application/json') : header('Content-type: text/plain');
 
	echo json_encode($response);
		
	mysqli_close($dbhandle);
}

$json = json_decode(file_get_contents('php://input'));
$account_id = $json->account_id;
$login_key = $json->login_key;
$time_now = $json->time_now;

ExpBoostList($account_id, $login_key, $time_now);

?>