95 lines
3.7 KiB
PHP
95 lines
3.7 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;
|
|
}
|
|
|
|
// Fetch the logged-in resident's data
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM residents WHERE user_id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$resident = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// If no resident profile is linked to this user account, show a message.
|
|
if (!$resident) {
|
|
$no_profile_message = "Your profile is not yet linked. Please contact support.";
|
|
}
|
|
|
|
} catch (PDOException $e) {
|
|
$error_message = "Error fetching your data.";
|
|
}
|
|
|
|
?>
|
|
<!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 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>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav">
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="resident_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">
|
|
<?php if (isset($resident) && $resident): ?>
|
|
<h1 class="h2">Welcome, <?php echo htmlspecialchars($resident['first_name']); ?>!</h1>
|
|
<?php else: ?>
|
|
<h1 class="h2">Welcome, Resident!</h1>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php if (isset($error_message)): ?>
|
|
<div class="alert alert-danger"><?php echo $error_message; ?></div>
|
|
<?php elseif (isset($no_profile_message)): ?>
|
|
<div class="alert alert-warning"><?php echo $no_profile_message; ?></div>
|
|
<?php elseif (isset($resident)): ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
Your Progress
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row">
|
|
<div class="col-md-6">
|
|
<p><strong>Name:</strong> <?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></p>
|
|
<p><strong>Program:</strong> <?php echo htmlspecialchars($resident['program']); ?></p>
|
|
</div>
|
|
<div class="col-md-6">
|
|
<p><strong>Status:</strong> <span class="badge bg-success"><?php echo htmlspecialchars($resident['status']); ?></span></p>
|
|
<p><strong>Last Check-in:</strong> <?php echo htmlspecialchars(date("M j, Y, g:i a", strtotime($resident['last_check_in']))); ?></p>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|