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

$patients = $conn->query("SELECT * FROM patients ORDER BY created_at DESC");
?>
<!DOCTYPE html>
<html>
<head><title>Manage Patients</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"><h2>Patient List</h2><div class="table-responsive"><table class="table table-bordered"><thead><tr><th>ID</th><th>Name</th><th>Email</th><th>Phone</th><th>Type</th><th>Status</th></tr></thead><tbody>
<?php while($p = $patients->fetch_assoc()): ?>
<tr><td><?= $p['patient_id'] ?></td><td><?= $p['first_name'].' '.$p['last_name'] ?></td><td><?= $p['email'] ?></td><td><?= $p['phone'] ?></td><td><?= ucfirst($p['user_type'] ?? 'patient') ?></td><td><?= $p['portal_active'] ? 'Active' : 'Inactive' ?></td></tr>
<?php endwhile; ?>
</tbody></table></div><a href="dashboard.php" class="btn btn-secondary">Back</a></div></body>
</html>