216 lines
12 KiB
PHP
216 lines
12 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();
|
|
|
|
// -- Fetch Domains --
|
|
$domains = [
|
|
['id' => 'economic', 'name' => 'Economic Stability'],
|
|
['id' => 'education', 'name' => 'Education Access & Quality'],
|
|
['id' => 'healthcare', 'name' => 'Health Care Access & Quality'],
|
|
['id' => 'neighborhood', 'name' => 'Neighborhood & Built Environment'],
|
|
['id' => 'social', 'name' => 'Social & Community Context'],
|
|
];
|
|
|
|
// -- Get active domain --
|
|
$active_domain_id = $_GET['domain'] ?? 'economic';
|
|
$active_domain_name = '';
|
|
foreach ($domains as $domain) {
|
|
if ($domain['id'] === $active_domain_id) {
|
|
$active_domain_name = $domain['name'];
|
|
break;
|
|
}
|
|
}
|
|
|
|
// --- DATA FETCHING FOR THE ACTIVE DOMAIN ---
|
|
|
|
// KPI: Total Residents in this domain (placeholder)
|
|
$kpi_total_residents = $pdo->query("SELECT COUNT(DISTINCT resident_id) FROM risk_scores WHERE domain = '{$active_domain_id}'")->fetchColumn();
|
|
|
|
// KPI: Average Risk Score
|
|
$kpi_avg_risk = $pdo->prepare("SELECT AVG(score_int) FROM risk_scores WHERE domain = ?");
|
|
$kpi_avg_risk->execute([$active_domain_id]);
|
|
$kpi_avg_risk = round($kpi_avg_risk->fetchColumn() ?? 0);
|
|
|
|
// KPI: High-Risk Residents
|
|
$kpi_high_risk_count = $pdo->prepare("SELECT COUNT(*) FROM risk_scores WHERE domain = ? AND level = 'high'");
|
|
$kpi_high_risk_count->execute([$active_domain_id]);
|
|
$kpi_high_risk_count = $kpi_high_risk_count->fetchColumn();
|
|
|
|
// Risk & Drivers: Top Drivers (Placeholder - requires JSON processing)
|
|
$top_drivers = [
|
|
['label' => 'Inconsistent employment', 'weight' => 0.8],
|
|
['label' => 'High rent burden', 'weight' => 0.7],
|
|
['label' => 'Lack of emergency funds', 'weight' => 0.6],
|
|
];
|
|
|
|
// Summary Table: Survey Responses
|
|
$survey_responses_stmt = $pdo->prepare("SELECT r.first_name, r.last_name, sr.question_label, sr.answer_value, sr.answered_at
|
|
FROM survey_responses sr
|
|
JOIN residents r ON sr.resident_id = r.id
|
|
WHERE sr.domain = ? ORDER BY sr.answered_at DESC LIMIT 10");
|
|
$survey_responses_stmt->execute([$active_domain_id]);
|
|
$survey_responses = $survey_responses_stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
?>
|
|
<!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 Nexus</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 Nexus</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-fluid 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>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<ul class="nav nav-tabs card-header-tabs" id="domainTabs" role="tablist">
|
|
<?php foreach ($domains as $domain): ?>
|
|
<li class="nav-item" role="presentation">
|
|
<a class="nav-link <?php echo ($domain['id'] === $active_domain_id) ? 'active' : ''; ?>" href="?domain=<?php echo $domain['id']; ?>" role="tab"><?php echo htmlspecialchars($domain['name']); ?></a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="tab-content" id="domainTabsContent">
|
|
<div class="tab-pane fade show active" role="tabpanel">
|
|
<h3 class="mb-4">Domain: <?php echo htmlspecialchars($active_domain_name); ?></h3>
|
|
|
|
<!-- Overview Cards (KPIs) -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Residents in Domain</h5>
|
|
<p class="card-text fs-4"><?php echo $kpi_total_residents; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Avg. Risk Score</h5>
|
|
<p class="card-text fs-4"><?php echo $kpi_avg_risk; ?>%</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 $kpi_high_risk_count; ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<!-- Left Column: Risk/Drivers & Actions -->
|
|
<div class="col-lg-4">
|
|
<div class="card mb-4">
|
|
<div class="card-header">Risk & Drivers</div>
|
|
<div class="card-body">
|
|
<h5 class="card-title">Top Risk Drivers</h5>
|
|
<ul class="list-group list-group-flush">
|
|
<?php foreach ($top_drivers as $driver): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<?php echo htmlspecialchars($driver['label']); ?>
|
|
<span class="badge bg-danger rounded-pill"><?php echo ($driver['weight'] * 100); ?>%</span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-header">Actions</div>
|
|
<div class="list-group list-group-flush">
|
|
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-ui-checks me-2"></i>Launch Follow-Up Survey</a>
|
|
<a href="create_referral.php" class="list-group-item list-group-item-action"><i class="bi bi-send me-2"></i>Create Referral</a>
|
|
<a href="add_case_note.php" class="list-group-item list-group-item-action"><i class="bi bi-journal-plus me-2"></i>Add Note</a>
|
|
<a href="#" class="list-group-item list-group-item-action"><i class="bi bi-check2-square me-2"></i>New Task</a>
|
|
<a href="#" class="list-group-item list-group-item-action text-success"><i class="bi bi-download me-2"></i>Export Domain Data (CSV)</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Right Column: Timeline & Summary Tables -->
|
|
<div class="col-lg-8">
|
|
<div class="card mb-4">
|
|
<div class="card-header">Domain Timeline</div>
|
|
<div class="card-body" style="height: 200px; overflow-y: auto;">
|
|
<p class="text-muted">[Placeholder for chronological stream of events: survey responses, notes, referrals, etc.]</p>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-header">Summary: Survey Responses</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-sm">
|
|
<thead>
|
|
<tr><th>Resident</th><th>Question</th><th>Answer</th><th>Date</th></tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (!empty($survey_responses)): ?>
|
|
<?php foreach ($survey_responses as $resp): ?>
|
|
<tr>
|
|
<td><?php echo htmlspecialchars($resp['first_name'] . ' ' . $resp['last_name']); ?></td>
|
|
<td><?php echo htmlspecialchars($resp['question_label']); ?></td>
|
|
<td><?php echo htmlspecialchars($resp['answer_value']); ?></td>
|
|
<td><?php echo date('M j, Y', strtotime($resp['answered_at'])); ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<tr><td colspan="4" class="text-center text-muted">No survey responses for this domain yet.</td></tr>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|