<?php
require("lib/config.php");
require_once 'vendor/eway/eway-rapid-php/include_eway.php';
$data  = $_REQUEST;
$sql = "SELECT * FROM customers where email = '".$_REQUEST['username']."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) 
{
    while($row = $result->fetch_assoc()) 
	{
        $customer[] = $row;
		$sql = "SELECT * FROM `customer_details` where `cid` = '".$row["id"]."'"; 
		$result = $conn->query($sql);
		if ($result->num_rows > 0) 
		{
			while($row_details = $result->fetch_assoc()) 
			{
				$cust_detail[] = $row_details;
			}
		}
		$sql = "SELECT * FROM `customer_tokens`  where `cid` = '".$row["id"]."'"; 
		$result = $conn->query($sql);
		if ($result->num_rows > 0) 
		{
			while($row_token = $result->fetch_assoc()) 
			{
				$cust_token[] = $row_token;
			}
		}
		$sql = "SELECT * FROM `booking` where email = '".$_REQUEST['username']."'";
		$result = $conn->query($sql);
		if ($result->num_rows > 0) 
		{
			while($row_booking = $result->fetch_assoc()) 
			{
				$cust_booking[] = $row_booking;
			}
		}
		
    }
}
$name = $customer[0]["name"];
$name_split = explode(" ",$name);
$fname = $name_split[0];
$lname = $name_split[1];
$cus = $customer[0]["name"];
$mob = $customer[0]["mobile"];

		$Res["data"]["id"] = $customer[0]["id"];
		$Res["data"]["name"] = $customer[0]["name"];
		$Res["data"]["mobile"] = $customer[0]["mobile"];
		$Res["data"]["email"] = $customer[0]["email"];
		$Res["data"]["address"] = $cust_detail[0]["address"];
		$Res["data"]["addr_lat"] = $cust_detail[0]["addr_lat"];
		$Res["data"]["addr_long"] = $cust_detail[0]["addr_long"];
		$Res["data"]["pickup_addr"] = $cust_booking[0]["pickup_addr"];
		$Res["data"]["pickup_lat"] = $cust_booking[0]["pickup_lat"];
		$Res["data"]["pickup_long"] = $cust_booking[0]["pickup_long"];
		$Res["data"]["pickoff_addr"] = $cust_booking[0]["pickoff_addr"];
		$Res["data"]["pickoff_lat"] = $cust_booking[0]["pickoff_lat"];
		$Res["data"]["pickoff_long"] = $cust_booking[0]["pickoff_long"];
		$Res["data"]["booking_date"] = $cust_booking[0]["booking_date"];
		$Res["data"]["booking_time"] = $cust_booking[0]["booking_time"];
		$Res["data"]["Access_token"] = $cust_token[0]["access_token_value"];
		$Res["data"]["show_message"] = "Thank you for submitting your booking. Please make sure the above details are correct. 
You will receive confirmation via SMS within 30 mins. 
When the driver is en route you will receive a tracking link via SMS with driver contact details and their ETA.
Please call 1300466365 if you need to make any changes at short notice."; 
	echo json_encode(new ArrayObject($Res));
