<?php session_start();
$url = $_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_FILENAME'];
if(!isMobile()) {
if(strpos($url, "setup.php")!==false) {
	echo '<table id="nav"><tbody><tr><td><a href="view.php"><img src="img/opolytics-beta.png" alt="Opolytics Logo"></a></td><td><span>Neuer Nutzer - <a href="view.php" title="Übersicht/Dashboard">Übersicht/Dashboard</a> - <a href="settings.php" title="Einstellungen">Einstellungen</a> - <a href="view.php?action=logout&csrf='.$_SESSION['csrf'].'" title="Logout">Logout</a></span></td></tr></tbody></table>';
}
/*if(strpos($url, "login.php")!==false) {
	echo '<table id="nav"><tbody><tr><td><a href="view.php"><img src="img/opolytics-beta.png" alt="Opolytics Logo"></a></td><td><span>Nicht angemeldeter Nutzer - <a href="view.php" title="Übersicht/Dashboard">Übersicht/Dashboard</a> - <a href="settings.php" title="Einstellungen">Einstellungen</a> - <a href="view.php?action=logout&csrf='.$_SESSION['csrf'].'" title="Logout">Logout</a></span></td></tr></tbody></table>';
}*/
if(strpos($url, "shared/")!==false) {
	echo '<script>blocked = "Funktion in diesem Bereich blockiert.";</script><table id="nav"><tbody><tr><td><img src="../img/opolytics-beta.png" alt="Opolytics Logo" id="opolytics_logo"><span id="search_field"></span></td><td><span>'.$_SESSION['user'].' - <a href="javascript:alert(blocked);" class="act_site" title="Übersicht/Dashboard">Übersicht/Dashboard</a> - <a href="javascript:alert(blocked);" title="Einstellungen">Einstellungen</a> - <a href="javascript:alert(blocked);" title="Logout">Logout</a></span></td></tr></tbody></table>';
}
if(strpos($url, "opb/")!==false) {
	echo '<table id="nav"><tbody><tr><td><a href="../view.php"><img src="../img/opolytics-beta.png" alt="Opolytics Logo"></a></td><td><span>'.$_SESSION['user'].' - <a href="../view.php" title="Übersicht/Dashboard">Übersicht/Dashboard</a> - <a href="../settings.php" title="Einstellungen">Einstellungen</a> - <a href="../view.php?action=logout&csrf='.$_SESSION['csrf'].'" title="Logout">Logout</a></span></td></tr></tbody></table>';
}
else {
	echo '<table id="nav"><tbody><tr><td><a href="view.php"><img src="img/opolytics-beta.png" alt="Opolytics Logo"></a></td><td><span>'.$_SESSION['user'].' (<span id="timeuntilinactivity"></span>) - <a href="view.php" title="Übersicht/Dashboard" '.(strpos($url, "view.php")!==false ? 'class="act_site"' : '').'>Übersicht/Dashboard</a> - <a href="settings.php" '.(strpos($url, "settings.php")!==false ? 'class="act_site"' : '').' title="Einstellungen">Einstellungen</a> - <a href="view.php?action=logout&csrf='.$_SESSION['csrf'].'" title="Logout">Logout</a></span></td></tr></tbody></table>';
}
if(strpos($url, "view.php")!==false) {
echo '<nav class="sidebar"><b>Sidebar</b>
<details><summary>Regelmässige Statistiken</summary><span><a href="detail.php?view=live">Live</a><br><a href="detail.php?view=tag&day='.date("d.m.Y",time()).'">Heutige Tagesstatistik</a><br><a href="detail.php?view=tag">Tages-Einzelansichten</a><br><a href="detail.php?view=woche&start='.getMonday(date("d.m.Y",time())).'&end='.getSunday(date("d.m.Y",time())).'">Aktuelle Wochenstatistik</a><br><a href="detail.php?view=woche">Wochenstatistiken</a></span></details>
<details><summary>Suchen/Verweise/Herkünfte</summary><span><a href="detail.php?view=herkuenfte">Verweise auf Ihre Seite</a><br><a href="detail.php?view=suchmaschinen">Suchmaschinenanalyse</a><br><a href="detail.php?view=interne_suchen">Intern oft gesucht</a></span></details>
<details><summary>Ihre Seite in Zahlen</summary><span><a href="detail.php?view=nutzerzahlen">Nutzerzahlen</a><br><a href="detail.php?view=beliebt">Beliebte Seiten</a><br><a href="detail.php?view=sprachen">Sprachen</a><br><a href="detail.php?view=aktionen">Aktionen</a><br><a href="detail.php?view=karte">Benutzerkarte</a><br><a href="detail.php?view=ecommerce">E-Commerce</a></span></details>
<details><summary>Mehr</summary><span><a href="detail.php?view=nutzerlog">Nutzerlog/Logbuch</a><br><a href="detail.php?view=kampagnen+ziele"><span style="color:green">NEU:</span> Kampagnen & Ziele</a><br><a href="detail.php?view=optimizer">Optimierer</a><br></span></details></nav>';
if(!isset($_COOKIE["views"])) {
	echo '<p>Willkommen zurück bei Opolytics '.$_SESSION["user"].'!</p><script>document.cookie = "views=1";</script>';
}
}
}
else {
echo '<table id="nav"><tbody><tr><td width="80%"><a href="view.php"><img src="img/opolytics-beta.png" alt="Opolytics Logo"></a></td><td width="20%"><input type="button" value="Menu" onclick="showmenu()" id="menushower"></td></tr></tbody></table>
<div id="dropdownmenu">'.$_SESSION['user'].'<hr><a href="view.php">Übersicht/Dashboard</a><br><details><summary>Detailansichten</summary><span><a href="detail.php?view=nutzerzahlen">Nutzerzahlen</a><br>
<a href="detail.php?view=live">Live</a><br>
<a href="detail.php?view=tag">Tagesstatistiken</a><br>
<a href="detail.php?view=tag&day='.date("d.m.Y",time()).'">Heutige Tagesstatistik</a><br>
<a href="detail.php?view=woche">Wochenstatistiken</a><br>
<a href="detail.php?view=woche&start='.getMonday(date("d.m.Y",time())).'&end='.getSunday(date("d.m.Y",time())).'">Aktuelle Wochenstatistik</a><br>
<a href="detail.php?view=herkuenfte">Verweise auf Ihre Seite</a><br>
<a href="detail.php?view=suchmaschinen">Suchmaschinenanalyse</a><br>
<a href="detail.php?view=interne_suchen">Interne Suche</a><br>
<a href="detail.php?view=beliebt">Beliebte Seiten</a><br>
<a href="detail.php?view=sprachen">Sprachen</a><br>
<a href="detail.php?view=aktionen">Aktionen</a><br>
<a href="detail.php?view=nutzerlog">Logbuch</a><br>
<a href="detail.php?view=kampagnen+ziele">Kampagnen & Ziele</a><br>
<a href="detail.php?view=optimizer">Optimierer</a><br></span></details>
<a href="settings.php">Einstellungen</a><br><a href="view.php?action=logout&csrf='.$_SESSION['csrf'].'">Logout</a></div>
<script>
function showmenu() {
document.getElementById("menushower").onclick = function() {hidemenu()};
document.getElementById("dropdownmenu").style.display = "block";
}
function hidemenu() {
document.getElementById("menushower").onclick = function() {showmenu()};
document.getElementById("dropdownmenu").style.display = "none";
}
</script>
<style>
#nav {
position: fixed !important;
top:0px !important;
}
#nav td img{
height:50px;
} 
body {
margin-left:0px;
}
#dropdownmenu {
display:none;
background-color: rgba(0,0,0,0.9);
color:white;
border-radius:20px;
padding:20px;
}
#dropdownmenu a{
color:white;
}
</style>';
}
if(strpos($url,'view.php')!==false OR strpos($url,'detail.php')!==false AND $_GET['view']!='live') {
	echo '<p style="text-align:center">Angezeigte Seite: <select id="shown_site"><optgroup label="Hauptseite"><option name="main" '.(($_SESSION['site']=='main' OR !isset($_SESSION['site'])) ? 'selected' : '').'>Hauptseite</option></optgroup><optgroup label="Alle"><option name="all" '.($_SESSION['site']=='all' ? 'selected' : '').'>Alle</option></optgroup><optgroup label="Weitere">';
	foreach(array_slice(scandir('log'),2) AS $site) {
		$site = substr($site,0,-4);
		echo '<option name="'.$site.'" '.($_SESSION['site']==$site ? 'selected' : '').'>'.$site.'</option>';
	}
	echo '</optgroup></select> - <span id="site_change_state">Geladen</span> - <a href="settings.php?show=sites">Einstellungen</a></p>';
}
?><script src="js/functions.js" id="functions.js"></script><script src="js/common.js"></script>