123 lines
5.0 KiB
PHP
123 lines
5.0 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Check if user is logged in and has a staff role
|
|
if (!isset($_SESSION['user_id']) || !in_array($_SESSION['user_role'], ['staff', 'resident'])) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$action_plan_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
if ($action_plan_id === 0) {
|
|
header("Location: staff_dashboard.php");
|
|
exit;
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Handle status update
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['user_role'] === 'staff') {
|
|
try {
|
|
$sql = "UPDATE action_plans SET status = ? WHERE id = ?";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$_POST['status'], $action_plan_id]);
|
|
header("Location: view_action_plan.php?id=" . $action_plan_id . "&success=1");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
$error_message = "Database error: Could not update status. " . $e->getMessage();
|
|
}
|
|
}
|
|
|
|
// Fetch action plan details and resident info
|
|
$stmt = $pdo->prepare("SELECT ap.*, r.first_name, r.last_name FROM action_plans ap JOIN residents r ON ap.resident_id = r.id WHERE ap.id = ?");
|
|
$stmt->execute([$action_plan_id]);
|
|
$action_plan = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$action_plan) {
|
|
header("Location: staff_dashboard.php");
|
|
exit;
|
|
}
|
|
|
|
// Security check: if resident is logged in, ensure they own this action plan
|
|
if ($_SESSION['user_role'] === 'resident') {
|
|
$stmt = $pdo->prepare("SELECT id FROM residents WHERE user_id = ?");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$current_resident = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
if (!$current_resident || $action_plan['resident_id'] !== $current_resident['id']) {
|
|
header("Location: resident_dashboard.php");
|
|
exit;
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>View Action Plan - 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="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="#">Continuum Nexus</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<div class="container mt-4">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Action Plan Details</h1>
|
|
<?php
|
|
if ($_SESSION['user_role'] === 'staff') {
|
|
$back_link = "resident_view.php?id=" . $action_plan['resident_id'];
|
|
$back_text = "← Back to Resident View";
|
|
} else {
|
|
$back_link = "resident_dashboard.php";
|
|
$back_text = "← Back to Dashboard";
|
|
}
|
|
?>
|
|
<a href="<?php echo $back_link; ?>" class="btn btn-secondary"><?php echo $back_text; ?></a>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">
|
|
Plan for <?php echo htmlspecialchars($action_plan['first_name'] . ' ' . $action_plan['last_name']); ?>
|
|
</div>
|
|
<div class="card-body">
|
|
<h3><?php echo htmlspecialchars($action_plan['title']); ?></h3>
|
|
<p class="text-muted">Created on <?php echo date("F j, Y", strtotime($action_plan['created_at'])); ?></p>
|
|
<p><strong>Status:</strong> <span class="badge bg-info"><?php echo htmlspecialchars($action_plan['status']); ?></span></p>
|
|
<p><strong>Due Date:</strong> <?php echo $action_plan['due_date'] ? date("F j, Y", strtotime($action_plan['due_date'])) : 'N/A'; ?></p>
|
|
<hr>
|
|
<p><?php echo nl2br(htmlspecialchars($action_plan['description'])); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($_SESSION['user_role'] === 'staff'): ?>
|
|
<div class="card mt-4">
|
|
<div class="card-header">Update Status</div>
|
|
<div class="card-body">
|
|
<form method="POST" action="view_action_plan.php?id=<?php echo $action_plan_id; ?>">
|
|
<div class="input-group">
|
|
<select class="form-select" name="status">
|
|
<option <?php echo ($action_plan['status'] == 'Not Started') ? 'selected' : ''; ?>>Not Started</option>
|
|
<option <?php echo ($action_plan['status'] == 'In Progress') ? 'selected' : ''; ?>>In Progress</option>
|
|
<option <?php echo ($action_plan['status'] == 'Completed') ? 'selected' : ''; ?>>Completed</option>
|
|
<option <?php echo ($action_plan['status'] == 'On Hold') ? 'selected' : ''; ?>>On Hold</option>
|
|
</select>
|
|
<button type="submit" class="btn btn-primary-custom">Update</button>
|
|
</div>
|
|
</form>
|
|
</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>
|