<?php 

require 'db.php';

if(isset($_GET['sid']) && isset($_GET['token']))
{
    $shop_id = $_GET['sid'];
    $shop_code = $_GET['token'];

    include 'token_check.php';
    
    if($token_check)
    {
        $sels = $con->query("select * from category where shop_id='$shop_id' and shop_code='$shop_code'");
        while($rows = $sels->fetch_assoc())
        {
            $p['id'] = $rows['id'];
        	$p['catname'] = $rows['catname'];
        	$p['cattime'] = $rows['cattime'];
        	if($p['cattime'] == "Default")
        	{
        	    $sel = $con->query("select start_time,end_time from shop_settings where shop_id='$shop_id' and shop_code='$shop_code'");
                if($row = $sel->fetch_assoc())
                {
                    $p['catstarttime'] = $row['start_time'];
                    $p['catstoptime'] = $row['end_time'];
                }
        	}
        	else
        	{
        	    $p['catstarttime'] = $rows['catstarttime'];
        	    $p['catstoptime'] = $rows['catstoptime'];
        	}
        	$p['catimg'] = $rows['catimg'];
        	$p['count'] = $con->query("select * from subcategory where cat_id=".$rows['id']."")->num_rows;
        	$p['catstatus'] = $rows['catstatus'];
        	$cp[] = $p;
        }
        echo json_encode($cp);
    }
    else
    {
        $rows = array('status'=>"",'message' => 'Data Error');
        echo json_encode($rows);
    }
}
// else
// {
//     header("location: https://iconxtechnologies.in/404");
//     exit();
// }
?>