Files
yogibook_aury_new/public/include/schoolswitcher.php
T

46 lines
2.3 KiB
PHP

<?php
/**
* Selettore scuola in topbar.
* Visibile solo se l'utente ha accesso a più di una scuola.
* Include: <?php include('include/schoolswitcher.php'); ?>
*/
$__schools = SchoolContext::available();
if (count($__schools) > 1) :
if (empty($_SESSION['csrf_switch'])) {
$_SESSION['csrf_switch'] = bin2hex(random_bytes(16));
}
$__current = SchoolContext::get();
$__roleLabels = [
'owner' => 'Titolare',
'admin' => 'Admin',
'teacher' => 'Insegnante',
'student' => 'Allievo',
'superadmin' => 'Superadmin',
];
?>
<div class="dropdown d-inline-block">
<button type="button" class="btn header-item" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" title="Cambia scuola">
<i class="bx bx-buildings font-size-20 align-middle"></i>
<span class="d-none d-xl-inline-block ms-1 fw-semibold"><?php echo htmlspecialchars($__current['name'], ENT_QUOTES, 'UTF-8'); ?></span>
<i class="bx bx-chevron-down d-none d-xl-inline-block"></i>
</button>
<div class="dropdown-menu dropdown-menu-end" style="min-width: 260px;">
<h6 class="dropdown-header">Le tue scuole</h6>
<?php foreach ($__schools as $__s) :
$__isCurrent = ((int) $__s['idschool'] === (int) $__current['idschool']);
$__role = $__roleLabels[$__s['school_role']] ?? $__s['school_role'];
?>
<form method="post" action="switchschool.php" class="m-0">
<input type="hidden" name="idschool" value="<?php echo (int) $__s['idschool']; ?>">
<input type="hidden" name="token" value="<?php echo $_SESSION['csrf_switch']; ?>">
<button type="submit" class="dropdown-item d-flex justify-content-between align-items-center <?php echo $__isCurrent ? 'active' : ''; ?>" <?php echo $__isCurrent ? 'disabled' : ''; ?>>
<span><?php echo htmlspecialchars($__s['name'], ENT_QUOTES, 'UTF-8'); ?></span>
<span class="badge rounded-pill bg-light text-dark ms-2"><?php echo htmlspecialchars($__role, ENT_QUOTES, 'UTF-8'); ?></span>
</button>
</form>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>