Files
server-manager/views/layouts/main.php

186 lines
9.2 KiB
PHP
Executable File

<?php
$notifications = $notifications ?? [];
$unreadCount = $unreadCount ?? 0;
$teamId = $teamId ?? null;
$title = $title ?? 'ServerManager';
$content = $content ?? '';
$currentRoute = $_SERVER['REQUEST_URI'] ?? '/';
if (!isset($user) || $user === null) {
$user = auth();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($title) ?> — ServerManager</title>
<meta name="api-token" content="<?= htmlspecialchars($user['api_token'] ?? '') ?>">
<meta name="csrf-token" content="<?= $this->csrfToken() ?>">
<link rel="stylesheet" href="/assets/css/style.css?v=<?= asset_version() ?>">
<link rel="icon" type="image/svg+xml" href="/assets/img/server.svg">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:opsz,wght@14..32,400;14..32,500;14..32,600;14..32,700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<div class="app-layout">
<!-- Sidebar -->
<aside class="sidebar" id="sidebar">
<div class="sidebar-header">
<a href="/dashboard" class="sidebar-brand">
<i class="fas fa-cubes"></i>
<span>ServerManager</span>
</a>
</div>
<nav class="sidebar-nav">
<!-- Dashboard -->
<a href="/dashboard" class="nav-item <?= str_starts_with($currentRoute, '/dashboard') ? 'active' : '' ?>">
<i class="fas fa-chart-pie"></i>
<span>Dashboard</span>
</a>
<!-- Notifications -->
<a href="/notifications" class="nav-item <?= str_starts_with($currentRoute, '/notifications') ? 'active' : '' ?>">
<i class="fas fa-bell"></i>
<span>Notifications</span>
</a>
<!-- Servers -->
<div class="nav-item-accordion <?= str_starts_with($currentRoute, '/servers') || str_starts_with($currentRoute, '/terminal') ? 'expanded' : '' ?>">
<a href="#" class="nav-item nav-item-toggle <?= str_starts_with($currentRoute, '/servers') ? 'active' : '' ?>" onclick="toggleServerList(event)">
<i class="fas fa-server"></i>
<span>Servers</span>
<i class="fas fa-chevron-right nav-chevron"></i>
</a>
<div class="nav-sublist" id="serverList" style="<?= str_starts_with($currentRoute, '/servers') || str_starts_with($currentRoute, '/terminal') ? '' : '' ?>">
<a href="/servers" class="nav-sub-item"><i class="fas fa-list"></i> All Servers</a>
</div>
</div>
<!-- Administration -->
<?php if (is_super_admin()): ?>
<hr class="nav-divider">
<div class="nav-section">Administration</div>
<a href="/admin" class="nav-item <?= str_starts_with($currentRoute, '/admin') ? 'active' : '' ?>">
<i class="fas fa-cog"></i>
<span>Administration</span>
</a>
<?php elseif (is_admin()): ?>
<hr class="nav-divider">
<div class="nav-section">Administration</div>
<a href="/teams" class="nav-item <?= str_starts_with($currentRoute, '/teams') ? 'active' : '' ?>">
<i class="fas fa-users-cog"></i>
<span>Teams</span>
</a>
<?php endif; ?>
<!-- Mobile -->
<hr class="nav-divider">
<div class="nav-section">Mobile</div>
<a href="/sysadmin.apk" class="nav-item" download>
<i class="fas fa-download"></i>
<span>Download APK</span>
</a>
</nav>
</aside>
<!-- Main Content -->
<div class="main-area">
<!-- Topbar -->
<header class="topbar">
<div class="topbar-left">
<button class="btn btn-icon" id="sidebarToggle" onclick="document.getElementById('sidebar').classList.toggle('collapsed')">
<i class="fas fa-bars"></i>
</button>
</div>
<div class="topbar-right">
<div class="notification-btn-wrapper">
<button class="btn btn-icon notification-btn" onclick="toggleNotifications()" title="Notifications">
<i class="fas fa-bell"></i>
<span class="notification-badge" id="notificationBadge" style="display:<?= $unreadCount > 0 ? 'inline-flex' : 'none' ?>">
<?= $unreadCount > 99 ? '99+' : $unreadCount ?>
</span>
</button>
<div class="notification-dropdown" id="notifDropdown">
<div class="notif-header">
<h3>Notifications</h3>
<button class="btn btn-text btn-sm" id="markAllReadBtn" onclick="markAllRead()"
style="display:<?= $unreadCount > 0 ? 'inline-flex' : 'none' ?>">
<i class="fas fa-check-double"></i> Mark all read
</button>
</div>
<div class="notif-list" id="notifList">
<div style="padding:40px 20px;text-align:center;color:var(--text-muted)">
<i class="fas fa-spinner fa-spin" style="font-size:1.5em;margin-bottom:10px;display:block"></i>
<span>Loading notifications...</span>
</div>
</div>
</div>
</div>
<div class="dropdown topbar-user-dropdown">
<button class="topbar-user" onclick="toggleUserMenu(event)">
<i class="fas fa-user-circle"></i>
<?= htmlspecialchars($user['username'] ?? 'Guest') ?>
<i class="fas fa-chevron-down" style="font-size:0.7rem;margin-left:4px"></i>
</button>
<div class="dropdown-menu dropdown-menu-right" id="userMenu">
<div class="dropdown-header">
<strong><?= htmlspecialchars($user['username'] ?? 'Guest') ?></strong>
<small><?= htmlspecialchars(ucfirst(str_replace('_', ' ', $user['role'] ?? 'guest'))) ?></small>
</div>
<div class="dropdown-divider"></div>
<a href="/profile" class="dropdown-item"><i class="fas fa-user-cog"></i> My Account</a>
<div class="dropdown-divider"></div>
<form method="POST" action="/logout" style="padding:0;margin:0">
<input type="hidden" name="_csrf_token" value="<?= $this->csrfToken() ?>">
<button type="submit" class="dropdown-item" style="width:100%;text-align:left;border:none;background:none;cursor:pointer;font:inherit">
<i class="fas fa-sign-out-alt"></i> Log out
</button>
</form>
</div>
</div>
</div>
</header>
<!-- Page Content -->
<main class="page-content">
<div class="container">
<?php if (isset($_SESSION['_flash'])): ?>
<?php foreach ($_SESSION['_flash'] as $type => $messages): ?>
<?php foreach ($messages as $msg): ?>
<div class="alert alert-<?= $type === 'error' ? 'danger' : $type ?>">
<i class="fas fa-<?= $type === 'success' ? 'check-circle' : ($type === 'error' ? 'exclamation-circle' : 'info-circle') ?>"></i>
<?= htmlspecialchars($msg) ?>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php unset($_SESSION['_flash']); ?>
<?php endif; ?>
<?= $content ?? '' ?>
</div>
</main>
</div>
</div>
<div id="toastContainer" class="toast-container"></div>
<script src="/assets/js/app.js?v=<?= asset_version() ?>"></script>
<?php if (isset($scripts)): ?>
<?php foreach ($scripts as $script): ?>
<script src="<?= htmlspecialchars($script) ?>"></script>
<?php endforeach; ?>
<?php endif; ?>
<script src="/assets/js/main.js?v=<?= asset_version() ?>"></script>
</body>
</html>