164 lines
7.2 KiB
PHP
164 lines
7.2 KiB
PHP
<?php
|
|
include 'includes/staff_header.php';
|
|
require_once 'db/config.php';
|
|
|
|
// --- Data Fetching and Preparation ---
|
|
|
|
// Sample Data Generation (as requested)
|
|
$residents = [];
|
|
$domains = ['Economic Stability', 'Education', 'Health and Healthcare', 'Neighborhood and Environment', 'Social and Community Context'];
|
|
$risk_levels = ['Low', 'Medium', 'High', 'Critical'];
|
|
|
|
for ($i = 1; $i <= 20; $i++) {
|
|
$risk_score = rand(10, 95);
|
|
$domain_scores = [];
|
|
foreach ($domains as $domain) {
|
|
$domain_scores[$domain] = $risk_levels[array_rand($risk_levels)];
|
|
}
|
|
|
|
$residents[] = [
|
|
'id' => $i,
|
|
'name' => "Resident #$i",
|
|
'risk_score' => $risk_score,
|
|
'progress' => rand(-20, 20),
|
|
'domain_scores' => $domain_scores,
|
|
'last_check_in' => date('Y-m-d', time() - rand(0, 30) * 86400),
|
|
'has_critical_alert' => $risk_score > 85
|
|
];
|
|
}
|
|
|
|
// --- Aggregate Calculations ---
|
|
$total_residents = count($residents);
|
|
$high_risk_alerts = array_reduce($residents, function($carry, $res) {
|
|
return $carry + ($res['risk_score'] > 75 ? 1 : 0);
|
|
}, 0);
|
|
$avg_progress = array_reduce($residents, function($carry, $res) { return $carry + $res['progress']; }, 0) / $total_residents;
|
|
|
|
// Filter for search query
|
|
$search_query = isset($_GET['search']) ? trim($_GET['search']) : '';
|
|
if ($search_query) {
|
|
$residents = array_filter($residents, function($res) use ($search_query) {
|
|
return stripos($res['name'], $search_query) !== false;
|
|
});
|
|
}
|
|
|
|
// Get residents with critical alerts for the dedicated section
|
|
$alert_residents = array_filter($residents, function($res) {
|
|
return $res['has_critical_alert'];
|
|
});
|
|
|
|
?>
|
|
|
|
<div class="container mt-4">
|
|
<!-- Page Title -->
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Aggregate Dashboard</h1>
|
|
<a href="create_action_plan.php" class="btn btn-success"><i class="fas fa-plus me-2"></i>Generate New Action Plan</a>
|
|
</div>
|
|
|
|
<!-- Aggregate KPI Cards -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm">
|
|
<div class="card-body">
|
|
<p class="card-title text-muted">Total Residents</p>
|
|
<h2 class="display-5"><?php echo $total_residents; ?></h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm text-white bg-danger">
|
|
<div class="card-body">
|
|
<p class="card-title">High-Risk Alerts</p>
|
|
<h2 class="display-5"><?php echo $high_risk_alerts; ?></h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-md-4">
|
|
<div class="card text-center shadow-sm">
|
|
<div class="card-body">
|
|
<p class="card-title text-muted">Avg. Progress Change</p>
|
|
<h2 class="display-5"><?php echo number_format($avg_progress, 1); ?>%</h2>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Critical Alerts Section -->
|
|
<?php if (!empty($alert_residents)): ?>
|
|
<div class="card shadow-sm mb-4 border-danger">
|
|
<div class="card-header bg-danger text-white">
|
|
<h5 class="mb-0"><i class="fas fa-exclamation-triangle me-2"></i>Critical Warning Alerts</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<ul class="list-group list-group-flush">
|
|
<?php foreach ($alert_residents as $res): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<a href="resident_view.php?resident_id=<?php echo $res['id']; ?>" class="fw-bold text-decoration-none"><?php echo htmlspecialchars($res['name']); ?></a>
|
|
<small class="text-muted ms-2">Risk Score: <?php echo $res['risk_score']; ?>%</small>
|
|
</div>
|
|
<a href="resident_view.php?resident_id=<?php echo $res['id']; ?>" class="btn btn-sm btn-outline-primary">View Plan</a>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<!-- All Residents List -->
|
|
<div class="card shadow-sm">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0">All Residents</h5>
|
|
<form class="d-flex" method="GET" action="staff_dashboard.php">
|
|
<input class="form-control me-2" type="search" placeholder="Search residents..." name="search" value="<?php echo htmlspecialchars($search_query); ?>">
|
|
<button class="btn btn-outline-secondary" type="submit">Search</button>
|
|
</form>
|
|
</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover mb-0">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Name</th>
|
|
<th class="text-center">Risk Score</th>
|
|
<th class="text-center">Progress</th>
|
|
<th>Last Check-In</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($residents)): ?>
|
|
<tr>
|
|
<td colspan="5" class="text-center text-muted">No residents found.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($residents as $resident): ?>
|
|
<tr>
|
|
<td>
|
|
<a href="resident_view.php?resident_id=<?php echo $resident['id']; ?>" class="text-decoration-none fw-bold"><?php echo htmlspecialchars($resident['name']); ?></a>
|
|
</td>
|
|
<td class="text-center">
|
|
<span class="badge bg-<?php echo $resident['risk_score'] > 75 ? 'danger' : ($resident['risk_score'] > 50 ? 'warning' : 'success'); ?>">
|
|
<?php echo $resident['risk_score']; ?>%
|
|
</span>
|
|
</td>
|
|
<td class="text-center">
|
|
<span class="text-<?php echo $resident['progress'] >= 0 ? 'success' : 'danger'; ?>">
|
|
<i class="fas fa-arrow-<?php echo $resident['progress'] >= 0 ? 'up' : 'down'; ?>"></i>
|
|
<?php echo abs($resident['progress']); ?>%
|
|
</span>
|
|
</td>
|
|
<td><?php echo $resident['last_check_in']; ?></td>
|
|
<td class="text-end">
|
|
<a href="resident_view.php?resident_id=<?php echo $resident['id']; ?>" class="btn btn-sm btn-primary">View</a>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; // Assuming a footer file exists ?>
|