<?php
// track.php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $trackingId = trim($_POST['tracking_id']);
    $ordersFile = 'orders.json';

    if (file_exists($ordersFile)) {
        $orders = json_decode(file_get_contents($ordersFile), true);

        if (isset($orders[$trackingId])) {
            $orderStatus = $orders[$trackingId]['status'];
        } else {
            $orderStatus = "Invalid tracking ID. Please check and try again.";
        }
    } else {
        $orderStatus = "No orders found in the system.";
    }
}
?>

<!DOCTYPE html>
<html lang="en" data-bs-theme="dark">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Track Order - African Nigerian Restaurant</title>
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-dark text-light">

<div class="container mt-5">
  <h1 class="text-warning text-center">Track Your Order</h1>
  <form method="POST" action="track.php" class="p-4 bg-secondary rounded shadow mt-4">
    <div class="mb-3">
      <label class="form-label">Enter Tracking ID</label>
      <input type="text" name="tracking_id" class="form-control" placeholder="e.g. #ORD12345" required>
    </div>
    <button type="submit" class="btn btn-warning">Check Status</button>
  </form>

  <?php if (isset($orderStatus)): ?>
    <div class="alert alert-info mt-4">
      <strong>Status:</strong> <?= htmlspecialchars($orderStatus) ?>
    </div>
  <?php endif; ?>
</div> 
 
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>