37338-vm/_get_meeting_attendance_details.php
2026-01-11 12:14:53 +00:00

118 lines
5.0 KiB
PHP

<?php
require_once 'WorkflowEngine.php';
$personId = $_GET['personId'] ?? null;
$meetingId = $_GET['meetingId'] ?? null;
if (!$personId || !$meetingId) {
die('Person ID and Meeting ID are required.');
}
$workflowEngine = new WorkflowEngine();
$db = db();
// Fetch person details
$stmt_person = $db->prepare("SELECT * FROM people WHERE id = :id");
$stmt_person->execute([':id' => $personId]);
$person = $stmt_person->fetch(PDO::FETCH_ASSOC);
// Fetch meeting details
$stmt_meeting = $db->prepare("SELECT m.*, bg.name as group_name FROM meetings m JOIN bni_groups bg ON m.group_id = bg.id WHERE m.id = :id");
$stmt_meeting->execute([':id' => $meetingId]);
$meeting = $stmt_meeting->fetch(PDO::FETCH_ASSOC);
// Fetch attendance details
$stmt_attendance = $db->prepare("SELECT * FROM meeting_attendance WHERE person_id = :person_id AND meeting_id = :meeting_id");
$stmt_attendance->execute([':person_id' => $personId, ':meeting_id' => $meetingId]);
$attendance = $stmt_attendance->fetch(PDO::FETCH_ASSOC);
$is_member = $person['bni_group_id'] == $meeting['group_id'];
if (!$attendance) {
$attendance = [
'attendance_status' => $is_member ? 'present' : 'n/a',
'guest_survey' => null
];
}
?>
<h4>Meeting Attendance</h4>
<p><strong>Person:</strong> <?= htmlspecialchars($person['first_name'].' '.$person['last_name']) ?></p>
<p><strong>Meeting:</strong> <?= htmlspecialchars($meeting['group_name']) ?> on <?= date('d/m/Y', strtotime($meeting['meeting_date'])) ?></p>
<form id="meetingAttendanceForm" action="_update_meeting_attendance.php" method="post">
<input type="hidden" name="person_id" value="<?= $personId ?>">
<input type="hidden" name="meeting_id" value="<?= $meetingId ?>">
<div class="mb-3">
<label for="attendance_status" class="form-label">Attendance Status</label>
<select class="form-select" id="attendance_status" name="attendance_status">
<option value="present" <?= ($attendance['attendance_status'] == 'present') ? 'selected' : '' ?>>Present</option>
<option value="absent" <?= ($attendance['attendance_status'] == 'absent') ? 'selected' : '' ?>>Absent</option>
<option value="substitute" <?= ($attendance['attendance_status'] == 'substitute') ? 'selected' : '' ?>>Substitute</option>
<option value="n/a" <?= ($attendance['attendance_status'] == 'n/a') ? 'selected' : '' ?>>N/A</option>
</select>
</div>
<?php
// The guest survey is only applicable if the person is not a member of the group.
$is_guest = !$is_member;
// The survey div should be visible only if the guest is present.
$show_survey = $is_guest && ($attendance['attendance_status'] == 'present');
?>
<div id="guest_survey_div" class="mb-3" style="display: <?= $show_survey ? 'block' : 'none' ?>;">
<label for="guest_survey" class="form-label">Guest Survey</label>
<select class="form-select" id="guest_survey" name="guest_survey">
<option value="" <?= (is_null($attendance['guest_survey'])) ? 'selected' : '' ?>>Not applicable</option>
<option value="1" <?= ($attendance['guest_survey'] == '1') ? 'selected' : '' ?>>1</option>
<option value="2" <?= ($attendance['guest_survey'] == '2') ? 'selected' : '' ?>>2</option>
<option value="3" <?= ($attendance['guest_survey'] == '3') ? 'selected' : '' ?>>3</option>
</select>
</div>
<button type="submit" class="btn btn-primary">Save</button>
</form>
<script>
document.getElementById('attendance_status').addEventListener('change', function() {
var guestSurveyDiv = document.getElementById('guest_survey_div');
var isGuest = <?= json_encode($is_guest) ?>;
if (this.value === 'present' && isGuest) {
guestSurveyDiv.style.display = 'block';
} else {
guestSurveyDiv.style.display = 'none';
document.getElementById('guest_survey').value = '';
}
});
document.getElementById('meetingAttendanceForm').addEventListener('submit', function(e) {
e.preventDefault();
var formData = new FormData(this);
fetch('_update_meeting_attendance.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
var instanceModal = bootstrap.Modal.getInstance(document.getElementById('instanceModal'));
instanceModal.hide();
// Find the dot and update its color
let dot = document.querySelector(`span[data-person-id='${formData.get('person_id')}'][data-meeting-id='${formData.get('meeting_id')}']`);
if (dot) {
const status_color_map = {
'present': 'success',
'absent': 'danger',
'substitute': 'warning',
'n/a': 'secondary'
};
dot.className = `badge rounded-circle bg-${status_color_map[formData.get('attendance_status')]}`;
}
} else {
alert('Failed to save attendance.');
}
});
});
</script>