fix score submission, and class progress
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user