<?php
ini_set('session.cookie_samesite', 'None');
//ini_set('session.cookie_secure', 'true');
//session_set_cookie_params('None');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
header('P3P: CP="CAO PSA OUR"');
/*header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type, origin");
ini_set('session.cookie_samesite', 'None');
//session_set_cookie_params(['samesite' => 'None', 'secure' => true]);
 session_set_cookie_params(3600, '/', '*', true, true);*/
//session_start();
if (version_compare(phpversion(), '5.4.0', '<')) {
 if(session_id() == '') {
    session_start();
 } }else{
if (session_status() == PHP_SESSION_NONE) {
    session_start();
} }
$param_url = explode("mod=", $_SERVER['REQUEST_URI']);
$permitir = false;
if(count($param_url) > 1)
{
	if($param_url[1] == "agente_agendamento" or $param_url[1] == "executar_agendamento")
	{
		$permitir = true;
	}
}	
//login via token base64 do usuário e senha {"usuario":"admin","senha":"123"} eyJ1c3VhcmlvIjoiYWRtaW4iLCJzZW5oYSI6IjEyMyJ9
if(isset($_GET["token"]))
{
	require_once("src/controller/LoginController.php");
	login_token($_GET["token"]);
}
$nomePag = explode("/",$_SERVER['PHP_SELF']);	
if( ((! isset($_SESSION["autenticado_bi"]) and  ! isset($_SESSION["id_usuario_bi"])) or  (isset($_SESSION["autenticado_bi"]) and ! $_SESSION["autenticado_bi"]) )
	and ! $permitir
	and $nomePag[(count($nomePag)-1)] != "login.php" 
	and $nomePag[(count($nomePag)-1)] != "LoginController.php" 
	and $nomePag[(count($nomePag)-1)] != "config.php" 
)
{
	header("Location: login.php"); 
	exit();
}
?>