288 lines
16 KiB
PHP
288 lines
16 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;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// -- Analytics & Alerts --
|
|
// Fetch summary metrics
|
|
$total_residents = $pdo->query("SELECT count(*) FROM residents")->fetchColumn();
|
|
$active_residents = $pdo->query("SELECT count(*) FROM residents WHERE status = 'Active'")->fetchColumn();
|
|
$high_risk_residents = $pdo->query("SELECT count(*) FROM residents WHERE risk_level = 'High'")->fetchColumn();
|
|
|
|
// Fetch high-risk residents for the alert panel
|
|
$high_risk_alert_stmt = $pdo->query("SELECT id, first_name, last_name, program FROM residents WHERE risk_level = 'High' ORDER BY last_name, first_name LIMIT 5");
|
|
$high_risk_alerts = $high_risk_alert_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// -- Filtering --
|
|
$program_filter = $_GET['program'] ?? '';
|
|
$risk_filter = $_GET['risk_level'] ?? '';
|
|
$status_filter = $_GET['status'] ?? '';
|
|
|
|
$where_clauses = [];
|
|
$params = [];
|
|
|
|
if ($program_filter) {
|
|
$where_clauses[] = "program = ?";
|
|
$params[] = $program_filter;
|
|
}
|
|
if ($risk_filter) {
|
|
$where_clauses[] = "risk_level = ?";
|
|
$params[] = $risk_filter;
|
|
}
|
|
if ($status_filter) {
|
|
$where_clauses[] = "status = ?";
|
|
$params[] = $status_filter;
|
|
}
|
|
|
|
$sql = "SELECT id, first_name, last_name, status, program, risk_level, health_progress, housing_progress, employment_progress FROM residents";
|
|
if (!empty($where_clauses)) {
|
|
$sql .= " WHERE " . implode(' AND ', $where_clauses);
|
|
}
|
|
$sql .= " ORDER BY last_name, first_name";
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute($params);
|
|
$residents = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
// For filter dropdowns
|
|
$programs = $pdo->query("SELECT DISTINCT program FROM residents ORDER BY program")->fetchAll(PDO::FETCH_COLUMN);
|
|
$risk_levels = $pdo->query("SELECT DISTINCT risk_level FROM residents ORDER BY risk_level")->fetchAll(PDO::FETCH_COLUMN);
|
|
$statuses = $pdo->query("SELECT DISTINCT status FROM residents ORDER BY status")->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
?>
|
|
<!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="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
|
<link rel="stylesheet" href="assets/css/custom.css">
|
|
</head>
|
|
<body>
|
|
|
|
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
|
<div class="container-fluid">
|
|
<a class="navbar-brand" href="staff_dashboard.php">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 me-auto mb-2 mb-lg-0">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" aria-current="page" href="staff_dashboard.php">Dashboard</a>
|
|
</li>
|
|
</ul>
|
|
<a href="logout.php" class="btn btn-outline-light">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>
|
|
<a href="resident_intake.php" class="btn btn-primary-custom"><i class="bi bi-plus-circle me-2"></i>New Resident</a>
|
|
</div>
|
|
|
|
<!-- Analytics Overview -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Total Residents</h5>
|
|
<p class="card-text fs-4"><?php echo $total_residents; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Active Residents</h5>
|
|
<p class="card-text fs-4"><?php echo $active_residents; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center text-danger">
|
|
<div class="card-body">
|
|
<h5 class="card-title">High Risk</h5>
|
|
<p class="card-text fs-4"><?php echo $high_risk_residents; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Main Content: Resident List -->
|
|
<div class="col-lg-8">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<div class="d-flex justify-content-between align-items-center">
|
|
<span>All Residents</span>
|
|
<div>
|
|
<button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#filterCollapse" aria-expanded="false" aria-controls="filterCollapse">
|
|
<i class="bi bi-funnel me-1"></i> Filters
|
|
</button>
|
|
<a href="export_residents.php" id="export-csv-btn" class="btn btn-sm btn-outline-success">
|
|
<i class="bi bi-download me-1"></i> Export CSV
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<!-- Filter Form -->
|
|
<div class="collapse" id="filterCollapse">
|
|
<form method="GET" action="staff_dashboard.php" class="mb-4">
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<label for="program" class="form-label">Program</label>
|
|
<select name="program" id="program" class="form-select">
|
|
<option value="">All</option>
|
|
<?php foreach ($programs as $p): ?>
|
|
<option value="<?php echo htmlspecialchars($p); ?>" <?php echo ($program_filter === $p) ? 'selected' : ''; ?>><?php echo htmlspecialchars($p); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label for="risk_level" class="form-label">Risk Level</label>
|
|
<select name="risk_level" id="risk_level" class="form-select">
|
|
<option value="">All</option>
|
|
<?php foreach ($risk_levels as $r): ?>
|
|
<option value="<?php echo htmlspecialchars($r); ?>" <?php echo ($risk_filter === $r) ? 'selected' : ''; ?>><?php echo htmlspecialchars($r); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<label for="status" class="form-label">Status</label>
|
|
<select name="status" id="status" class="form-select">
|
|
<option value="">All</option>
|
|
<?php foreach ($statuses as $s): ?>
|
|
<option value="<?php echo htmlspecialchars($s); ?>" <?php echo ($status_filter === $s) ? 'selected' : ''; ?>><?php echo htmlspecialchars($s); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
<div class="mt-2 text-end">
|
|
<a href="staff_dashboard.php" class="btn btn-secondary">Reset</a>
|
|
<button type="submit" class="btn btn-primary-custom">Filter</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Program</th>
|
|
<th>Risk Level</th>
|
|
<th>Continuum</th>
|
|
<th>Status</th>
|
|
<th>Action</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!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>
|
|
<?php
|
|
$risk_color = 'secondary';
|
|
if ($resident['risk_level'] === 'High') $risk_color = 'danger';
|
|
if ($resident['risk_level'] === 'Medium') $risk_color = 'warning';
|
|
?>
|
|
<span class="badge bg-<?php echo $risk_color; ?>"><?php echo htmlspecialchars($resident['risk_level']); ?></span>
|
|
</td>
|
|
<td>
|
|
<div class="d-flex flex-column">
|
|
<div class="progress" style="height: 5px; margin-bottom: 2px;" title="Health: <?php echo $resident['health_progress']; ?>%">
|
|
<div class="progress-bar bg-success" role="progressbar" style="width: <?php echo $resident['health_progress']; ?>%;" aria-valuenow="<?php echo $resident['health_progress']; ?>" aria-valuemin="0" aria-valuemax="100"></div>
|
|
</div>
|
|
<div class="progress" style="height: 5px; margin-bottom: 2px;" title="Housing: <?php echo $resident['housing_progress']; ?>%">
|
|
<div class="progress-bar bg-primary" role="progressbar" style="width: <?php echo $resident['housing_progress']; ?>%;" aria-valuenow="<?php echo $resident['housing_progress']; ?>" aria-valuemin="0" aria-valuemax="100"></div>
|
|
</div>
|
|
<div class="progress" style="height: 5px;" title="Employment: <?php echo $resident['employment_progress']; ?>%">
|
|
<div class="progress-bar bg-warning" role="progressbar" style="width: <?php echo $resident['employment_progress']; ?>%;" aria-valuenow="<?php echo $resident['employment_progress']; ?>" aria-valuemin="0" aria-valuemax="100"></div>
|
|
</div>
|
|
</div>
|
|
</td>
|
|
<td>
|
|
<?php
|
|
$status_color = 'primary';
|
|
if ($resident['status'] === 'Inactive') $status_color = 'secondary';
|
|
if ($resident['status'] === 'Stabilized') $status_color = 'success';
|
|
?>
|
|
<span class="badge bg-<?php echo $status_color; ?>"><?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="6" class="text-center">No residents found matching your criteria.</td>
|
|
</tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Side Panel: AI Alerts -->
|
|
<div class="col-lg-4">
|
|
<div class="card border-danger">
|
|
<div class="card-header bg-danger text-white">
|
|
<i class="bi bi-exclamation-triangle-fill me-2"></i> High Risk Alerts
|
|
</div>
|
|
<div class="list-group list-group-flush">
|
|
<?php if (!empty($high_risk_alerts)): ?>
|
|
<?php foreach ($high_risk_alerts as $alert): ?>
|
|
<a href="resident_view.php?id=<?php echo $alert['id']; ?>" class="list-group-item list-group-item-action">
|
|
<div class="d-flex w-100 justify-content-between">
|
|
<h6 class="mb-1"><?php echo htmlspecialchars($alert['first_name'] . ' ' . $alert['last_name']); ?></h6>
|
|
</div>
|
|
<small class="text-muted"><?php echo htmlspecialchars($alert['program']); ?></small>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<div class="list-group-item">
|
|
<p class="mb-0 text-center text-muted">No high risk residents found.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
document.getElementById('export-csv-btn').addEventListener('click', function(e) {
|
|
e.preventDefault();
|
|
const program = document.getElementById('program').value;
|
|
const riskLevel = document.getElementById('risk_level').value;
|
|
const status = document.getElementById('status').value;
|
|
|
|
const params = new URLSearchParams();
|
|
if (program) params.append('program', program);
|
|
if (riskLevel) params.append('risk_level', riskLevel);
|
|
if (status) params.append('status', status);
|
|
|
|
const url = 'export_residents.php?' + params.toString();
|
|
window.location.href = url;
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|