ensureAuthOrRedirect(static::REQUIRE_AUTH, static::REQUIRE_AUTHZ, static::REQUIRE_ROLE, static::REQUIRE_PERM); parent::afterConfig(); } /** @return string|array */ protected function MENU() { return static::MENU; } const MENU = "menu"; protected function MENU_SELECT(): ?string { return static::MENU_SELECT; } const MENU_SELECT = null; const MENU_LOGOUT = true; const MENU_SULOGIN = true; protected function getAuthzNbtext(IAuthzUser $user): array { $username = $user->getUsername(); $role = $user->getRole(); $profile = config::get_profile(); return nb::text([ "Connecté en tant que ", v::b($username), v::if($role !== null, [" avec le rôle ", v::b($role)]), " dans le profil ", v::b($profile), ]); } protected function getLoginNblink(): array { return nb::link($this->getLoginUrl(), icon::login("Se connecter"), [ "class" => "login", "accesskey" => "r", ]); } protected function getLogoutNblink(): array { return nb::link($this->getLogoutUrl(), icon::logout("Se déconnecter"), [ "class" => "logout", "accesskey" => "z", ]); } protected function printSuloginMenu(): void { $am = authz::manager(); if ($this->SULOGIN_ALLOWED() && ($am->isSulogin() || authz::get()->isPerm("sulogin"))) { navbar::nav(["align" => "right"]); fo::start([ "type" => "navbar", "method" => "post", "action" => $this->getMainUrl(), "class" => "navbar-form", ]); fo::text("!Chuser ", "su!", null, [ "style" => "width: 5rem; padding: 6px;", "accesskey" => "x", ]); fo::end(); navbar::endnav(); } } protected function printLogoutMenu(): void { if (authz::is_auth()) { $user = authz::get(); navbar::nav(["align" => "right"], [ nb::menu(icon::user($user->getShortName()), [ $this->getAuthzNbtext($user), $this->getLogoutNblink(), ]), ]); } } function beforePrintNavigation(): void { $menu = $this->MENU(); if ($menu !== null && !is_array($menu)) $menu = config::k($menu); if ($menu) { $selectedId = $this->MENU_SELECT(); if ($selectedId === null) $selectedId = static::class; $mm = navbar::menu_manager(); $mm->init($menu, $selectedId); ["brand" => $brand, "navbar_items" => $navbarItems, ] = $mm->get(); if ($brand) navbar::brand($brand); if ($navbarItems) navbar::nav(null, $navbarItems); } } function afterPrintNavigation(): void { if (static::MENU_LOGOUT) $this->printLogoutMenu(); if (static::MENU_SULOGIN) $this->printSuloginMenu(); } }