<?php
	if(!isset($_SESSION)) {
		session_start();
	}

	require_once($_SERVER['DOCUMENT_ROOT'].'/varios/varios.php');

	if(isset($_SESSION[_SYSTEM_SESIONID."idperfil"])
		// && isset($_SESSION[_SYSTEM_SESIONID.'permisos']['modulo'])
	) {

		unset($_SESSION[_SYSTEM_SESIONID.'rut']);
		unset($_SESSION[_SYSTEM_SESIONID.'nombre_completo']);
		unset($_SESSION[_SYSTEM_SESIONID.'email']);
		unset($_SESSION[_SYSTEM_SESIONID.'idperfil']);
		unset($_SESSION[_SYSTEM_SESIONID.'perfil']);
		unset($_SESSION[_SYSTEM_SESIONID.'primer']);
		unset($_SESSION[_SYSTEM_SESIONID.'gestorcentral']);

		unset($_SESSION[_SYSTEM_SESIONID.'permisos']);

		unset($_SESSION[_SYSTEM_SESIONID.'REMOTE_ADDR']);
		unset($_SESSION[_SYSTEM_SESIONID.'HTTP_USER_AGENT']);

	}

	unset($_COOKIE['contador']);

	if (ini_get("session.use_cookies")) {

		$params = session_get_cookie_params();
		setcookie('sicpsp', '', time() - 100,
			$params["path"], $params["domain"],
			$params["secure"], $params["httponly"]
		);
	}

	session_destroy();
	require_once($_SERVER['DOCUMENT_ROOT'].'/varios/varios.php');
	if( strtolower(_Ambiente) == 'local' )
		header("Location: http://local.sils.agendamiento.adm/login/");
	else
		header("Location: https://"._SYSTEM_URL."/login/");
?>