<?php
/*==============================================
|| ############################################# 
|| Copyright Pike Admin - www.pikeadmin.com
|| ############################################# 
==============================================*/
session_start();
require("config.php");
require_once "core/core_classes.php";

$page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_STRING);
$pToken = filter_input(INPUT_GET, 'token', FILTER_SANITIZE_STRING);

if(!$pToken) 
	$page = 'sinAutorizacion';
		
$stmt = $conn->prepare("call clientes_consultaxToken('$pToken')");			
$stmt->execute();	
$numRegistros = $stmt->rowCount();	

if($numRegistros > 0){
	while($row = $stmt->fetch(PDO::FETCH_ASSOC)) 
	{ 
		$respuesta = new core_usuario();
		$respuesta->nidCliente = $row["Id"];
		$respuesta->nidEmpresa = $row["IdEmpresa"];		

		$_SESSION['user'] = json_encode($respuesta);
		
		if(!$page) 
			$page = 'inicio';		
	};				
}else{
	$page = 'sinAutorizacion';
}


/*if(!$pToken) 
	$page = 'sinAutorizacion';
if($pToken != '12345') 
	$page = 'sinAutorizacion';
if(!$page) 
	$page = 'inicio';*/
?>
<!DOCTYPE html>
<html>
<head>
<title>Moversa</title>
<?php include ("global-head.php");?>
</head>

<body class="adminbody">

<div id="main">

	<?php include ("navigationAgencia.php");?>
	
	<?php
	
	if($pToken) 
		include ("sidebarAgencia.php");
	?>
	
    <div class="content-page">
	
		<!-- Start content -->
        <div class="content">
            
			<div class="container-fluid">

				<?php 				
				// ADMIN pages
				switch ($page)
					{       

						case $page:
							include ("formasAgencia/".$page.".php");
							break;					
													
						default:
							include ("formasAgencia/inicio.php");
							break;						
					}
				?>

            </div>
			<!-- END container-fluid -->

		</div>
		<!-- END content -->

    </div>
	<!-- END content-page -->
    
		
	<?php include ("footer.php");?>
</div>
<!-- END main -->

<?php include ("global-footer.php");?>

</body>
</html>