get('role'); if (is_array($rawRole)) { $rawRole = $rawRole[0] ?? 'guest'; } $role = strtolower((string)($rawRole ?? 'guest')); // Set dashboard path based on role switch ($role) { case 'parent': $dashboard = base_url('/parent_dashboard'); break; case 'teacher': $dashboard = base_url('/teacher_dashboard'); break; case 'teacher_assistant': $dashboard = base_url('/teacher_dashboard'); break; case 'student': $dashboard = base_url('/landing_page/student_dashboard'); break; case 'guest': $dashboard = base_url('/landing_page/guest_dashboard'); break; default: $dashboard = base_url('/login'); break; } ?> get('user_name') ?? '')); $userEmail = trim((string) (session()->get('user_email') ?? '')); $initials = 'U'; if ($userName !== '') { $parts = preg_split('/\s+/', $userName); $first = $parts[0] ?? ''; $last = count($parts) > 1 ? end($parts) : ''; $initials = strtoupper(substr($first, 0, 1) . ($last !== '' ? substr($last, 0, 1) : '')); } elseif ($userEmail !== '') { $initials = strtoupper(substr($userEmail, 0, 1)); } // Score card picker (parent/teacher only) $scoreCardStudents = []; $scoreCardEnabledRole = in_array($role, ['parent', 'parent_dashboard', 'teacher', 'teacher_assistant', 'teacher_dashboard'], true); if ($scoreCardEnabledRole) { try { $studentModel = new \App\Models\StudentModel(); if (in_array($role, ['parent', 'parent_dashboard'], true)) { $parentId = (int)(session()->get('user_id') ?? 0); if ($parentId > 0) { $scoreCardStudents = $studentModel ->select('id, school_id, firstname, lastname') ->where('parent_id', $parentId) ->orderBy('lastname', 'ASC') ->orderBy('firstname', 'ASC') ->findAll(); } } else { $configModel = new \App\Models\ConfigurationModel(); $schoolYear = session()->get('school_year') ?? $configModel->getConfig('school_year'); $classSectionId = (int)($class_section_id ?? session()->get('class_section_id') ?? 0); if ($classSectionId > 0 && !empty($schoolYear)) { $scoreCardStudents = $studentModel->getByClassAndYear($classSectionId, $schoolYear); } if (empty($scoreCardStudents)) { $userId = (int)(session()->get('user_id') ?? 0); if ($userId > 0 && !empty($schoolYear)) { $db = \Config\Database::connect(); $sectionRows = $db->table('teacher_class') ->select('class_section_id') ->where('teacher_id', $userId) ->where('school_year', (string)$schoolYear) ->get() ->getResultArray(); $sectionIds = array_values(array_filter(array_unique(array_map( static fn($r) => (int)($r['class_section_id'] ?? 0), $sectionRows )), static fn($v) => $v > 0)); if (!empty($sectionIds)) { $studentClassModel = new \App\Models\StudentClassModel(); $rows = $studentClassModel->getStudentsByClassSectionIds($sectionIds); $unique = []; foreach ($rows as $r) { $sid = (int)($r['student_id'] ?? 0); if ($sid > 0) { $unique[$sid] = [ 'id' => $sid, 'school_id' => $r['school_id'] ?? '', 'firstname' => $r['firstname'] ?? '', 'lastname' => $r['lastname'] ?? '', ]; } } $scoreCardStudents = array_values($unique); } } } } } catch (\Throwable $e) { $scoreCardStudents = []; } } ?> get('menu_color') ?? ($styleCfg->defaultMenu ?? 'white'); if ($menuKeyLP === 'custom') { $menuMode = (string)($sess->get('menu_custom_mode') ?? 'auto'); $menuBg = (string)($sess->get('menu_custom_bg') ?? '#0f172a'); $resolveMenuMode = function (string $mode, string $bg): string { $mode = strtolower(trim($mode)); if ($mode === 'light' || $mode === 'dark') return $mode; $hex = ltrim(trim($bg), '#'); if (strlen($hex) === 3) { $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; } if (strlen($hex) !== 6) return 'dark'; $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); $lum = (0.2126 * $r + 0.7152 * $g + 0.0722 * $b) / 255.0; return ($lum < 0.5) ? 'dark' : 'light'; }; $menuModeEffective = $resolveMenuMode($menuMode, $menuBg); $navModeCls = ($menuModeEffective === 'dark') ? 'navbar-dark' : 'navbar-light'; } else { $menuLP = $styleCfg->menuPalettes[$menuKeyLP] ?? ($styleCfg->menuPalettes[$styleCfg->defaultMenu] ?? ['mode' => 'light']); $navModeCls = (isset($menuLP['mode']) && $menuLP['mode'] === 'dark') ? 'navbar-dark' : 'navbar-light'; } // Provide active event count for parent role if not already injected by the controller if (!isset($activeEventCount) && ($role ?? '') === 'parent') { $configModel = new \App\Models\ConfigurationModel(); $eventModel = new \App\Models\EventModel(); $year = $sess->get('school_year') ?? $configModel->getConfig('school_year'); $semester = $sess->get('semester') ?? $configModel->getConfig('semester'); $activeEventCount = count($eventModel->getActiveEvents($year, $semester) ?? []); } ?>