35311-vm/staff_dashboard.php
2025-10-29 00:24:58 +00:00

107 lines
4.4 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and has the 'staff' role
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'staff') {
header("Location: index.php");
exit;
}
// Fetch residents from the database
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, first_name, last_name, status, program FROM residents ORDER BY last_name, first_name");
$residents = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// Handle DB error - for now, just show a simple message
$error_message = "Error fetching resident data.";
// In a real app, you'd log this error.
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Staff Dashboard | Continuum of Healing</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="assets/css/custom.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">Continuum of Healing</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="staff_dashboard.php">Dashboard</a>
</li>
</ul>
</div>
<div class="d-flex">
<span class="navbar-text me-3">
Logged in as: <?php echo htmlspecialchars($_SESSION['user_email']); ?>
</span>
<a href="logout.php" class="btn btn-outline-danger">Logout</a>
</div>
</div>
</nav>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Continuum Control Center</h1>
</div>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<div class="card">
<div class="card-header">
All Residents
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Program</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (isset($residents) && !empty($residents)): ?>
<?php foreach ($residents as $resident): ?>
<tr>
<td><?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></td>
<td><?php echo htmlspecialchars($resident['program']); ?></td>
<td><span class="badge bg-primary"><?php echo htmlspecialchars($resident['status']); ?></span></td>
<td>
<a href="resident_view.php?id=<?php echo $resident['id']; ?>" class="btn btn-sm btn-outline-primary">View</a>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr>
<td colspan="4" class="text-center">No residents found.</td>
</tr>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>