35311-vm/create_action_plan.php
2025-10-30 18:38:17 +00:00

117 lines
4.5 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['resident_id']) ? (int)$_GET['resident_id'] : 0;
if ($resident_id === 0) {
header("Location: staff_dashboard.php");
exit;
}
$pdo = db();
// Fetch resident details to display on the page
$stmt = $pdo->prepare("SELECT first_name, last_name FROM residents WHERE id = ?");
$stmt->execute([$resident_id]);
$resident = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$resident) {
header("Location: staff_dashboard.php");
exit;
}
$error_message = '';
$success_message = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (empty($_POST['title'])) {
$error_message = 'Please provide a title for the action plan.';
} else {
try {
$stmt = $pdo->prepare("INSERT INTO action_plans (resident_id, staff_id, title, description, status, due_date) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([
$resident_id,
$_SESSION['user_id'],
$_POST['title'],
$_POST['description'] ?? null,
$_POST['status'] ?? 'In Progress',
!empty($_POST['due_date']) ? $_POST['due_date'] : null
]);
header("Location: resident_view.php?id=" . $resident_id . "&success=1");
exit;
} catch (PDOException $e) {
$error_message = 'Database error: Could not create action plan. ' . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New 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="staff_dashboard.php">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">Create New Action Plan</h1>
<a href="resident_view.php?id=<?php echo $resident_id; ?>" class="btn btn-secondary">← Back to Resident View</a>
</div>
<p>Creating plan for: <strong><?php echo htmlspecialchars($resident['first_name'] . ' ' . $resident['last_name']); ?></strong></p>
<?php if ($error_message): ?>
<div class="alert alert-danger"><?php echo $error_message; ?></div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<form method="POST" action="create_action_plan.php?resident_id=<?php echo $resident_id; ?>">
<div class="mb-3">
<label for="title" class="form-label">Title</label>
<input type="text" class="form-control" id="title" name="title" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="5"></textarea>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option>Not Started</option>
<option selected>In Progress</option>
<option>Completed</option>
<option>On Hold</option>
</select>
</div>
<div class="col-md-6 mb-3">
<label for="due_date" class="form-label">Due Date</label>
<input type="date" class="form-control" id="due_date" name="due_date">
</div>
</div>
<button type="submit" class="btn btn-primary-custom">Save Action Plan</button>
</form>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>