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(); } } } ?>