<?php
require_once __DIR__ . '/../../connect.php';

$driver_phone = filterRequest("driver_phone");

$sql = "SELECT
    `driverToken`.`token`,
    `driver`.`id`,
    `driver`.`phone`,
    `driver`.`name_arabic`as name,
    driver.national_number
FROM
    `driverToken`
LEFT JOIN `driver` ON `driver`.`id` = `driverToken`.`captain_id`
WHERE
    `driver`.`phone` = '$driver_phone'";

$stmt = $con->prepare($sql);
$stmt->execute();
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);

if ($data) {
    // Print the car location data as JSON
    echo json_encode([
            'status' => 'success',
            
            'data' => $data
        ]);
} else {
    // Print a failure message
    jsonError($message = "No car locations found");
}

?>