<?php
	ini_set('date.timezone', 'Europe/Amsterdam');
	ini_set('session.cookie_httponly', 1);
	ini_set('session.use_only_cookies', 1);
	ini_set('session.cookie_secure', 1);

	require_once("autoload.php");

	if (!Config::isConfigured() || !Database::connected())
	{
		Session::destroy();
		if (!Config::isConfigured() || !Database::connected())
		{
			header("Location: https://".$_SERVER['HTTP_HOST']."/Config");
			exit;
		}
	}

	header("Content-Type: text/html; charset=utf-8");
	header("X-Frame-Options: SAMEORIGIN");

	$general_club_name = Settings::get("general_club_name");

	$user = UserAdmin::getLoggedInUser();
	$menu = Menu::getInstance();
	$location = $menu->GetTopMenuLocation();
	if (!isset($_REQUEST['locationparams']))
	{
		$_REQUEST['locationparams'] = "";
	}
	if (isset($_REQUEST['location']) && $_REQUEST['location'] != "")
	{
		$menu->ResolveLocation($_REQUEST['location'], $location, $_REQUEST['locationparams']);
	}
	$menuid = $menu->GetId($location);
	if (isset($_REQUEST["logout"]) || isset($_REQUEST["finalize"]))
	{
		Session::destroy();
		if ($_REQUEST['locationparams'] != "")
		{
			$location .= ":".$_REQUEST['locationparams'];
		}
		if (!isset($_REQUEST["finalize"]))
		{
			header("Location: https://".$_SERVER['HTTP_HOST']."/?finalize&location=".$location);
		}
		else
		{
			header("Location: https://".$_SERVER['HTTP_HOST']."/".$location);
		}
		exit;
	}
	if (!Session::isValid())
	{
		Session::destroy();
	}
	Session::prolong();

	if (!is_null($user) && isset($_REQUEST["phpinfo"]) && $user->getSiteAccesslevel() >= 255)
	{
		phpinfo();
		exit;
	}
	if (isset($_REQUEST["login"]))
	{
		if ($_REQUEST['locationparams'] != "")
		{
			$location .= ":".$_REQUEST['locationparams'];
		}
		$emailaddress = "";
		if (isset($_REQUEST["emailaddress"]))
		{
			$emailaddress = $_REQUEST["emailaddress"];
		}
		$useradmin = UserAdmin::getInstance();
		if ($useradmin->login($_REQUEST["username"], $_REQUEST["userpassword"], $emailaddress))
		{
			$menu->Init();
			header("Location: https://".$_SERVER['HTTP_HOST']."/".$location);
		}
		else
		{
			header("Location: https://".$_SERVER['HTTP_HOST']."/".$location."/Login");
		}
		exit;
	}
	header("Expires: ".date("D, d M Y H:i:s", strtotime('+7 days'))." GMT");
	setlocale(LC_ALL, 'nl_NL.UTF8');
	setlocale(LC_TIME, 'nl_NL');
	$_REQUEST['location'] = $location;
	$pagecontent = $general_club_name;
	$keywords = "tilburg, water, watervrienden, zwemles, drieburcht, reeshof, zwemmen";

	$title = "";
	$worker = null;
	$type = "";

	if (isset($_REQUEST['type']))
	{
		$type = $_REQUEST['type'];
		if ($type == "User")
		{
			$worker = User::getInstance();
		}
		else if ($type == "Menu")
		{
			$worker = Menu::getInstance();
		}
	}
	if (is_null($worker))
	{
		$type = $menu->GetClass($menuid);
		$worker = $menu->GetWorker($menuid);
	}
	if (!is_null($worker))
	{
		$title = $worker->GetTitle($menuid);
	}
	if ($title == "")
	{
		$title = $menu->GetTitle($menuid);
	}
	if ($title != "")
	{
		$title = " - ".$title;
	}
	if (is_null($worker) || empty($type))
	{
		$menuid = -1;
		$type = "";
	}
        $requiredlevel = $menu->GetRequiredLevel($menuid);
       	$currentAccessLevel = $menu->GetAccessLevel($menuid);
        if ($menuid == 0)
        {
                $requiredlevel = 10;
                $currentAccessLevel = $menu->GetAccessLevel($menu->GetId($menu->GetParentLocation($_REQUEST['location'])));
        }
	if ($menuid < 0)
	{
		http_response_code(404);
	}
	else if ($currentAccessLevel < $requiredlevel)
	{
		http_response_code(403);
	}

	if (!UserAdmin::isLoggedIn() && ($requiredlevel <= $currentAccessLevel) && $menuid > 0)
	{
		if ($menu->GetTooltip($menuid) != "")
		{
			$pagecontent = str_replace(array("\t", "\n", "\r", "  "), " ", $menu->GetTooltip($menuid));
		}
		if ($menu->GetKeywords($menuid) != "")
		{
			$keywords = $menu->GetKeywords($menuid);
		}
		else
		{
			ob_start();
			include($_SERVER['DOCUMENT_ROOT']."/view/".strtolower($type).".php");
			$page = ob_get_contents();
			ob_end_clean();
			$page = str_ireplace(array("\n", "\r", ".", ",", ":", "!", "(", ")", "<br>", "<br />", "@", "?", "-"), " ", $page);
			$page = $menu->html2txt($page);
			$keywords = explode(" ", $page);
			$keywords = array_unique($keywords);
			$keywordString = "";
			foreach ($keywords as $key => $keyword)
			{
				$keyword = trim($keyword);
				if ($keyword != '' && strlen($keyword) > 4 && !is_numeric($keyword))
				{
					if ($keywordString != "")
					{
						$keywordString .= ", ";
					}
					$keywordString .= $keyword;
				}
			}
			$menu->SetKeywords($menuid, $keywordString);
			$keywords = $keywordString;
		}
	}

	$general_email_address = Settings::get("general_email_address");
	if ($general_email_address == "")
	{
		$general_email_address = "info@".$_SERVER["HTTP_HOST"];
	}
