<?php

require_once __DIR__ . '/db_config.php';

$r = array();
$r["brand"]= array();
$r["model"]= array();
$r["product"]= array();
$r["serial"]= array();
$r["qcat"]= array();
$r["qsubcat"]= array();
$r["ques"]= array();
$r["assign"] = array();
$r["combs"] = array();
$r["facility"] = array();
$r["subcat"]= array();
$r["cat"]= array();
$r["type"]= array();


if (isset($_POST["mail"]) ) {
 
$cname=$_POST["cname"];
$email=$_POST["mail"];
date_default_timezone_set('Asia/Calcutta');
$date=date('Y-m-d');
//$email="demonew3@gmail.com";

$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE) or die(mysql_error());

$combs=array();
$cat=array();
$subcat=array();
$type=array();
 mysqli_query($con,'SET CHARACTER SET utf8');

$comQuery="SELECT ID,type,typename,custonermode,atmid,brand,product,model,serialnumber,deleted,dateandtime,customername,
    service_category,service_subcategory,service_servicetype,u_datetime 
    FROM combination 
    WHERE companyname='$cname' AND deleted='no'";

$result=mysqli_query($con,$comQuery);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r["combs"], $row);
            array_push($cat, $row["service_category"]);
            array_push($subcat, $row["service_subcategory"]);
            array_push($type,$row["service_servicetype"]);
        }
}

if(count($cat)!=0){
    $cat=array_unique($cat);
    $catQuery="SELECT id,category_name,category_description FROM service_category WHERE   (id='".implode("' OR  id='",$cat)."')";
    $result=mysqli_query($con,$catQuery);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r["cat"], $row);
        }
    }
}

if(count($subcat)!=0){
    $subcat=array_unique($subcat);
   $subcatQuery="SELECT id,category_name,sub_category_name,description 
   FROM service_sub_category 
   WHERE (id='".implode("' OR  id='",$subcat)."')";
    $result=mysqli_query($con,$subcatQuery);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r["subcat"], $row);
        }
    }
}

if(count($type)!=0){
    $type=array_unique($type);
   $typeQuery="SELECT id,category,sub_category,service_type,details FROM service_type WHERE   (id='".implode("' OR  id='",$type)."')";
    $result=mysqli_query($con,$typeQuery);
    if(!empty($result) && mysqli_num_rows($result) > 0){
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)) {
            array_push($r["type"], $row);
        }
    }
}

}

echo json_encode($r);


?>