<?php
require_once '../db/config.php';

session_start();
// Check if the user is logged in as an admin
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: login.php');
    exit;
}

if (isset($_GET['id']) && isset($_GET['status'])) {
    $driver_id = $_GET['id'];
    $status = $_GET['status'];

    $possible_statuses = ['approved', 'rejected'];

    if (in_array($status, $possible_statuses)) {
        $pdo = db();
        $update_stmt = $pdo->prepare("UPDATE drivers SET approval_status = :status WHERE id = :driver_id");
        $update_stmt->execute(['status' => $status, 'driver_id' => $driver_id]);
    }
}

header('Location: drivers.php');
exit;
?>