?>
<!DOCTYPE html>
<html>
	<head>
		<title><?php echo($general_club_name.$title); ?></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
		<meta name="mobile-web-app-capable" content="yes">
		<link href="<?php echo(Util::getFileURLWithVersion('/css/print.css')); ?>" rel="stylesheet" type="text/css" media="print">
		<link href="<?php echo(Util::getFileURLWithVersion('/css/responsive.css')); ?>" rel="stylesheet" type="text/css" media="screen">
		<link rel="manifest" href="/manifest.json" crossorigin="use-credentials">
		<link href="/js/jquery-ui-1.13.2/jquery-ui.min.css" rel="stylesheet" type="text/css" media="screen">
		<link href="https://<?php echo($_SERVER['HTTP_HOST']); ?>/rss/" rel="alternate" type="application/rss+xml" title="RSS">
		<link rel="icon" type="image/png" sizes="32x32" href="/icon/favicon-32x32.png">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="language" content="NL">
		<meta name="robots" content="index,follow">
		<meta name="keywords" content="<?php echo($keywords); ?>">
		<meta name="description" content="<?php echo($pagecontent); ?>">
<?php
	if ($type == "Info")
	{
?>
		<script type="application/ld+json">
		{
		  "@context": "http://schema.org",
		  "@type": "Article",
		  "mainEntityOfPage": {
		    "@type": "WebPage",
		    "@id": "https://<?php echo($_SERVER['HTTP_HOST'].'/'.$_REQUEST['location']); ?>"
		  },
		  "headline": "<?php echo($worker->GetTitle($menuid)); ?>",
		  "image": [
		    "https://<?php echo($_SERVER['HTTP_HOST'].'/images/logo.png'); ?>"
		   ],
		  "datePublished": "<?php echo($menu->GetAddedOn($menuid)); ?>",
		  "dateModified": "<?php echo($menu->GetUpdatedOn($menuid)); ?>",
		  "author": {
		    "@type": "Person",
		    "name": "<?php echo($menu->GetUpdatedBy($menuid)); ?>"
		  },
		   "publisher": {
		    "@type": "Organization",
		    "name": "<?php echo($general_club_name); ?>",
		    "logo": {
		      "@type": "ImageObject",
		      "url": "https://<?php echo($_SERVER['HTTP_HOST'].'/images/logo.png'); ?>"
		    }
		  },
		  "description": "<?php echo($pagecontent); ?>"
		}
		</script>
<?php
	}
