<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED ^ E_WARNING);
include('core/connection.php');
include('core/functions.php');
include('core/engine.php');

$xprid = $_COOKIE[md5('pr_id')];
$pagina = $_GET['pg'];
//echo '<script>console.log("xprid: ' . $xprid . '");</script>';
//echo '<script>console.log("pagina: ' . $pagina . '");</script>';

//se pagina incluir "files/"
if(strpos($pagina, 'files/') !== false) {

	$url = explode('/', $pagina);
	$slug = $url[1];

	$getFile = mysql_query('SELECT * FROM sy_site_arquivos WHERE slug = "' . $slug . '"');
	if($getFile && mysql_num_rows($getFile) > 0) {
		$file = mysql_fetch_array($getFile);
		$file = realpath('uploads/imagens/users/' . md5($file['pr_id_cliente']) . '/' . $file['arquivo']);
		if(file_exists($file)) {
			$mime = mime_content_type($file);
			header("Content-Type: $mime");
			header('Content-Disposition: inline; filename="' . $file['arquivo'] . '"');
			readfile($file);
			exit;
		}
	}
	
}

if (isPanel($pag) === true) {
	include('core/queries.php');
	if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") && strpos($_SERVER['HTTP_HOST'], '.test') === false) {
		$host = $_SERVER['HTTP_HOST'];
		$redirect = 'https://' . $host . $_SERVER['REQUEST_URI'];
		header('HTTP/1.1 301 Moved Permanently');
		header('location:' . $redirect);
		exit();
	}
} else {
	if (strpos($_SERVER['HTTP_HOST'], '.photojob.com.br') === false) {
		if (isSubdomain($_SERVER['HTTP_HOST'])) {
			if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") && strpos($_SERVER['HTTP_HOST'], '.test') === false) {
				$host = $_SERVER['HTTP_HOST'];
				$redirect = 'https://' . $host . $_SERVER['REQUEST_URI'];
				header('HTTP/1.1 301 Moved Permanently');
				header('location:' . $redirect);
				exit();
			}
		} elseif ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off") && strpos($_SERVER['HTTP_HOST'], '.test') === false) {
			if (strpos($_SERVER['HTTP_HOST'], 'www.') !== false) {
				$host = $_SERVER['HTTP_HOST'];
			} else {
				$host = 'www.' . $_SERVER['HTTP_HOST'];
			}
			$redirect = 'https://' . $host . $_SERVER['REQUEST_URI'];
			header('HTTP/1.1 301 Moved Permanently');
			header('location:' . $redirect);
			exit();
		} else {
			if (strpos($_SERVER['HTTP_HOST'], '.test') === false) {
				if (strpos($_SERVER['HTTP_HOST'], 'www.') === false) {
					$host = 'www.' . $_SERVER['HTTP_HOST'];
					$redirect = 'https://' . $host . $_SERVER['REQUEST_URI'];
					header('HTTP/1.1 301 Moved Permanently');
					header('location:' . $redirect);
					exit();
				}
			}
		}
	}
}
if (isPanel($pag) === true) {
	if (strpos($pag, 'login') !== false) {
		$xclass = 'class="app-login-page"';
	}
} else {
	if ($pag == 'home') {
		$xclass = 'class="home"';
	}
	if ($pag == 'area-restrita') {
		$xclass = 'class="area-restrita"';
	}
}
?>
<!doctype html>
<html>

<head>
	<?php
	include('includes/html/metatags.php');
	include('includes/html/social.php');
	include('includes/html/css.php');
	include('includes/html/scripts.php');
	include('includes/html/ga.php');
	?>
</head>

<body <?php echo $xclass; ?>>
	<div class="wrapper">
		<?php
		// Website Inativo
		// Caso seja marcado no cadastro do cliente "Site Inativo", o site ficará temporariamente desabilitado com uma mensagem.
		if ($user_site['site_ativo'] == 'no') {
			include('core/unavailable.php');
			exit;
		}
		include('core/header.php');
		include('core/pages.php');
		include('core/footer.php');
		?>
	</div>
	<?php
	if (isset($xscript)) {
		$xscript;
	}
	?>
</body>

</html>