<!DOCTYPE html>
<html lang="de">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Ihre Webseite</title>
	<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
	<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<?php
// Ensure $user is available without changing authentication behavior elsewhere
if (!isset($user)) {
	if (isset($_SESSION['userid']) && isset($pdo)) {
		$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
		$stmt->execute([$_SESSION['userid']]);
		$user = $stmt->fetch();
	} else {
		// Minimal default to avoid notices when not logged in
		$user = ['admin' => 0, 'zeiterfassung' => 0];
	}
}
?>

	<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
		<a class="navbar-brand" href="#">Zeiterfassung</a>
		<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
			<span class="navbar-toggler-icon"></span>
		</button>
		<div class="collapse navbar-collapse" id="navbarNav">
			<ul class="navbar-nav mr-auto">
				<li class="nav-item active">
					<a class="nav-link" href="index.php">Startseite</a>
				</li>

				<li class="nav-item">
					<a class="nav-link" href="ZeitenAnzeige.php">Zeitübersicht</a>
				</li>

				<li class="nav-item">
					<a class="nav-link" href="fehlbuchungen.php">Fehlbuchungen</a>
				</li>

				<!-- Urlaub Dropdown -->
				<li class="nav-item dropdown">
					<a class="nav-link dropdown-toggle" href="#" id="urlaubDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
						Urlaub
					</a>
					<div class="dropdown-menu" aria-labelledby="urlaubDropdown">
						<a class="dropdown-item" href="urlaubsantrag.php">Urlaubsantrag</a>
						<a class="dropdown-item" href="my_vacations_calendar.php">Mein Urlaubskalender</a>
						<a class="dropdown-item" href="vacations_calendar_all.php">Team Urlaubskalender</a>
						<?php if (is_admin_user()) : ?>
							<div class="dropdown-divider"></div>
							<a class="dropdown-item" href="vacations_overview.php">Urlaubsübersicht</a>					
							<a class="dropdown-item" href="approveVacation.php">Urlaubsanträge genehmigen</a>
							<a class="dropdown-item" href="company_holidays.php">Betriebsurlaub</a>
						<?php endif; ?>
					</div>
				</li>

				<!-- Verwaltung Dropdown (Admin only) -->
				<?php if (is_admin_user()) : ?>
				<li class="nav-item dropdown">
					<a class="nav-link dropdown-toggle" href="#" id="adminDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
						Verwaltung
					</a>
					<div class="dropdown-menu" aria-labelledby="adminDropdown">
						<a class="dropdown-item" href="alleZeitenanzeige.php">Alle Zeitbuchungen</a>
						<a class="dropdown-item" href="allefehlbuchungen.php">Alle Fehlbuchungen</a>
						<a class="dropdown-item" href="showworker.php">Mitarbeiterverwaltung</a>
					</div>
				</li>
				<?php endif; ?>
			</ul>

			<!-- optional right-side user area -->
			<ul class="navbar-nav">
				<?php if (isset($user['vorname'])): ?>
					<li class="nav-item"><span class="navbar-text text-light mr-3"><?php echo htmlspecialchars($user['vorname']); ?></span></li>
					<li class="nav-item"><a class="nav-link" href="logout.php">Abmelden</a></li>
				<?php else: ?>
					<li class="nav-item"><a class="nav-link" href="login.php">Anmelden</a></li>
				<?php endif; ?>
			</ul>
		</div>
	</nav>

<?php
// Enforce zeiterfassung permission if present on pages that expect it
if (isset($user['zeiterfassung']) && $user['zeiterfassung'] != 1) {
	die("Keine Rechte für die Zeiterfassung");
}