78 lines
3.2 KiB
PHP
78 lines
3.2 KiB
PHP
<?php
|
|
|
|
|
|
function html_head(string $title): void {
|
|
$domain = cfg('domain', 'copymail');
|
|
echo <<<HTML
|
|
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{$title} — CopyMail</title>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css">
|
|
<link rel="stylesheet" href="/assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
HTML;
|
|
}
|
|
|
|
function html_navbar(string $active = ''): void {
|
|
$user = current_user();
|
|
$isAdmin = is_admin();
|
|
|
|
$pages = [
|
|
'mail' => ['/', 'bi-envelope-fill', 'Courriers'],
|
|
];
|
|
if ($isAdmin) {
|
|
$pages['accounts'] = ['/admin/accounts.php', 'bi-people-fill', 'Comptes'];
|
|
$pages['domain'] = ['/admin/domain.php', 'bi-gear-fill', 'Configuration'];
|
|
$pages['status'] = ['/admin/index.php', 'bi-activity', 'Tableau de bord'];
|
|
$pages['users'] = ['/admin/users.php', 'bi-person-lock', 'Utilisateurs'];
|
|
}
|
|
|
|
$roleBadge = $isAdmin
|
|
? '<span class="badge bg-warning text-dark me-2">admin</span>'
|
|
: '<span class="badge bg-secondary me-2">user</span>';
|
|
|
|
echo '<nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-4">';
|
|
echo '<div class="container-fluid">';
|
|
echo '<a class="navbar-brand fw-bold" href="/"><i class="bi bi-envelope-arrow-down-fill me-2"></i>CopyMail</a>';
|
|
echo '<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#nav"><span class="navbar-toggler-icon"></span></button>';
|
|
echo '<div class="collapse navbar-collapse" id="nav"><ul class="navbar-nav me-auto">';
|
|
foreach ($pages as $key => [$href, $icon, $label]) {
|
|
$cls = $key === $active ? 'nav-link active' : 'nav-link';
|
|
echo "<li class=\"nav-item\"><a class=\"{$cls}\" href=\"{$href}\"><i class=\"bi {$icon} me-1\"></i>{$label}</a></li>";
|
|
}
|
|
echo '</ul>';
|
|
echo '<div class="d-flex align-items-center gap-2">';
|
|
echo "{$roleBadge}<span class=\"navbar-text me-2\"><i class=\"bi bi-person-circle me-1\"></i>{$user}</span>";
|
|
echo '<a class="btn btn-outline-light btn-sm" href="/logout.php"><i class="bi bi-box-arrow-right me-1"></i>Déconnexion</a>';
|
|
echo '</div></div></div></nav>';
|
|
}
|
|
|
|
function html_foot(): void {
|
|
echo <<<HTML
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="/assets/js/app.js"></script>
|
|
</body>
|
|
</html>
|
|
HTML;
|
|
}
|
|
|
|
function flash(string $type, string $msg): void {
|
|
$_SESSION['flash'] = ['type' => $type, 'msg' => $msg];
|
|
}
|
|
|
|
function flash_render(): void {
|
|
if (!empty($_SESSION['flash'])) {
|
|
$f = $_SESSION['flash'];
|
|
unset($_SESSION['flash']);
|
|
$icon = $f['type'] === 'success' ? 'check-circle-fill' : 'exclamation-triangle-fill';
|
|
echo "<div class=\"alert alert-{$f['type']} d-flex align-items-center alert-dismissible fade show\" role=\"alert\">";
|
|
echo "<i class=\"bi bi-{$icon} me-2\"></i>{$f['msg']}";
|
|
echo '<button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>';
|
|
}
|
|
}
|