
<?php






require_once __DIR__ . '/db_connect.php';

        require_once __DIR__ . '/db_config.php';




$mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}




if (isset($_GET['allbranch'])) {
        if($_GET['allbranch']){ 
    
    
    $response = array();
    $allbranch = $_GET['allbranch'];
    
   
                                                   
    $query = "SELECT * FROM `branches`";
$result = $mysqli->query($query);
    $response = array();
        $response["branches"]= array();
while($row = $result->fetch_array())
{
            $order = array();
            $order["id"] = $row["id"];
            $order["name"] = $row["name"];
            array_push($response["branches"], $order);

            
        }
            $response["success"] = 1;
    echo json_encode($response["branches"]);

    }
    
}


if (isset($_GET['branch_id'], $_GET['categories'])) {//do the fields exist
    if($_GET['branch_id'] && $_GET['categories']){ //do the fields contain data
    $branch_id = $_GET['branch_id'];


$query = "SELECT parent_category_id,parent_category_name,'' as printer_name FROM `parent_categories` where branch_id= $branch_id";
$result = $mysqli->query($query);
    $response = array();
        $response["categories"]= array();
while($row2 = $result->fetch_array())
{
     $parent_categories = array();
               
            $parent_categories["parent_category_id"] = $row2["parent_category_id"];
            $parent_categories["parent_category_name"] = $row2["parent_category_name"];
            $parent_categories["printer_name"] = $row2["printer_name"];
            
            array_push($response["categories"], $parent_categories);
}


    $response["success"] = 1;
    echo json_encode($response["categories"]);
    
    }
}




if (isset($_GET['branch_id'], $_GET['drivers'])) {//do the fields exist
    if($_GET['branch_id'] && $_GET['drivers']){ //do the fields contain data

    $response = array();
    $branch_id = $_GET['branch_id'];
    
    
    $query = "SELECT id,name from `drivers`  where branch_id=$branch_id";
$result = $mysqli->query($query);
    $response = array();
        $response["drivers"]= array();
while($row = $result->fetch_array())
{
            $order = array();
            $order["id"] = $row["id"];
            $order["name"] = $row["name"];
            array_push($response["drivers"], $order);
}

    $response["success"] = 1;
    echo json_encode($response["drivers"]);




    }
    
}





