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

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

if($uid == '' || $shop_id == '')
{
    $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");    
}
else
{
    $sel = $con->query("select shop_status from shop_settings where shop_id = '$shop_id' and shop_code = '$shop_code'");
    if($row = $sel->fetch_assoc())
    {
    	$status = $row['shop_status'];
    }
    if($status == 0)
    {
        $returnArr = array("ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>"Shop not Accepting Orders this time");
    }
    else if($status == 1)
    {
        $notavailproduct = false;
        $p = array();
        for($i=0;$i<count($pname);$i++)
        {
            $p[] = $pname[$i]['pid'];
        }
        for($i=0;$i<count($p);$i++)
        {
            $pid = $p[$i];
            $sel1 = $con->query("select status,pname from product where id = '$pid' and shop_id = '$shop_id' and shop_code = '$shop_code'");
            if($row1 = $sel1->fetch_assoc())
            {
            	$pstatus = $row1['status'];
            	$proname = $row1['pname'];
            }
            if($pstatus == 0)
            {
                $pro_message = $proname." is Not Available";
                $notavailproduct = true;
            }
        }
        if($notavailproduct)
        {
            $returnArr = array("ResponseCode"=>"201","Result"=>"false","ResponseMsg"=>$pro_message);
        }
        else
        {
            $returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"");
        }
    }
}
echo json_encode($returnArr);


?>