<?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 subcategory where shop_id='$shop_id' and shop_code='$shop_code'");
        while($rows = $sels->fetch_assoc())
        {
                $p['id'] = $rows['id'];
        		$p['subcatname'] = $rows['name'];
        		$p['subcatimg'] = $rows['img'];
        		$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['catstatus'] = $rows['catstatus'];
        		$cat =  $con->query("select catname from category where id=".$rows['cat_id']."");
        		if($row = $cat->fetch_assoc())
        		$p['catname'] = $row['catname'];
        
        		$cp[] = $p;
        }
        
        echo json_encode($cp);
    }
    else
    {
        $rows = array('status'=>"",'message' => 'Data Error');
        echo json_encode($rows);
    }
}

?>