<?php
require("lib/config.php");
require_once 'vendor/eway/eway-rapid-php/include_eway.php';
// =============== Get customer user api ===================================
$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;
			}
		}
    }
	$Res["message"] = "user detail ok"; 
	$Res["staus"] = "OK"; 
	if(isset($_REQUEST["all"]))
	{
		$Res["data"] = $customer;
		$Res["cust_detail"] = $cust_detail;
		$Res["cust_token"] = $cust_token;
	}
	elseif(isset($_REQUEST["token"]))
	{
		$Res["cust_token"] = $cust_token;
	}
	else
	{
		$fullname = $customer[0]["name"];
		$name_split = explode(" ", $fullname);
		$fname = $name_split[0];
		$lname = $name_split[1];
		$Res["data"]["fname"] = $fname ;
		$Res["data"]["lname"] = $lname ;
		$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"]["fam_pax"] = $cust_detail[0]["no_pax"];
		$Res["data"]["fam_rf"] = $cust_detail[0]["no_rf"];
		$Res["data"]["fam_ff"] = $cust_detail[0]["no_ff"];
		$Res["data"]["fam_b"] = $cust_detail[0]["no_b"];
		
		
	}
	
	
	
} 
else 
{
	$Res["message"] = "Username or Passowrd  not correct!"; 
	$Res["staus"] = "error"; 
}
	
	
echo json_encode(new ArrayObject($Res)); 
/*echo "<pre>";
print_r($Res);
//print_r($response);
echo "</pre>";*/
$conn->close();
// =============== New customer user api End Here ==========================


?>