?>
		<script type="application/ld+json">
		{
		  "@context": "http://schema.org",
		  "@type": "Organization",
		  "url": "https://<?php echo($_SERVER["HTTP_HOST"]); ?>",
		  "contactPoint": [
		    {
			"@type": "ContactPoint",
<?php
	$general_phone_number = Settings::get("general_phone_number");
	if (!empty($general_phone_number))
	{
			if ($general_phone_number[0] == "0")
			{
				$general_phone_number[0] = "1";
				$general_phone_number = "+3".$general_phone_number;
			}
?>
			"telephone": "<?php echo(preg_replace('/[^0-9\+]/', '', $general_phone_number)); ?>",
<?php
	}
?>
			"email": "<?php echo($general_email_address); ?>",
			"contactType": "customer service"
		    }
		  ]
		}
		</script>
		<script src="/js/mustache.min.js"></script>
		<script src="/js/jquery-3.7.1.min.js"></script>
                <script src="/js/jquery-ui-1.13.2/jquery-ui.min.js"></script>
                <script src="/js/jquery.ui.widget.js"></script>
		<script src="/js/jquery.lazy.min.js"></script>
		<script src="<?php echo(Util::getFileURLWithVersion('/js/main.js')); ?>"></script>
		<script>
			var currentMenuId = <?php echo($menuid); ?>;
			function setFontSize(fontSize)
			{
				if (fontSize == 'A') {
					document.body.style.zoom = "100%";
				}
				else if (fontSize == 'B') {
					document.body.style.zoom = "120%";
				}
				else if (fontSize == 'C') {
					document.body.style.zoom = "140%";
				}
				setCookie('fontsize', fontSize, 1);
			}
			$(function() {
				var fontSize = getCookie("fontsize");
				setFontSize(fontSize);
			});
		</script>
<?php
	if (UserAdmin::isLoggedIn())
	{
?>
                <script src="/js/jquery.iframe-transport.js"></script>
                <script src="/js/jquery.fileupload.js"></script>

		<link rel="stylesheet" type="text/css" href="/js/imgareaselect/css/imgareaselect-default.css" />
		<script src="/js/imgareaselect/scripts/jquery.imgareaselect.js"></script>
		<link rel="stylesheet" href="/js/sceditor-3.2.0/development/themes/default.css" />
		<script src="/js/sceditor-3.2.0/minified/jquery.sceditor.min.js"></script>
		<script src="/js/sceditor-3.2.0/minified/formats/xhtml.js"></script>
		<script src="/js/sceditor-3.2.0/languages/nl.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvlink.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvimage.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvvideo.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvformat.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvtable.js"></script>
		<script src="/js/sceditor-3.2.0/development/plugins/twvinsert.js"></script>
		<script>
			isLoggedIn = true;
			var allowUpdateEditorText = true;
			handleSessionExpiration();
			window.addEventListener("beforeunload", beforeUnload);
			$(function() {
				$('.lazyload').Lazy();
			});
		</script>
<?php
	}
	$backgroundid = $menuid;
	while(intval($backgroundid) > 0)
	{
		if ($menu->GetBackground($backgroundid))
		{
			break;
		}
		$backgroundid = $menu->GetParentId($backgroundid);
	}
	if ($backgroundid == 0)
	{
		$backgroundid = $menu->GetTopMenuId();
	}
