<?php

use Illuminate\Support\Arr;

require "Config.php";
require "Crud.php";
require dirname(dirname(__FILE__)) . "/vendor/autoload.php";

// use Grimzy\LaravelMysqlSpatial\Types\Point;
// use Grimzy\LaravelMysqlSpatial\Types\Polygon;
// use Grimzy\LaravelMysqlSpatial\Types\LineString;

// function siteURL()
// {
//     $protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ||
//         $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
//     $domainName = $_SERVER['HTTP_HOST'];
//     return $protocol . $domainName;
// }

// return json_encode('hre');
if (isset($_POST["type"])) {
    if ($_POST["type"] == "list_category") {
        $cat = $lundry->query("select * from tbl_mcat");
        $row = $cat->fetch_assoc();

        echo json_encode($row);
    } else if ($_POST["type"] == "list_products") {
        $prdres = $lundry->query("select * from tbl_product where cat_id=" . $_POST["category_id"] . "");

        $products = array();
        while ($all_products = $prdres->fetch_assoc()) {

            $products[] = $all_products;
        }

        echo json_encode($products);
    }else if ($_POST["type"] == "list_attributes") {
        $prdres = $lundry->query("select * from tbl_product_attribute where product_id=" . $_POST["product_id"] . "");

        $products = array();
        while ($all_products = $prdres->fetch_assoc()) {

            $products[] = $all_products;
        }

        echo json_encode($products);
    }
}

if(isset($_GET['type'])){
    if ($_GET["type"] == "delete_customer") {
        $lundry->query("delete from tbl_user where id=" . $_GET["c_id"] . "");
         
            $returnArr = array(
                "ResponseCode" => "200",
                "Result" => "true",
                "title" => "Customer deleted successfully",
                "message" => "Something is done!",
                "action" => "list_customers.php",

            );
        
    }
    
}
