<?php

include '../config.php';
date_default_timezone_set('Asia/Kolkata');
$date = $date;
$Market_type=$_POST['Market_type'];

$timec = date('H:i');
$sql = "SELECT * FROM starLineMarketList mar left join winningbetting_starlinedetail  wd on (wd.market_Id=mar.id  AND DATE(wd.opening_date) = DATE('$date')) WHERE active_status = 'Active' AND active_status = 'Active' AND mar.starline_market_type='$Market_type'";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result)) 
{
	$list = array();
	while ($row = mysqli_fetch_assoc($result)) 
	{
	    
	     $market_id = $row['id'];
	      $market_time = $row['market_time'];
	      $market_name = $row['star_name'];

	    $digit1 = "*";
	    $pana1 = "***";
         $digit1=empty($row["winning_number_first"])?"*":$row["winning_number_first"];
         $pana1=empty($row["winning_number_first"])?"***":array_sum(str_split($row["winning_number_first"]));
         IF(strlen($pana1)>1)
         {
                         $pana1=  substr($pana1, -1);
         }
	    
	   $markettime= $row['market_time'];
	   $activestatus= $row['active_status'];
	   if(strtotime($timec)<=strtotime($markettime))
	   {
	     $activestatus="Active";  
	   }
	   else
	   {
	       $activestatus="close";
	   }

	    

            $d_t = $row['market_time']; 
            $d_time  = date('h:i a', strtotime($d_t));

		$winningNumberStarLine = $digit1."_".$pana1;
		$temp = 
		[
			"market_time"=>$d_time,
			"market_id"=>$market_id,
			"market_date"=>$date,
			"market_name"=>$market_name,
			"winningNumberStarLine"=>$winningNumberStarLine,
			"active_status"=>$activestatus
					];
		array_push($list, $temp);
	}
	$response = ["status"=>"success","starLineMarketList"=>$list];

}
else {
	$response = ["status"=>"failure"];
}
echo json_encode($response);

?>