<?php
$lines = file('/var/www/html/systapp-admin-php/logs/audit/backup-audit.log');
$entries = array_map('json_decode', $lines);

// Sort newest first
usort($entries, fn($a, $b) => strcmp($b->timestamp, $a->timestamp));

// Get latest snapshot timestamp
$latest_ts = $entries[0]->details->timestamp;

// Filter only entries from latest run
$latest_entries = array_filter($entries, fn($e) => $e->details->timestamp === $latest_ts);

echo "<h2>Latest Backup Audit</h2>";
echo "<p>Snapshot: $latest_ts</p>";

echo "<table border='1' cellpadding='6'>";
echo "<tr><th>Event</th><th>Status</th><th>Snapshot Path</th></tr>";

foreach ($latest_entries as $e) {
    echo "<tr>";
    echo "<td>{$e->event}</td>";
    echo "<td>{$e->details->status}</td>";
    echo "<td>{$e->details->snapshot}</td>";
    echo "</tr>";
}

echo "</table>";
?>

