35311-vm/resident_view.php
Flatlogic Bot c5ae495f9e draft 2
2025-10-29 20:33:18 +00:00

133 lines
6.0 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;
}
$resident_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($resident_id === 0) {
header("Location: staff_dashboard.php");
exit;
}
$pdo = db();
// Fetch resident details
$stmt = $pdo->prepare("SELECT * FROM residents WHERE id = ?");
$stmt->execute([$resident_id]);
$resident = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$resident) {
header("Location: staff_dashboard.php");
exit;
}
// Fetch action plans for the resident
$stmt = $pdo->prepare("SELECT * FROM action_plans WHERE resident_id = ? ORDER BY created_at DESC");
$stmt->execute([$resident_id]);
$action_plans = $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>View Resident - <?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></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-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="staff_dashboard.php">Continuum of Healing</a>
<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" 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">Resident: <?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></h1>
<a href="staff_dashboard.php" class="btn btn-secondary">← Back to Dashboard</a>
</div>
<!-- Resident Details Card -->
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
Resident Information
<a href="resident_edit.php?id=<?php echo $resident_id; ?>" class="btn btn-secondary btn-sm">Edit</a>
</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>Email:</strong> <?php echo htmlspecialchars($resident['email']); ?></p>
<p><strong>Phone:</strong> <?php echo htmlspecialchars($resident['phone_number'] ?? 'N/A'); ?></p>
</div>
<div class="col-md-6">
<p><strong>Program:</strong> <?php echo htmlspecialchars($resident['program']); ?></p>
<p><strong>Status:</strong> <span class="badge bg-primary"><?php echo htmlspecialchars($resident['status']); ?></span></p>
<p><strong>Date of Birth:</strong> <?php echo htmlspecialchars($resident['date_of_birth'] ? date("M j, Y", strtotime($resident['date_of_birth'])) : 'N/A'); ?></p>
</div>
</div>
</div>
</div>
<!-- Action Plans Card -->
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
Action Plans
<a href="create_action_plan.php?resident_id=<?php echo $resident_id; ?>" class="btn btn-primary-custom btn-sm">+ New Action Plan</a>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Status</th>
<th>Due Date</th>
<th>Created On</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (empty($action_plans)): ?>
<tr>
<td colspan="5" class="text-center">No action plans found for this resident.</td>
</tr>
<?php else: ?>
<?php foreach ($action_plans as $plan): ?>
<tr>
<td><?php echo htmlspecialchars($plan['title']); ?></td>
<td><span class="badge bg-info"><?php echo htmlspecialchars($plan['status']); ?></span></td>
<td><?php echo htmlspecialchars($plan['due_date'] ? date("M j, Y", strtotime($plan['due_date'])) : 'N/A'); ?></td>
<td><?php echo htmlspecialchars(date("M j, Y", strtotime($plan['created_at']))); ?></td>
<td>
<a href="view_action_plan.php?id=<?php echo $plan['id']; ?>" class="btn btn-outline-secondary btn-sm">View/Edit</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>