<?php

require 'db.php';

$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
if(isset($postdata) && !empty($postdata))
{
    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'");
            $value = mysqli_real_escape_string($con, trim($request->value));
            if($value == "1")
            {
                $sql = "SELECT * FROM shop_settings where shop_id='$shop_id' and shop_code='$shop_code'";
                $result = mysqli_query($con,$sql);
                if($rows = mysqli_fetch_assoc($result))
                {
                	$privacy_policy = $rows['privacy_policy'];
                	$about_app = $rows['about_us'];
                	$contact_us = $rows['contact_us'];
                	$terms = $rows['terms'];
                }
                
                $rows = array('privacy_policy'=>$privacy_policy,'about_app'=>$about_app,'contact_us'=>$contact_us,'terms'=>$terms);
                echo json_encode($rows);
            }
            else if($value == '2')
            {
                $sql = "SELECT 
                shop_details.owner,
                shop_details.owner_mobile,
                shop_details.manager,
                shop_details.manager_mobile,
                shop_details.email,
                shop_details.address1,
                shop_details.address2,
                shop_details.area,
                shop_details.city,
                shop_details.pincode,
                shop_details.ifsc_code,
                shop_details.bank_account_no,
                shop_details.bank_name,
                shop_details.branch_name,
                shop_details.is_bank_verified,
                shop_details.account_holder_name,
                shop_settings.min_order_value,
                shop_settings.free_deli_value,
                shop_settings.tax_value,
                shop_settings.shop_message,
                shop_settings.start_time,
                shop_settings.end_time,
                shop_settings.shop_status
                FROM shop_settings
                INNER JOIN shop_details ON
                shop_settings.shop_id = shop_details.shop_id and
                shop_settings.shop_code = shop_details.shop_code
                WHERE shop_settings.shop_id = '$shop_id' and shop_settings.shop_code = '$shop_code'";
                $result = mysqli_query($con,$sql);
                if($rows = mysqli_fetch_assoc($result))
                {
                    $shop_details['owner'] = $rows['owner'];
                    $shop_details['owner_mobile'] = $rows['owner_mobile'];
                    $shop_details['manager'] = $rows['manager'];
                    $shop_details['manager_mobile'] = $rows['manager_mobile'];
                    $shop_details['email'] = $rows['email'];
                    $shop_details['address1'] = $rows['address1'];
                    $shop_details['address2'] = $rows['address2'];
                    $shop_details['area'] = $rows['area'];
                    $shop_details['city'] = $rows['city'];
                    $shop_details['pincode'] = $rows['pincode'];
                    $shop_details['ifsc_code'] = $rows['ifsc_code'];
                    $shop_details['bank_account_no'] = $rows['bank_account_no'];
                    $shop_details['bank_name'] = $rows['bank_name'];
                    $shop_details['branch_name'] = $rows['branch_name'];
                    $shop_details['is_bank_verified'] = $rows['is_bank_verified'];
                    $shop_details['account_holder_name'] = $rows['account_holder_name'];
                    $shop_details['min_order_value'] = $rows['min_order_value'];
                    $shop_details['free_deli_value'] = $rows['free_deli_value'];
                    $shop_details['tax_value'] = $rows['tax_value'];
                    $shop_details['shop_message'] = $rows['shop_message'];
                    $shop_details['start_time'] = $rows['start_time'];
                    $shop_details['end_time'] = $rows['end_time'];
                    $shop_details['shop_status'] = $rows['shop_status'];
                }
                $rows = array('shop_details'=>$shop_details);
                echo json_encode($rows);
            }
        }
        else
        {
            $rows = array('status'=>"",'message' => 'Data Error');
            echo json_encode($rows);
        }
    }

}


?>