<?php
	declare(strict_types = 1);
	namespace Kimendisch\Sbgg_Jetzt;
	use Flake\Url_Redirect;
	use Flake\Request;
	
	// CHECK AUTHENTICATION //
	// redirect to login page when not logged in
	$login = $_SESSION[__NAMESPACE__]["admin"]["login"] ?? null;
	if($login !== true){
		Url_Redirect::location("http" . (Request::has_ssl() ? "s" : "") . "://" . Request::domain_raw_full() . "/admin/login");
		die();
	}
	
	
	// MAYBE DO LOGOUT //
	if(isset($_GET["logout"])){
		// unset session flag
		$_SESSION[__NAMESPACE__]["admin"]["login"] = false;
		
		// redirect to login page
		Url_Redirect::location("http" . (Request::has_ssl() ? "s" : "") . "://" . Request::domain_raw_full() . "/admin/login");
		die();
	}
?>
