<?php
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
require_once __DIR__ . '/../includes/db.php';

// Publicly accessible to allow public order.php page polling
$result = $conn->query("SELECT table_name, UNIX_TIMESTAMP(last_updated) AS ts, COALESCE(version, 1) AS version FROM system_states");
$states = [];
if ($result) {
    while ($row = $result->fetch_assoc()) {
        $states[$row['table_name']] = (int)$row['ts'] . '_' . (int)$row['version'];
    }
}

echo json_encode([
    "status" => "success",
    "states" => $states
]);
exit;
?>
