<?php
session_start();
if (!isset($_SESSION['staff_id'])) { header("Location: login.php"); exit(); }
include '../include/config.php';

$messages = $conn->query("SELECT * FROM patient_notifications ORDER BY created_at DESC LIMIT 50");
?>
<!DOCTYPE html>
<html><head><title>Messages</title><link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"></head>
<body><div class="container mt-4"><div class="card"><div class="card-header bg-success text-white"><h4>Patient Notifications</h4></div><div class="card-body">
<div class="table-responsive"><table class="table"><thead><tr><th>Patient ID</th><th>Title</th><th>Message</th><th>Date</th></tr></thead><tbody>
<?php while($m=$messages->fetch_assoc()): ?>
<tr><td><?= $m['patient_id'] ?></td><td><?= htmlspecialchars($m['title']) ?></td><td><?= htmlspecialchars(substr($m['message'],0,50)) ?>...</td><td><?= date('M d, H:i', strtotime($m['created_at'])) ?></td></tr>
<?php endwhile; ?>
</tbody></table></div><a href="dashboard.php" class="btn btn-secondary">Back</a>
</div></div></div></body>
</html>