From 253be573ac36e770bcc7f37b24eeb1186ec61d64 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 27 Feb 2026 15:26:23 -0500 Subject: [PATCH] score submit fix for spring semester --- .gitignore | 1 + app/Controllers/View/ScoreController.php | 31 ++++++++++++++++++++++++ public/assets/js/validateScores.js | 15 ++++++++++-- 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 397b4a7..02be6e4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.log +writable/session/ diff --git a/app/Controllers/View/ScoreController.php b/app/Controllers/View/ScoreController.php index ff24070..ef8c530 100644 --- a/app/Controllers/View/ScoreController.php +++ b/app/Controllers/View/ScoreController.php @@ -339,6 +339,37 @@ class ScoreController extends Controller ); } + try { + $students = $this->getStudentScores($classSectionId, $semester, $schoolYear, $teacherId); + } catch (\Throwable $e) { + log_message('error', 'ScoreController::submitScoresLock missing check failed: ' . $e->getMessage()); + return redirect()->back()->with('error', 'Unable to validate missing scores. Please try again.'); + } + + $missingRows = []; + foreach ($students as $student) { + $missingItems = $student['missing_items'] ?? []; + if (empty($missingItems)) { + continue; + } + $studentId = (int) ($student['student_id'] ?? 0); + $studentName = trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')); + if ($studentName === '') { + $studentName = $studentId > 0 ? ('Student #' . $studentId) : 'Student'; + } + $missingRows[] = $studentName . ': ' . implode(', ', $missingItems); + } + + if (!empty($missingRows)) { + $sample = array_slice($missingRows, 0, 8); + $message = sprintf( + 'Missing entries found for %d student(s). Fill them or mark "Missing ok" before submitting. %s', + count($missingRows), + $sample ? ('Examples: ' . implode(' | ', $sample)) : '' + ); + return redirect()->back()->with('error', trim($message)); + } + $existing = $this->gradingLockModel->getLock($classSectionId, $semester, $schoolYear); if (!empty($existing) && !empty($existing['is_locked'])) { return redirect()->back()->with('status', 'Scores already submitted and locked.'); diff --git a/public/assets/js/validateScores.js b/public/assets/js/validateScores.js index dc4cbeb..5a58137 100644 --- a/public/assets/js/validateScores.js +++ b/public/assets/js/validateScores.js @@ -32,9 +32,20 @@ document.addEventListener('DOMContentLoaded', function () { toggleCommentCheckbox(wrapper); }); + let lastSubmitterId = null; + form.addEventListener('click', function (event) { + const target = event.target.closest('button, input[type="submit"]'); + if (!target || target.form !== form) return; + lastSubmitterId = target.id || null; + }); + form.addEventListener('submit', function (event) { - const submitter = event.submitter; - if (!submitter || submitter.id !== 'submitScoresLockBtn') { + const activeEl = document.activeElement; + const submitterId = event.submitter + ? event.submitter.id + : (activeEl && activeEl.form === form ? activeEl.id : lastSubmitterId); + lastSubmitterId = null; + if (submitterId !== 'submitScoresLockBtn') { return; }