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


 $passengerID = filterRequest("passengerID"); 

$sql = "SELECT
   `id`, `promo_code`, `amount`, `description`, `passengerID`, `validity_start_date`,
    DATEDIFF(promos.validity_end_date, CURDATE()) AS validity_end_date
FROM
    `promos`
WHERE
    (passengerID = '$passengerID' OR passengerID LIKE '%all%')
    AND promos.validity_start_date <= CURDATE()
    AND promos.validity_end_date >= CURDATE();";

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

if ($result) {
    jsonSuccess($result);
} else {
    // Print an empty list
    jsonSuccess([]);
}
?>