?>
	</head>
	<body>
		<div class="top" id="top"<?php if ($menu->GetBackground($backgroundid)) { ?> style="background-image: url(/images/backgrounds/<?php echo($backgroundid); ?>_background.png)" <?php } ?>>
			<a href="https://www.nrz-nl.nl/licentie-nationale-zwemdiplomas/zwemlesaanbieders-met-licentie/" target="_blank"><img id="licentie" src="/images/Licentiehouder-Nationale-zwemdiplomas.png" /></a>
			<a href="/<?php echo($menu->GetTopMenuLocation()); ?>">
 				<img id="logo" alt="Logo <?php echo($general_club_name); ?>" src="<?php echo(Util::getFileURLWithVersion('/images/logo.png')); ?>" <?php if ($menu->GetBackground($menu->GetTopMenuId())) { ?> onmouseover="ChangeBackground('<?php echo($menu->GetTopMenuId()); ?>'); return false;" <?php } ?>>
			</a>
		</div>
<?php
	if (!Util::isRunningOnProduction())
	{
?>
		<div style="background-color: red; padding-left: 1em; width: auto;"><br>Let op: Dit is een testomgeving!<br><br></div>
<?php
	}
	if (!is_null($user) && $user->getSiteAccesslevel() >= 255 && Util::isSiteDown())
	{
?>
		<div style="background-color: red; padding-left: 1em; max-width: 100%;"><br>Let op: De site is momenteel niet beschikbaar!<br><br></div>
<?php
	}
        $parentid = -1;
        $parentlocation = $location;
        while($parentid == -1 && $parentlocation != "")
        {
                $parentlocation = $menu->GetParentLocation($parentlocation);
                $parentid = $menu->GetId($parentlocation);
        }
	$searchlocation = Settings::get("search_location");
	$contactlocation = Settings::get("contact_location");
	$showuntil = $menu->GetShowUntil($menuid);
	if (Util::isSiteDown() && (is_null($user) || $user->getSiteAccesslevel() < 255))
	{
		$sitedowntext = Settings::get("site_down_text");
	        if (UserAdmin::isLoggedIn())
                {
?>
		<div>Aangemeld als: <?php echo($user->getRealname()); ?> | <a href="/index.php?logout">Afmelden</a></div>
<?php
                }
?>
		<div style="margin-left: 1em;">
<?php
		echo(nl2br($sitedowntext));
?>
		</div>
<?php
	}
	else
	{
?>
		<div class="menubutton">
			<img onclick="$('#buttons').toggle({duration: 800});" style="padding-right: 10px; max-height: 80%" src="/images/menu/menu_icon.png" alt="Menu icon" /><span style="font-family: PoppinsBold, DMSans, Verdana, sans-serif !important;" onclick="$('#buttons').toggle({duration: 800});">Menu</span>
			<div style="font-size: 1rem; float: right; justify-content: right; align-items: center; display: flex; margin-left: auto; padding-right: 1em;">Tekstgrootte:
				&nbsp;<a style="align-self: flex-middle; font-size: 15px;" href="#" onclick="setFontSize('A'); return false;">A</a>
				&nbsp;<a style="align-self: flex-middle; font-size: 20px;" href="#" onclick="setFontSize('B'); return false;">B</a>
				&nbsp;<a style="align-self: flex-middle; font-size: 25px;" href="#" onclick="setFontSize('C'); return false;">C</a>
			</div>
		</div>
		<div id="buttons" class="buttons">
<?php
		include($_SERVER['DOCUMENT_ROOT']."/view/menu.php");
?>
		</div>
		<div class="contentpane" id="content">
<?php
	if ($menuid < 0)
	{
                echo($menu->GetLocationLine(-1, $parentid));
?>
                                <h1>Helaas</h1>
                                De pagina die je probeert te openen is niet gevonden. <?php if ($_REQUEST['location'] != "") echo("(".$_REQUEST['location'].")"); ?><br>
                                Als je hier bent gekomen door een link van buiten onze site, pas deze dan aan.<br>
<?php
		if ($contactlocation != "")
		{
?>
                                Als je deze melding krijgt van een link op onze site, neem dan <a href="/<?php echo($contactlocation); ?>">contact</a> met ons op.<br><br>
<?php
		}
		if ($searchlocation != "")
		{
?>
                                Je kunt eventueel <a href="/<?php echo($searchlocation); ?>">zoeken</a> naar de pagina die je wilde bezoeken.<br><br>
<?php
		}
?>
                                Onze excuses voor het ongemak.<br>
<?php
	}
        else if ($currentAccessLevel < $requiredlevel)
        {
                echo($menu->GetLocationLine(-1, $parentid));
		if ($_REQUEST['locationparams'] != "")
		{
			$location .= ":".$_REQUEST['locationparams'];
		}
?>
                                <H1>Helaas</H1>
                                Je bent niet bevoegd deze pagina te bekijken.<br>
                                Deze pagina is alleen toegangelijk voor mensen die daarvoor toegang hebben gekregen van de webmaster.<br><br>
                                Als je deze toegang hebt, dan dien je <a href="/<?php echo($location); ?>/Login">jezelf aan te melden</a>.<br><br>
                                Als je hier bent gekomen door een link van buiten onze site, pas deze dan aan.<br>
<?php
		if ($searchlocation != "")
		{
?>
                                Je kunt eventueel <a href="/<?php echo($searchlocation); ?>">zoeken</a> naar de pagina die je wilde bezoeken.<br><br>
<?php
		}
		if ($contactlocation != "")
		{
?>
                                Als je deze melding krijgt van een link op onze site, neem dan <a href="/<?php echo($contactlocation); ?>">contact</a> met ons op.<br><br>
<?php
		}
?>
                                Onze excuses voor het ongemak.<br>
<?php
        }
        else if ($currentAccessLevel < 10 && !is_null($showuntil) && strtotime($showuntil) < time())
        {
                echo($menu->GetLocationLine(-1, $parentid));
?>
                                <H1>Helaas</H1>
                                Deze pagina was beschikbaar tot en met <?php echo(Util::getNiceLongDutchDate($showuntil)); ?> en is nu niet meer te bekijken.<br><br>
<?php
		if ($contactlocation != "")
		{
?>
                                Als je deze melding krijgt van een link op onze site, neem dan <a href="/<?php echo($contactlocation); ?>">contact</a> met ons op.<br><br>
<?php
		}
?>
                                Onze excuses voor het ongemak.<br>
<?php
        }
	else
	{
	        echo($menu->GetLocationLine($menuid, $parentid));
        	if (!is_null($user) && (!$user->isSpecialUser() || $currentAccessLevel >= 10))
        	{
?>
                        <script>
                                addLoadEvent(function()
                                {
                                        $("#tabmenu").tabs();
                                });
                        </script>
                        <div id="tabmenu">
	                        <ul>
<?php
	                if ($type != "Dummy")
        	        {
?>
        	                        <li><a href="#pagetab">Pagina</a></li>
<?php
                	}
	                if ($currentAccessLevel >= 10)
        	        {
?>
                	                <li><a href="#menutab">Menu</a></li>
<?php
               		}
	                if ($currentAccessLevel >= 255 && $type != "Dummy")
	                {
?>
                        	        <li><a href="#userstab">Gebruikers</a></li>
<?php
	                }
	                if (!is_null($user) && !$user->isSpecialUser())
	                {
?>
                                	<li><a href="#usertab"><?php echo($user->getRealname()); ?></a></li>
<?php
		        }
	                if ($currentAccessLevel >= 255)
	                {
?>
	                                <li><a href="#settingstab">Instellingen</a></li>
<?php
	                }
		        $pagestoapprove = array();
		        $pagestoapprove = $menu->GetPagesToApprove();
		        if (count($pagestoapprove) > 0)
		        {
?>
        	                        <li><a href="#approvetab">Goedkeuren (<?php echo(count($pagestoapprove)); ?>)</a></li>
<?php
	                }
	                if ($currentAccessLevel >= 255)
	                {
		                $errors = array();
	                        $menuTypes = $menu->GetMenuTypes();
	                        $specialMenuTypes = $menu->GetSpecialMenuTypes();
	                        $allMenuTypes = array_merge($menuTypes, $specialMenuTypes);
	                        $allMenuTypes["Menu"] = "Menu";
	                        foreach($allMenuTypes as $workertype => $name)
	                        {
	                                $update_worker = $menu->GetWorkerFromType($workertype);
	                                if (!is_null($update_worker) && method_exists($update_worker, "GetErrors"))
					{
						$errors = array_merge($errors, $update_worker->GetErrors());
					}
				}
				$internalTypes = array("SMS", "Email", "IDeal");
				foreach($internalTypes as $classname)
				{
					$worker = new $classname();
					if (!is_null($worker) && method_exists($worker, "getErrors"))
					{
						$errors = array_merge($errors, $worker->getErrors());
					}
				}
	                        if (count($errors) > 0)
	                        {
?>
                                <li><a href="#linkstab">Fouten (<?php echo(count($errors)); ?>)</a></li>
<?php
	                        }
	                }
			if (!is_null($user) && $user->getSiteAccesslevel() >= 255)
			{
				$database = Database::getInstance();
				$dberrors = $database->getErrors();
				if (count($dberrors) > 0)
				{
?>
                                <li><a href="#dberrorstab">Database fouten (<?php echo(count($dberrors)); ?>)</a></li>
<?php
				}
			}
?>
                        </ul>
<?php
	                if ($type != "Dummy")
	                {
?>
                        <div id="pagetab">
<?php
				if (!is_null($showuntil) && strtotime($showuntil) < time())
				{
?>
					<div style="background: red; padding-left: 2em;"><br>Deze pagina is niet meer te zien voor gasten.<br><br></div>
<?php
				}
?>
                                <?php include($_SERVER['DOCUMENT_ROOT']."/view/".strtolower($type).".php"); ?>
                        </div>
<?php
	                }
	                if ($currentAccessLevel >= 10)
	                {
?>
                        <div id="menutab">
                                <?php include($_SERVER['DOCUMENT_ROOT']."/view/menu_admin.php"); ?>
                        </div>
<?php
	                }
	                if ($currentAccessLevel >= 255 && $type != "Dummy")
	                {
?>
                        <div id="userstab">
                                <?php include($_SERVER['DOCUMENT_ROOT']."/view/user_admin.php"); ?>
                        </div>
<?php
	                }
	                if (!is_null($user) && !$user->isSpecialUser())
	                {
?>
                        <div id="usertab">
<?php
                                include($_SERVER['DOCUMENT_ROOT']."/view/user.php");
                                include($_SERVER['DOCUMENT_ROOT']."/view/menu_user_admin.php");
?>
                        </div>
<?php
	                }
	                if (!is_null($user) && $user->getSiteAccesslevel() >= 255)
	                {
?>
                        <div id="settingstab">
                                <?php include($_SERVER['DOCUMENT_ROOT']."/view/settings.php"); ?>
                        </div>
<?php
	                }
	                if (count($pagestoapprove) > 0)
	                {
?>
                        <div id="approvetab">
<?php
	                        echo("<h2>Pagina's die goedgekeurd moeten worden</h2>");
	                        for ($i = 0; $i < count($pagestoapprove); $i++)
	                        {
	                                $safeLocation = $pagestoapprove[$i]['safelocation'];
	                                echo("<a href=\"/".$safeLocation."\">".$safeLocation."</a><br>");
	                        }
?>
                        </div>
<?php
	                }
	                if ($currentAccessLevel >= 255 && count($errors) > 0)
	                {
?>
                        <div id="linkstab">
<?php
		                reset($errors);
		                foreach($errors as $location => $links)
		                {
		                        echo('<h2><a href="/'.$location.'">'.$location.'</a></h2>');
		                        for ($i = 0; $i < count($links); $i++)
					{
		                                echo($links[$i]."<br>");
					}
		                }
?>
                        </div>
<?php
	                }
			if (!is_null($user) && $user->getSiteAccesslevel() >= 255 && count($dberrors) > 0)
			{
?>
                        <div id="dberrorstab">
                                <?php include($_SERVER['DOCUMENT_ROOT']."/view/database.php"); ?>
                        </div>
<?php
			}
?>
                </div>
<?php
	        }
	        else
	        {
	                $originallocation = $_REQUEST["location"];
	                $linkedpages = $menu->GetLinkedPages($menuid);
	                $linkedpageright = 0;
	                for ($i = 0; $i < count($linkedpages); $i++)
	                {
	                        if ($linkedpages[$i]["id"] == $menuid || $linkedpages[$i]["position"] != "right")
				{
	                                continue;
				}
	                        if (!is_null($linkedpages[$i]["showto"]) && strtotime($linkedpages[$i]["showto"]) < time())
				{
	                                continue;
				}
	                        if (!is_null($linkedpages[$i]["showuntil"]) && strtotime($linkedpages[$i]["showuntil"]) < time())
				{
	                                continue;
				}
	                        $linkedpageright = $linkedpages[$i]["id"];
	                }
                        if ($linkedpageright > 0)
                        {
?>
                                <div class="leftpane" style="clear: both;">
<?php
                        }
                        $_REQUEST["linked"] = "";
                        include($_SERVER['DOCUMENT_ROOT']."/view/".strtolower($type).".php");

                        for ($i = 0; $i < count($linkedpages); $i++)
                        {
                                if ($linkedpages[$i]["id"] == $menuid || $linkedpages[$i]["position"] != "below")
				{
                                        continue;
				}
	                        if (!is_null($linkedpages[$i]["showto"]) && strtotime($linkedpages[$i]["showto"]) < time())
				{
	                                continue;
				}
	                        if (!is_null($linkedpages[$i]["showuntil"]) && strtotime($linkedpages[$i]["showuntil"]) < time())
				{
	                                continue;
				}
                                $location = $menu->GetLocation($linkedpages[$i]["id"]);
                                $type = $menu->GetClass($linkedpages[$i]["id"]);
                                echo("<br style='clear: both' />");
                                $_REQUEST["linked"] = "below";
                                $_REQUEST["location"] = $location;
                                $_REQUEST["menuid"] = $linkedpages[$i]["id"];
                                include($_SERVER['DOCUMENT_ROOT']."/view/".strtolower($type).".php");
                        }

                        if ($linkedpageright)
                        {
?>
                                </div>
<?php
                        }
                        if ($linkedpageright > 0)
                        {
                                $_REQUEST["linked"] = "right";
?>
                                <div class="rightpane">
<?php
                                $location = $menu->GetLocation($linkedpageright);
                                $type = $menu->GetClass($linkedpageright);
                                $_REQUEST["location"] = $location;
                                $_REQUEST["menuid"] = $linkedpageright;
                                include($_SERVER['DOCUMENT_ROOT']."/view/".strtolower($type).".php");
?>
                                </div>
<?php
	                }
	                $_REQUEST["linked"] = "";
	                $_REQUEST["location"] = $originallocation;
	                $location = $originallocation;
	                $menuid = $menu->GetId($location);
                        $_REQUEST["menuid"] = $menuid;
	        }
	}
	}
?>
		</div>
		<br>
		<div class="bottom">
<?php
			include("view/footer.php");
?>
		</div>
	</body>
</html>
