<?php
include "../script/db.php";

session_start();

if(isset($_SESSION['id'])) {
	$req_user = $db->prepare("SELECT pseudo, perm FROM admin WHERE id = ?");
	$req_user->execute(array($_SESSION['id']));
	$user_exist = $req_user->rowcount();
	$user = $req_user->fetch();
} else {
	$user_exist = 0;
}

echo '<link rel="stylesheet" type="text/css" href="admin.css" />';

if($user_exist != 1) {
	if($page != "index") {
		header('Location: index.php');
	}
} else {
	$content = 
	 '<li class="green"><a href="index.php">Index</a></li>'
	.'<li class="green"><a href="stats.php">Stats</a></li>';

	switch ($user['perm']) {
    case 1:
		$content = $content.'<li class="orange"><a href="planning.php">Planning</a></li>';
        break;
    case 2:
        $content = $content
        .'<li class="orange"><a href="planning.php">Planning</a></li>'
        .'<li class="red"><a href="gestion_des_acces.php">Gestion des accès</a></li>'
        .'<li class="red"><a href="enigma.php">Enigma</a></li>'
		.'<li class="red"><a href="stats.php">Stats</a></li>'
		.'<li class="red"><a href="vacances.php">Vacances</a></li>';
        break;
	}

	$content = $content.'<li class="white"><a href="deco.php">Se déconnecter</a></li>';
}
?>

<nav>
	<ul>
		<?php
		if(isset($content)) {
			echo $content;
		} ?>
	</ul>
</nav>