fix issues on examdraft view and event print page

This commit is contained in:
root
2026-05-05 01:38:20 -04:00
parent 45d7895182
commit 92016f90d0
4 changed files with 412 additions and 45 deletions
+53
View File
@@ -224,6 +224,10 @@ class FilesController extends Controller
throw PageNotFoundException::forPageNotFound();
}
if (!$this->canAccessExamDraftFile($name, $subdir)) {
return $this->response->setStatusCode(403, 'You are not allowed to access this file.');
}
$mime = 'application/octet-stream';
if (function_exists('finfo_open')) {
$fi = finfo_open(FILEINFO_MIME_TYPE);
@@ -317,4 +321,53 @@ class FilesController extends Controller
}
return 'teacher_file';
}
private function canAccessExamDraftFile(string $filename, string $subdir): bool
{
$userId = (int) (session()->get('user_id') ?? 0);
if ($userId <= 0) {
return false;
}
$role = strtolower((string) (session()->get('role') ?? ''));
if ($role === 'admin') {
return true;
}
$db = Database::connect();
$fileColumn = $subdir === 'finals' ? 'final_file' : $this->resolveExamDraftFileColumn($db);
$draft = $db->table('exam_drafts ed')
->select('ed.class_section_id, ed.school_year, ed.teacher_id, ed.author_id')
->where('ed.' . $fileColumn, $filename)
->limit(1)
->get()
->getRowArray();
if (empty($draft)) {
return false;
}
$authorId = (int) ($draft['teacher_id'] ?? $draft['author_id'] ?? 0);
if ($authorId > 0 && $authorId === $userId) {
return true;
}
$classSectionId = (int) ($draft['class_section_id'] ?? 0);
if ($classSectionId <= 0) {
return false;
}
$assignmentQuery = $db->table('teacher_class')
->select('id')
->where('teacher_id', $userId)
->where('class_section_id', $classSectionId);
$schoolYear = trim((string) ($draft['school_year'] ?? ''));
if ($schoolYear !== '') {
$assignmentQuery->where('school_year', $schoolYear);
}
return $assignmentQuery->limit(1)->countAllResults() > 0;
}
}