diff --git a/app/Controllers/ClassProgressController.php b/app/Controllers/ClassProgressController.php index c40ba30..0a63e2e 100644 --- a/app/Controllers/ClassProgressController.php +++ b/app/Controllers/ClassProgressController.php @@ -383,13 +383,18 @@ class ClassProgressController extends BaseController } } + $sundayOptions = $this->buildSundayOptions(); + if (!in_array($row['week_start'], $sundayOptions, true)) { + array_unshift($sundayOptions, $row['week_start']); + } + return view('teacher/class_progress_submit', [ 'subjectSections' => self::SUBJECT_SECTIONS, 'subjectCurriculum' => $subjectCurriculum, 'classSectionId' => $row['class_section_id'], 'classSectionName' => $classSectionName, 'classId' => $classId, - 'sundayOptions' => [$row['week_start']], + 'sundayOptions' => $sundayOptions, 'defaultWeekStart' => $row['week_start'], 'existingWeekEnd' => $row['week_end'], 'existingReports' => $subjectReports, @@ -458,6 +463,32 @@ class ClassProgressController extends BaseController return redirect()->back()->withInput()->with('error', 'No class assignment found for this report.'); } + $confirmOverwrite = (bool) $this->request->getPost('confirm_overwrite'); + if ($weekStart && $weekStart !== (string) ($row['week_start'] ?? '')) { + $conflicts = $this->reportModel + ->select('id') + ->where('class_section_id', $classSectionId) + ->where('week_start', $weekStart) + ->where('teacher_id', $teacherId) + ->findAll(); + if (! $confirmOverwrite && ! empty($conflicts)) { + return redirect()->back() + ->withInput() + ->with('warning', 'A progress report already exists for this week, are you sure you want to override it?') + ->with('confirm_overwrite', true); + } + if ($confirmOverwrite && ! empty($conflicts)) { + $conflictIds = array_values(array_filter(array_map( + static fn (array $row): int => (int) ($row['id'] ?? 0), + $conflicts + ))); + if (! empty($conflictIds)) { + $this->attachmentModel->whereIn('report_id', $conflictIds)->delete(); + $this->reportModel->whereIn('id', $conflictIds)->delete(); + } + } + } + $weeklyReports = $this->reportModel ->select('class_progress_reports.*') ->whereIn('teacher_id', $allowedTeacherIds) diff --git a/app/Controllers/View/ScoreController.php b/app/Controllers/View/ScoreController.php index ff24070..13950e2 100644 --- a/app/Controllers/View/ScoreController.php +++ b/app/Controllers/View/ScoreController.php @@ -1287,14 +1287,14 @@ class ScoreController extends Controller public function viewStudentScore() { $parentId = session()->get('user_id'); - $userType = $_SESSION['user_type']; + $userType = session()->get('user_type') ?? ''; $firstParentId = null; $releaseFall = $this->getParentScoresReleasedForSemester('Fall'); $releaseSpring = $this->getParentScoresReleasedForSemester('Spring'); $releaseAny = $releaseFall || $releaseSpring; // Identify the firstparent based on user type - if ($userType === 'primary') { + if ($userType === 'primary' || $userType === '') { $firstParentId = $parentId; } elseif ($userType === 'secondary') { $parentData = $this->db->table('parents') diff --git a/app/Views/teacher/class_progress_submit.php b/app/Views/teacher/class_progress_submit.php index 510dab9..fbecb19 100644 --- a/app/Views/teacher/class_progress_submit.php +++ b/app/Views/teacher/class_progress_submit.php @@ -77,39 +77,25 @@
Date Selection - -
- format('M d, Y'); - } catch (\Exception $e) { - $displayStart = $weekStartSelected; - } - ?> - Week of -
- - -
- -
Week start is required.
-
- +
+ +
Week start is 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) { diff --git a/app/Views/teacher/scores.php b/app/Views/teacher/scores.php index d36cfb3..b4a62a0 100644 --- a/app/Views/teacher/scores.php +++ b/app/Views/teacher/scores.php @@ -308,6 +308,7 @@ id="submitScoresLockBtn" formaction="" formmethod="post" + data-confirm-message="Once you submit, you cannot add any scores or comments. Do you want to continue?" > @@ -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();