fix score submission, and class progress

This commit is contained in:
root
2026-04-04 17:44:40 -04:00
parent d158650be9
commit 05dad52e10
4 changed files with 75 additions and 36 deletions
+32 -33
View File
@@ -77,39 +77,25 @@
<div class="card shadow-sm mb-3">
<div class="card-header bg-white d-flex flex-wrap align-items-center justify-content-between gap-3">
<strong class="mb-0">Date Selection</strong>
<?php if ($isEdit): ?>
<div class="text-muted small">
<?php
try {
$displayStart = (new \DateTime($weekStartSelected))->format('M d, Y');
} catch (\Exception $e) {
$displayStart = $weekStartSelected;
}
?>
Week of <?= esc($displayStart ?: 'N/A') ?>
</div>
<input type="hidden" name="week_start" value="<?= esc($weekStartSelected) ?>">
<?php else: ?>
<div class="d-flex align-items-center gap-2">
<select id="weekStartSelect" name="week_start" class="form-select form-select-sm" required>
<option value="">Select week</option>
<?php foreach ($sundayOptions as $sunday): ?>
<?php
try {
$startDt = new \DateTime($sunday);
$displayStart = $startDt->format('M d, Y');
} catch (\Exception $e) {
$displayStart = $sunday;
}
?>
<option value="<?= esc($sunday) ?>" <?= $sunday === $weekStartSelected ? 'selected' : '' ?>>
<?= esc($displayStart) ?>
</option>
<?php endforeach; ?>
</select>
<div class="invalid-feedback">Week start is required.</div>
</div>
<?php endif; ?>
<div class="d-flex align-items-center gap-2">
<select id="weekStartSelect" name="week_start" class="form-select form-select-sm" required <?= $isEdit ? 'data-original-week="' . esc($weekStartSelected) . '"' : '' ?>>
<option value="">Select week</option>
<?php foreach ($sundayOptions as $sunday): ?>
<?php
try {
$startDt = new \DateTime($sunday);
$displayStart = $startDt->format('M d, Y');
} catch (\Exception $e) {
$displayStart = $sunday;
}
?>
<option value="<?= esc($sunday) ?>" <?= $sunday === $weekStartSelected ? 'selected' : '' ?>>
<?= esc($displayStart) ?>
</option>
<?php endforeach; ?>
</select>
<div class="invalid-feedback">Week start is required.</div>
</div>
</div>
<div class="card-body">
<input type="hidden" name="week_end" id="weekEndInput" value="<?= esc($weekEndValue) ?>" required>
@@ -306,6 +292,19 @@
const forms = document.querySelectorAll('.needs-validation');
Array.from(forms).forEach(form => {
form.addEventListener('submit', event => {
const originalWeek = weekStartSelect?.dataset.originalWeek || '';
if (originalWeek && weekStartSelect && weekStartSelect.value && weekStartSelect.value !== originalWeek) {
const ok = confirm('A progress report already exists for the original week. Change the week and override any existing report for the new date?');
if (!ok) {
event.preventDefault();
event.stopPropagation();
return;
}
const confirmInput = document.getElementById('confirmOverwriteInput');
if (confirmInput) {
confirmInput.value = '1';
}
}
const islamicUnits = form.querySelectorAll('input[name="unit_islamic[]"]');
const hasIslamicUnit = Array.from(islamicUnits).some(input => input.value.trim() !== '');
if (!hasIslamicUnit) {
+9
View File
@@ -308,6 +308,7 @@
id="submitScoresLockBtn"
formaction="<?= base_url('/teacher/submit-scores-lock') ?>"
formmethod="post"
data-confirm-message="Once you submit, you cannot add any scores or comments. Do you want to continue?"
<?= $scoresLocked ? 'disabled' : '' ?>>
<?= $scoresLocked ? 'Scores Locked' : 'Submit Semester Scores' ?>
</button>
@@ -430,6 +431,14 @@
form.addEventListener('submit', function(event) {
syncCsrfToken();
const submitter = event.submitter;
if (submitter && submitter.id === 'submitScoresLockBtn') {
const message = submitter.dataset.confirmMessage || 'Submit semester scores?';
if (!confirm(message)) {
event.preventDefault();
return;
}
}
const errors = [];
form.querySelectorAll('textarea[data-first-name]').forEach(function(field) {
const value = field.value.trim();