<?php
require("lib/config.php");
require_once 'vendor/eway/eway-rapid-php/include_eway.php';
// =============== Get customer user api ===================================
$data  = $_REQUEST;
$sql = "SELECT * FROM `booking` where id = '".$_REQUEST['bid']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{
	while($row_details = $result->fetch_assoc()) 
	{
		$booking_detail[] = $row_details;
	}
	$sql = "SELECT * FROM `customers` where email = '".$booking_detail[0]["email"]."'";
	$result = $conn->query($sql);
	if ($result->num_rows > 0) 
	{
		while($row_detail = $result->fetch_assoc()) 
		{
			$booking_details[] = $row_detail;
		}
		
	}
	$sql = "SELECT * FROM `driver` where spat_id = ".$booking_detail[0]['driver'];
	
	$driverq = $conn->query($sql);
	
	if($driverq->num_rows > 0) {
	
	$driver_row = $driverq->fetch_assoc();
	$driver = $driver_row["name"];
	$rego = $driver_row["registration"];
	} else {
	    
	 $driver = "unassigned";
	 $rego = "unassigned";
	    
	}
	
	if($booking_detail[0]['spatula_link'] == "" OR $booking_detail[0]['spatula_link'] == "[") {
	    
	    $sql = "SELECT * FROM `holding_link` where id = 1";
	
	    $hold = $conn->query($sql);

	    if($hold->num_rows > 0) {
	        $hold_link = $hold->fetch_assoc();
	        $spat_link = $hold_link["link"];
	    }
	    
	} else {
	    
	    $spat_link = $booking_detail[0]['spatula_link'];
	}
	
	
	
	$Res["data"] = $booking_detail;
	$Res["user-data"] = $booking_details;
	$Res["booking_status"] = $booking_detail[0]['status'];
	$Res["date"] = $booking_detail[0]['booking_date'];
	$Res["time"] = $booking_detail[0]['booking_time'];
	$Res["pickup"] = $booking_detail[0]['pickup_addr'];
	$Res["dropoff"] = $booking_detail[0]['pickoff_addr'];
	$Res["quote"] = $booking_detail[0]['quote'];
	$Res["vehicle"] = $booking_detail[0]['vehicle'];
	$Res["color"] = $booking_detail[0]['color'];
	$Res["rego"] = $rego;
	$Res["driver"] = $driver;
	$Res["spatula_link"] = $spat_link;
	$Res["message"] = "booking info for user"; 
	$Res["status"] = "OK"; 
	
}
else
{
	$Res["message"] = "no such result present in booking"; 
	$Res["status"] = "ok"; 
}

echo json_encode(new ArrayObject($Res)); 
				
