<?php 
require 'db.php';
header('Content-type: text/json');
$data = json_decode(file_get_contents('php://input'), true);
$current_time = date("H:i");

$uid =$data['uid'];

// $shop_id = "8316293";
// $shop_code = "Ey3a8s7U79";

$shop_id = strip_tags(mysqli_real_escape_string($con,$data['shop_id']));
$shop_code = strip_tags(mysqli_real_escape_string($con,$data['shop_code']));

$sel1 = $con->query("select * from cat_banner where shop_id = '$shop_id' and shop_code = '$shop_code'");
while($row = $sel1->fetch_assoc())
{
    $banner[] = $row;
}

$sel = $con->query("SELECT category.*, shop_settings.start_time, shop_settings.end_time 
    FROM category INNER JOIN shop_settings on category.cattime != '' and category.shop_id = shop_settings.shop_id
    where category.catstatus='1' and category.shop_id = '$shop_id' and category.shop_code = '$shop_code' and
    TIME_TO_SEC(IF (category.cattime = 'Default', shop_settings.start_time, category.catstarttime)) < TIME_TO_SEC('$current_time')
    and TIME_TO_SEC(IF (category.cattime = 'Default', shop_settings.end_time, category.catstoptime)) > TIME_TO_SEC('$current_time') 
    or category.catstatus='1' and category.shop_id = '$shop_id' and category.shop_code = '$shop_code' and
    TIME_TO_SEC(IF (category.cattime = 'Customise',category.catstarttime, shop_settings.start_time)) < TIME_TO_SEC('$current_time') 
    and TIME_TO_SEC(IF (category.cattime = 'Customise',category.catstoptime, shop_settings.end_time)) > TIME_TO_SEC('$current_time')");
    
// $sel = $con->query("select * from category where TIME_TO_SEC(catstarttime) > TIME_TO_SEC('$current_time') and TIME_TO_SEC(catstoptime) < TIME_TO_SEC('$current_time') and catstatus = '1'");
$myarray = array();
while($row = $sel->fetch_assoc())
{
	$p['id'] = $row['id'];
    $p['catname'] = $row['catname'];
	$p['catimg'] = $row['catimg'];
	$cid = $row['id'];
	$p['count'] = $con->query("select * from subcategory where cat_id='$cid' and shop_id = '$shop_id' and shop_code = '$shop_code'")->num_rows;
	$myarray[] = $p;
}
$data = array("Banner"=>$banner,"Catlist"=>$myarray);
	$returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Data Get Successfully!","ResultData"=>$data);
echo json_encode($returnArr);
?>