update code

This commit is contained in:
root
2026-02-26 23:27:50 -05:00
parent 663c0cdbda
commit a6880ea14f
10 changed files with 807 additions and 138 deletions
+93 -5
View File
@@ -122,15 +122,40 @@
<div class="card shadow-sm">
<div class="card-body">
<?php
$cutoffDate = '';
$cutoffTime = '';
$cutoffThreshold = (string) ($cutoffThreshold ?? '09:00');
$cutoffTzAbbr = '';
try {
$tzName = (string) (config('School')->attendance['timezone'] ?? user_timezone());
$tz = new DateTimeZone($tzName ?: 'UTC');
$nowTz = new DateTime('now', $tz);
$cutoffDate = $nowTz->format('Y-m-d');
$cutoffTime = $nowTz->format('H:i');
$cutoffTzAbbr = $nowTz->format('T');
} catch (\Throwable $e) {
$cutoffDate = '';
$cutoffTime = '';
$cutoffTzAbbr = '';
}
?>
<form id="reportForm"
method="post"
action="<?= site_url('parent/report-attendance') ?>"
data-csrf-name="<?= esc(csrf_token()) ?>"
data-csrf-value="<?= esc(csrf_hash()) ?>"
data-check-url="<?= site_url('api/parent/report-attendance/check') ?>">
data-check-url="<?= site_url('api/parent/report-attendance/check') ?>"
data-cutoff-date="<?= esc($cutoffDate) ?>"
data-cutoff-time="<?= esc($cutoffTime) ?>"
data-cutoff-threshold="<?= esc($cutoffThreshold) ?>"
data-cutoff-blocked="0">
<input type="hidden" name="<?= csrf_token() ?>" value="<?= csrf_hash() ?>">
<div id="clientCheckAlert" class="alert d-none" role="alert"></div>
<div id="cutoffAlert" class="alert alert-warning d-none" role="alert">
Reporting closes at <?= esc($cutoffThreshold) ?><?= $cutoffTzAbbr !== '' ? ' ' . esc($cutoffTzAbbr) : '' ?> on the report date.
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Select Child(ren)</label>
@@ -352,7 +377,10 @@
const dates = selectedDates();
if (!checkUrl || !dateSel || !typeSel) return;
if (!ids.length || !dates.length) {
if (submitBtn) submitBtn.disabled = false;
if (submitBtn) {
const cutoffBlocked = form.getAttribute('data-cutoff-blocked') === '1';
submitBtn.disabled = cutoffBlocked;
}
return;
}
@@ -395,7 +423,10 @@
}
if (!data || !data.ok) {
if (submitBtn) submitBtn.disabled = false;
if (submitBtn) {
const cutoffBlocked = form.getAttribute('data-cutoff-blocked') === '1';
submitBtn.disabled = cutoffBlocked;
}
return;
}
@@ -454,10 +485,16 @@
setAlert('', '');
}
if (submitBtn) submitBtn.disabled = (selectedIds().length === 0);
if (submitBtn) {
const cutoffBlocked = form.getAttribute('data-cutoff-blocked') === '1';
submitBtn.disabled = cutoffBlocked || (selectedIds().length === 0);
}
} catch (e) {
setAlert('warn', 'Could not verify submissions right now. You may proceed; server will validate.');
if (submitBtn) submitBtn.disabled = false;
if (submitBtn) {
const cutoffBlocked = form.getAttribute('data-cutoff-blocked') === '1';
submitBtn.disabled = cutoffBlocked;
}
}
}
@@ -472,4 +509,55 @@
runCheck();
});
</script>
<script>
// Cutoff enforcement helper (9:00 AM on the selected Sunday).
document.addEventListener('DOMContentLoaded', function() {
const form = document.getElementById('reportForm');
if (!form) return;
const dateSel = form.querySelector('select[name="dates[]"]');
const submitBtn = form.querySelector('button[type="submit"]');
const cutoffAlert = document.getElementById('cutoffAlert');
const cutoffDate = form.getAttribute('data-cutoff-date') || '';
const cutoffTime = form.getAttribute('data-cutoff-time') || '';
const cutoffThreshold = form.getAttribute('data-cutoff-threshold') || '09:00';
function parseTimeToMinutes(val) {
const parts = (val || '').split(':');
if (parts.length < 2) return null;
const hh = parseInt(parts[0], 10);
const mm = parseInt(parts[1], 10);
if (Number.isNaN(hh) || Number.isNaN(mm)) return null;
return (hh * 60) + mm;
}
function updateCutoffState() {
if (!dateSel || !cutoffDate || !cutoffTime) return;
const dates = Array.from(dateSel.selectedOptions || [])
.map(opt => opt.value)
.filter(v => v);
const nowMinutes = parseTimeToMinutes(cutoffTime);
const cutoffMinutes = parseTimeToMinutes(cutoffThreshold);
const isTodaySelected = dates.includes(cutoffDate);
const blocked = isTodaySelected && nowMinutes !== null && cutoffMinutes !== null && nowMinutes >= cutoffMinutes;
form.setAttribute('data-cutoff-blocked', blocked ? '1' : '0');
if (cutoffAlert) {
cutoffAlert.classList.toggle('d-none', !blocked);
}
if (submitBtn && blocked) {
submitBtn.disabled = true;
}
}
form.addEventListener('change', function(e) {
const tgt = e.target;
if (!tgt) return;
if (tgt.matches('select[name="dates[]"], input[name="student_ids[]"], #reportType')) {
updateCutoffState();
}
});
updateCutoffState();
});
</script>
<?= $this->endSection() ?>