false, 'message' => 'An error occurred.']; if (!isset($_SESSION['user_id'])) { $response['message'] = 'You must be logged in to perform this action.'; echo json_encode($response); exit; } if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $response['message'] = 'Invalid request method.'; echo json_encode($response); exit; } $personId = $_POST['person_id'] ?? null; $groupId = $_POST['group_id'] ?? null; $meetingDate = $_POST['meeting_date'] ?? null; $status = $_POST['attendance_status'] ?? null; $guestSurvey = $_POST['guest_survey'] ?? null; $userId = $_SESSION['user_id']; if (!$personId || !$groupId || !$meetingDate || !$status) { $response['message'] = 'Missing required parameters.'; echo json_encode($response); exit; } try { $workflowEngine = new WorkflowEngine(); $meetingId = $workflowEngine->getOrCreateMeeting((int)$groupId, $meetingDate); $workflowEngine->updateMeetingAttendance($meetingId, (int)$personId, (int)$groupId, $status, (int)$userId, $guestSurvey); $response['success'] = true; $response['message'] = 'Attendance updated successfully.'; } catch (Exception $e) { error_log($e->getMessage()); $response['message'] = 'Error updating attendance: ' . $e->getMessage(); } echo json_encode($response);