<?php
require "conn.php";



$DriverId  		   = $_POST["DriverId"];
$Fname     		   = $_POST["Name"];
$LName    		   = $_POST["Lname"];
$DriverEmail       = $_POST["DriverEmail"];
$PersonalPhoto     = $_POST["PersonalPhoto"];

$photo1name=rand(1,700000).rand(1,700000);



$paths1 = "$photo1name.png";
$path1 =  "photo/$paths1";
$actualpath1 = $DomainNamee."$path1";





$Token = "s";

foreach (getallheaders() as $name => $value) { 

	if($name == "token"){
		
		$Token = $value;
	
	}
	
} 

$test=0;

	$res = mysqli_query($con,"SELECT * FROM Drivers WHERE DriverToken='$Token'");
	while($row = mysqli_fetch_assoc($res)){
		
		
		$test=4;

	}
	
	if($test==4){

   $sql="UPDATE Drivers SET DriverEmail='$DriverEmail', Fname='$Fname',LName='$LName',PersonalPhoto='$actualpath1' WHERE DriverID=$DriverId";
   if(mysqli_query($con,$sql))
   {
	   
	   
	   
	file_put_contents($path1,base64_decode($PersonalPhoto));		

	$message ="Updated Sucssessfuly";
    $success = true;
    $status_code = 200;
	//$result = []; 
	$res = mysqli_query($con,"SELECT * FROM Drivers WHERE DriverID=$DriverId");

$result = array();

while($row = mysqli_fetch_assoc($res)){

//$data = $row[0];
$result[] = $row;


$test=4;

}
    echo json_encode(array('status_code' => $status_code,'success' => $success ,"data"=>$result[0],"message"=>$message));

   }
   else
   {
	   
	   

	$message ="Error Updated";
    $success = false;
    $status_code = 200;
	$result = []; 
    echo json_encode(array('status_code' => $status_code,'success' => $success ,"data"=>$result,"message"=>$message));

   }
   
	}
	
	else{
		
		
			$message ="Error Token Eror";
			$success = false;
			$status_code = 200;
			$result = []; 
   echo json_encode(array('status_code' => $status_code,'success' => $success ,"data"=>$result,"message"=>$message));
		
	}
die;
mysqli_close($con);
?>