68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
require_once 'WorkflowEngine.php';
|
|
|
|
$personId = $_POST['person_id'] ?? null;
|
|
$meetingId = $_POST['meeting_id'] ?? null;
|
|
$attendance_status = $_POST['attendance_status'] ?? null;
|
|
$guest_survey = $_POST['guest_survey'] ?? null;
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
if (!$personId || !$meetingId || !$attendance_status) {
|
|
echo json_encode(['success' => false, 'message' => 'Missing required fields.']);
|
|
exit;
|
|
}
|
|
|
|
$db = db();
|
|
|
|
// Check if an attendance record already exists
|
|
$stmt_check = $db->prepare("SELECT id FROM meeting_attendance WHERE person_id = :person_id AND meeting_id = :meeting_id");
|
|
$stmt_check->execute([':person_id' => $personId, ':meeting_id' => $meetingId]);
|
|
$existing_id = $stmt_check->fetchColumn();
|
|
|
|
if ($existing_id) {
|
|
// Update existing record
|
|
$stmt_update = $db->prepare("
|
|
UPDATE meeting_attendance
|
|
SET attendance_status = :attendance_status, guest_survey = :guest_survey, updated_at = NOW()
|
|
WHERE id = :id
|
|
");
|
|
$stmt_update->execute([
|
|
':attendance_status' => $attendance_status,
|
|
':guest_survey' => $guest_survey,
|
|
':id' => $existing_id
|
|
]);
|
|
} else {
|
|
// Insert new record
|
|
$stmt_insert = $db->prepare("
|
|
INSERT INTO meeting_attendance (person_id, meeting_id, attendance_status, guest_survey)
|
|
VALUES (:person_id, :meeting_id, :attendance_status, :guest_survey)
|
|
");
|
|
$stmt_insert->execute([
|
|
':person_id' => $personId,
|
|
':meeting_id' => $meetingId,
|
|
':attendance_status' => $attendance_status,
|
|
':guest_survey' => $guest_survey
|
|
]);
|
|
}
|
|
|
|
if (in_array($guest_survey, ['1', '2', '3'])) {
|
|
session_start();
|
|
$userId = $_SESSION['user_id'] ?? null;
|
|
if ($userId) {
|
|
$workflowEngine = new WorkflowEngine();
|
|
try {
|
|
$stmt = $db->prepare("SELECT id FROM process_definitions WHERE code = 'guest_survey_follow_up'");
|
|
$stmt->execute();
|
|
$processDefinitionId = $stmt->fetchColumn();
|
|
if($processDefinitionId) {
|
|
$workflowEngine->getOrCreateInstanceByDefId($personId, $processDefinitionId, $userId);
|
|
}
|
|
} catch (Exception $e) {
|
|
error_log('Failed to start guest survey follow-up process: ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
|
|
echo json_encode(['success' => true]);
|