diff --git a/app/Controllers/View/BadgesController.php b/app/Controllers/View/BadgesController.php index 8082a52..d0fb419 100644 --- a/app/Controllers/View/BadgesController.php +++ b/app/Controllers/View/BadgesController.php @@ -122,6 +122,10 @@ class BadgesController extends PrintablesBaseController $roleResolved = $postedRole !== null ? $postedRole : $resolveRole($info); $roleResolved = $formatRole((string)$roleResolved); $info['role_resolved'] = $roleResolved; + if ($postedRole !== null && trim((string)$postedRole) !== '') { + $info['roles_raw'] = $roleResolved; + $info['role_name_raw'] = $roleResolved; + } // Prefer posted class name if provided (keeps what the user saw) if (!empty($classesMap[$userId])) { diff --git a/app/Views/printables_reports/badge_form.php b/app/Views/printables_reports/badge_form.php index 884669a..6978c06 100644 --- a/app/Views/printables_reports/badge_form.php +++ b/app/Views/printables_reports/badge_form.php @@ -7,10 +7,17 @@ $formatRole = function (?string $role): string { $role = str_replace(['-', '_'], ' ', $role); $role = preg_replace('/\s+/', ' ', trim($role)); if ($role === '') return ''; + $special = [ + 'of' => 'of', + 'head' => 'Head', + ]; $out = []; foreach (explode(' ', $role) as $w) { if ($w === '') continue; - if (preg_match('/^[A-Za-z]{1,3}$/', $w)) { + $lower = strtolower($w); + if (isset($special[$lower])) { + $out[] = $special[$lower]; + } elseif (preg_match('/^[A-Za-z]{1,3}$/', $w)) { $out[] = strtoupper($w); // TA, PTA, HR, KG... } else { $out[] = ucfirst(strtolower($w)); // Teacher, Assistant, Admin... @@ -59,14 +66,23 @@ $formatRole = function (?string $role): string { - + + 1): ?> + + + + + @@ -235,11 +261,20 @@ $formatRole = function (?string $role): string { // Delegate checkbox change handling once at the table level (works across redraws) document.getElementById('staffTable').addEventListener('change', function (e) { const target = e.target; - if (!target || !target.classList.contains('user-checkbox')) return; + if (!target) return; const tr = target.closest('tr[data-user-id]'); const userId = tr ? tr.getAttribute('data-user-id') : null; if (!userId) return; - if (target.checked) selected.add(userId); else selected.delete(userId); + + if (target.classList.contains('role-select')) { + rowMeta[userId] = rowMeta[userId] || { role: '', className: '' }; + rowMeta[userId].role = target.value || ''; + } else if (target.classList.contains('user-checkbox')) { + if (target.checked) selected.add(userId); else selected.delete(userId); + } else { + return; + } + syncHiddenInputs(); syncPageCheckboxes(); // If user interacts, cancel any pending auto-clear to avoid wiping new selections @@ -341,4 +376,4 @@ $formatRole = function (?string $role): string { window.addEventListener('focus', fetchPrintStatus); }); -endSection() ?> \ No newline at end of file +endSection() ?>