35311-vm/resident_dashboard.php
Flatlogic Bot 540e3681d5 10 30 2
2025-10-30 19:18:05 +00:00

154 lines
6.8 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
// Check if user is logged in and has the 'resident' role
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'resident') {
header("Location: index.php");
exit;
}
$resident_id = $_SESSION['user_id'];
$pdo = db();
// Fetch resident's first name
$stmt = $pdo->prepare("SELECT first_name FROM residents WHERE id = ?");
$stmt->execute([$resident_id]);
$resident_name = $stmt->fetchColumn();
// Fetch resident's domain risk scores, levels, and drivers
$risk_scores_stmt = $pdo->prepare("
SELECT domain, score_int, level, drivers
FROM risk_scores
WHERE resident_id = ?
ORDER BY domain
");
$risk_scores_stmt->execute([$resident_id]);
$risk_scores = $risk_scores_stmt->fetchAll(PDO::FETCH_ASSOC | PDO::FETCH_GROUP);
// Fetch resident's action plans
$action_plans_stmt = $pdo->prepare("
SELECT ap.id, ap.title, ap.status, ap.domain
FROM action_plans ap
WHERE ap.resident_id = ?
ORDER BY ap.created_at DESC
");
$action_plans_stmt->execute([$resident_id]);
$action_plans = $action_plans_stmt->fetchAll(PDO::FETCH_ASSOC);
// Domain names mapping
$domains = [
'economic' => 'Economic Stability',
'education' => 'Education Access & Quality',
'healthcare' => 'Health Care Access & Quality',
'neighborhood' => 'Neighborhood & Built Environment',
'social' => 'Social & Community Context',
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Resident 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>
<?php include 'includes/resident_header.php'; ?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="h2">Welcome, <?php echo htmlspecialchars($resident_name); ?>!</h1>
<div>
<a href="messages.php" class="btn btn-primary-custom"><i class="bi bi-inbox-fill me-2"></i>My Messages</a>
</div>
</div>
<h3 class="mb-4">Your Domain Overview</h3>
<div class="row">
<?php foreach ($domains as $domain_id => $domain_name): ?>
<?php
$score_data = $risk_scores[$domain_id][0] ?? null;
$score = $score_data ? (int)$score_data['score_int'] : 0;
$level = $score_data ? ucfirst($score_data['level']) : 'N/A';
$drivers = $score_data && $score_data['drivers'] ? json_decode($score_data['drivers'], true) : [];
$level_class = 'text-bg-secondary';
if ($level === 'High') $level_class = 'text-bg-danger';
if ($level === 'Moderate') $level_class = 'text-bg-warning';
if ($level === 'Low') $level_class = 'text-bg-success';
?>
<div class="col-md-6 mb-4">
<div class="card h-100">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0"><?php echo htmlspecialchars($domain_name); ?></h5>
<span class="badge <?php echo $level_class; ?>"><?php echo htmlspecialchars($level); ?></span>
</div>
<div class="card-body">
<div class="text-center mb-3">
<p class="display-4 fw-bold mb-0"><?php echo $score; ?><span class="fs-5">/100</span></p>
<p class="text-muted mb-0">Risk Score</p>
</div>
<?php if (!empty($drivers)): ?>
<h6 class="card-subtitle mb-2 text-muted">Key Factors:</h6>
<ul class="list-group list-group-flush">
<?php foreach ($drivers as $driver): ?>
<li class="list-group-item">- <?php echo htmlspecialchars($driver['label']); ?></li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p class="text-muted text-center">No specific risk factors identified.</p>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="card mt-4">
<div class="card-header">
<h4 class="mb-0"><i class="bi bi-list-check me-2"></i>Your Action Plans</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle">
<thead>
<tr>
<th>Title</th>
<th>Domain</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php if (empty($action_plans)): ?>
<tr>
<td colspan="4" class="text-center text-muted">You have no active action plans.</td>
</tr>
<?php else: ?>
<?php foreach ($action_plans as $plan): ?>
<tr>
<td><?php echo htmlspecialchars($plan['title']); ?></td>
<td><span class="badge text-bg-info"><?php echo htmlspecialchars($domains[$plan['domain']] ?? 'N/A'); ?></span></td>
<td><span class="badge text-bg-primary"><?php echo htmlspecialchars(ucfirst($plan['status'])); ?></span></td>
<td class="text-end">
<a href="view_action_plan.php?id=<?php echo $plan['id']; ?>" class="btn btn-sm btn-outline-primary">View</a>
</td>
</tr>
<?php endforeach; ?>
<?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>