<?php
    if($_SESSION['id_user'] == "" ){
        echo '
			<script>
				window.location = "/login"
			</script>
        ';
    }
    $hoy = date("Y-m-d H:i:s");

    $id = $pagina[1];
	$base = '';
    $query = mysqli_query($connect,"SELECT * FROM Stands WHERE id = '".$id."' ");
	$data = mysqli_fetch_array($query);

    $queryIz = mysqli_query($connect,"SELECT * FROM Stands WHERE id_pabellon = '".$data["id_pabellon"]."' AND posicion = 1 ");
	$dataIz = mysqli_fetch_array($queryIz);

    $queryDr = mysqli_query($connect,"SELECT * FROM Stands WHERE id_pabellon = '".$data["id_pabellon"]."' AND posicion = 2 ");
	$dataDr = mysqli_fetch_array($queryDr);
    
    $base = $recursos.'/'.$data["imagen"]; 

    $bt_iz = '
        <a href="'.$url.'/info/'.$dataIz["id"].'">
            <img src="'.$recursos.'/'.$dataIz["boton"].'" width="250" style="position: fixed; bottom: 10%; left: 2%; z-index:2" class="botones parpadea">
        </a>
    ';
    $bt_dr = '
        <a href="'.$url.'/info/'.$dataDr["id"].'">
            <img src="'.$recursos.'/'.$dataDr["boton"].'" width="250" style="position: fixed; bottom: 10%; right: 2%; z-index:2" class="botones parpadea">
	   </a>
    ';

    if($data["posicion"] == 2) {
        if( $id == 2){$pos_bt_info = '20%'; }
        if( $id == 4){$pos_bt_info = '11%'; }
        if( $id == 6){$pos_bt_info = '9%'; }
        if( $id == 8){$pos_bt_info = '13.5%'; }
        if( $id == 10){$pos_bt_info = '22%'; }
        if( $id == 12){$pos_bt_info = '22%'; }
        if( $id == 14){$pos_bt_info = '16%'; }
    }
    
    mysqli_query($connect,"INSERT INTO Analitica (id_evento, id_user, tipo, url, titulo, created_at) 
    VALUES 
    ( 1, ".$_SESSION['id_user'].", 10, '".$pagina[1]."', '".$data["nombre"]."', '".$hoy."' )");

?>

<div class="modal fade" id="modal_descargar" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Descargue información correspondiente a su país</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
			</div>
            <div class="modal-body" align="left">
                
                <div class="list-group">
                <?php
                    $queryInfo = mysqli_query($connect,"SELECT * FROM Stand_Documentos WHERE id_stand = '".$id."' AND estado = 1 ");
                    while($dataInfo = mysqli_fetch_array($queryInfo)){
                        echo '
                            <a href="'.$dataInfo["archivo"].'" target="_blank" class="list-group-item list-group-item-action" onclick="GuardarDato('.$_SESSION['id_user'].',1,'."'".$dataInfo["titulo"]."'".')">
                                '.$dataInfo["titulo"].'
                            </a>
                        ';
                    } 
                ?> 
                </div>
                
            </div>
		</div>
	</div>
</div>



<div class="modal fade" id="modal_videos_info" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Videos</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
			</div>
            <div class="modal-body" align="left">
                
                <div class="list-group">
                <?php
                    $queryVideo = mysqli_query($connect,"SELECT * FROM Stand_Videos WHERE id_stand = '".$id."' AND estado = 1 ");
                    while($dataVideo = mysqli_fetch_array($queryVideo)){
                        echo '
                            <a href="#" class="list-group-item list-group-item-action" onclick="Ver_Videos('."'".$dataVideo["video"]."'".'); OcultarPopVideos(); GuardarDato('.$_SESSION['id_user'].',2, '."'".$dataInfo["titulo"]."'".')">
                                '.$dataVideo["titulo"].'
                            </a>
                        ';
                    }
                ?> 
                </div>
                
            </div>
		</div>
	</div>
</div>

<div class="modal fade" id="modal_chat" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Chat en Línea</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
			</div>
            <div class="modal-body" align="left">
                
                <div class="list-group">
                <?php
                    $queryChat = mysqli_query($connect,"SELECT * FROM Stand_Contactos WHERE id_stand = '".$id."' AND estado = 1 ");
                    while($dataChat = mysqli_fetch_array($queryChat)){
                        echo '
                            
                            <a href="https://wa.me/'.$dataChat["telefono"].'/?text=Hola,+quiero+información+sobre+'.$data["nombre"].'" target="_blank" class="list-group-item list-group-item-action" onclick="GuardarDato('.$_SESSION['id_user'].',3, '."'".$dataInfo["nombre"]."'".')">
                                <img src="'.$url.'/img/whatsapp.png" width="30">
                                '.$dataChat["nombre"].'
                            </a>
                        ';
                    }
                ?> 
                </div>
            </div>
		</div>
	</div>
</div>



<div class="modal fade" id="modal_referencias" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">
			<div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Referencias (IPP)</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
			</div>
            <div class="modal-body" align="left" style="text-align: justify">
                <?php
                    $queryRef = mysqli_query($connect,"SELECT * FROM Stand_Referencias WHERE id_stand = '".$id."' AND estado = 1 ");
                    $dataRef = mysqli_fetch_array($queryRef);
                    echo nl2br($dataRef["referencia"]);   
                ?>
            </div>
		</div>
	</div>
</div>

<div class="modal fade" id="modal_zonas" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Zona Interactiva</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
			</div>
            <div class="modal-body" align="left">
                <div class="list-group">
                <?php
                    $queryZona = mysqli_query($connect,"SELECT * FROM Stand_Interactivos WHERE id_stand = '".$id."' AND estado = 1 ");
                    while($dataZona = mysqli_fetch_array($queryZona)){
                        echo '
                            <a href="'.$dataZona["link"].'" target="_blank" class="list-group-item list-group-item-action" onclick="GuardarDato('.$_SESSION['id_user'].',5, '."'".$dataInfo["titulo"]."'".')">
                                '.$dataZona["titulo"].'
                            </a>
                        ';
                    }
                ?> 
                </div>
                
                
            </div>
		</div>
	</div>
</div>

<div align="center" id="maestro" class="e_web">
	
    <!-- BOTONES -->
    <?php if($data["posicion"] == 1) { ?>
    <img src="<?php echo $url; ?>/img/img_wd/bt_descargar.png" width="110" class="bt_interface bt_descargar" style="left: 38.5%;" id="bt_descargar" data-toggle="modal" data-target="#modal_descargar">
    <img src="<?php echo $url; ?>/img/bt_video.png" width="110" class="bt_interface bt_video" style=" left: 62%;" id="bt_video" data-toggle="modal" data-target="#modal_videos_info">
    <img src="<?php echo $url; ?>/img/bt_chat.png" width="110" class="bt_interface bt_chat" style=" left: 62%;" id="bt_chat" data-toggle="modal" data-target="#modal_chat">
    <img src="<?php echo $url; ?>/img/bt_referencias.png" width="110" class="bt_interface bt_referencias" style=" left: 42%;" id="bt_referencias" data-toggle="modal" data-target="#modal_referencias">
    <img src="<?php echo $url; ?>/img/bt_zona_interactiva.png" width="110" class="bt_interface bt_zona" style=" left: 76%;" id="bt_zona" data-toggle="modal" data-target="#modal_zonas">
    <?php } ?>
    
    <!-- BOTONES -->
    <?php if($data["posicion"] == 2) { ?>
    <img src="<?php echo $url; ?>/img/bt_descargar.png" width="110" class="bt_interface bt_descargar" style=" left: <?php echo $pos_bt_info ?>;" id="bt_descargar" data-toggle="modal" data-target="#modal_descargar">
    <img src="<?php echo $url; ?>/img/bt_video.png" width="110" class="bt_interface bt_video" style=" left: 60%;" id="bt_video" data-toggle="modal" data-target="#modal_videos_info">
    <img src="<?php echo $url; ?>/img/bt_chat.png" width="110" class="bt_interface bt_chat" style=" left: 68%;" id="bt_chat" data-toggle="modal" data-target="#modal_chat">
    <img src="<?php echo $url; ?>/img/bt_referencias.png" width="110" class="bt_interface bt_referencias" style=" left: 30%;" id="bt_referencias" data-toggle="modal" data-target="#modal_referencias">
    <img src="<?php echo $url; ?>/img/bt_zona_interactiva.png" width="110" class="bt_interface bt_zona" style=" left: 67.5%;" id="bt_zona" data-toggle="modal" data-target="#modal_zonas">
    <?php } ?>
    
    
    <a href="<?php echo $url; ?>/muestra">
        <img src="<?php echo $url; ?>/img/bt_volver_muestra.png" width="200" style="position: absolute; top: 20%; right: 10%;" class="botones">
	</a>
	<?php echo $bt_iz; ?>
	<?php echo $bt_dr; ?>

	<img src="<?php echo $base; ?>" width="100%" id="stand_img" style="margin-bottom: 70px" >
</div>

<div align="center" class="e_movil">
    
    <img src="<?php echo $base; ?>" width="100%" id="stand_img" style="margin-bottom: 15px" >
    
    <button type="button" class="btn btn-light botones_movil" data-toggle="modal" data-target="#modal_descargar">Descargar Documentos</button>
    <button type="button" class="btn btn-light botones_movil" data-toggle="modal" data-target="#modal_videos_info">Video</button>
    <button type="button" class="btn btn-light botones_movil" data-toggle="modal" data-target="#modal_chat">Chat</button>
    <button type="button" class="btn btn-light botones_movil" data-toggle="modal" data-target="#modal_referencias">Referencias</button>
    

    <?php echo $bt_iz_movil; ?>
	<?php echo $bt_dr_movil; ?>
    
    <a href="<?php echo $url; ?>/muestra">
        <img src="<?php echo $url; ?>/img/bt_volver_muestra.png" width="200" class="botones">
	</a>
	
    
    
    


	
</div>

<style>
	.botones{
		transition: 0.5s all;
	}
    .botones:hover{
		transform: scale(1.1);
	}
    
    .bt_interface{
        position: absolute;
        width: 9%;
        max-width: 160px;
        min-width: 120px;
        cursor: pointer;
        transition: 0.5s all;
    }
    .bt_interface:hover{
        transform: scale(1.1);
    }
    
    .botones_movil{
		border-radius: 30px;
        width: 90%;
        font-size: 11px;
        padding: 5px 20px;
        font-weight: bold;
        box-shadow: 0px 3px 0px #a2a2a2;
        margin-bottom: 10px;
	}
    
    
    
    .parpadea {
  
      animation-name: parpadeo;
      animation-duration: 1s;
      animation-timing-function: linear;
      animation-iteration-count: infinite;

      -webkit-animation-name:parpadeo;
      -webkit-animation-duration: 3s;
      -webkit-animation-timing-function: linear;
      -webkit-animation-iteration-count: infinite;
    }

    @-moz-keyframes parpadeo{  
      0% { transform: scale(1); }
      15% { transform: scale(1.1); }
        30% { transform: scale(1); }
      100% { transform: scale(1); }
    }

    @-webkit-keyframes parpadeo {  
      0% { transform: scale(1); }
      15% { transform: scale(1.1); }
        30% { transform: scale(1); }
      100% { transform: scale(1); }
    }

    @keyframes parpadeo {  
      0% { transform: scale(1); }
      15% { transform: scale(1.1); }
    30% { transform: scale(1); }
      100% { transform: scale(1); }
    }
    
    
</style>
	
<script>
$( document ).ready(function() {    
    alto = $(window).width() * 0.41;
    
    <?php if($data["posicion"] == 1) { ?>
    $("#bt_descargar").css("top", (alto*0.73) ); 
    $("#bt_video").css("top", (alto*0.5) ); 
    $("#bt_chat").css("top", (alto*0.92) ); 
    $("#bt_referencias").css("top", (alto*0.92) ); 
    $("#bt_zona").css("top", (alto*0.85) ); 
    <?php } ?>
    
    <?php if($data["posicion"] == 2) { ?>
    $("#bt_descargar").css("top", (alto*0.73) ); 
    $("#bt_video").css("top", (alto*0.44) ); 
    $("#bt_chat").css("top", (alto*0.92) ); 
    $("#bt_referencias").css("top", (alto*0.92) ); 
    $("#bt_zona").css("top", (alto*0.85) ); 
    <?php } ?>
});
	
$( window ).resize(function() {
    
    alto = $(window).width() * 0.41;
    
    <?php if($data["posicion"] == 1) { ?>
    $("#bt_descargar").css("top", (alto*0.73) ); 
    $("#bt_video").css("top", (alto*0.5) ); 
    $("#bt_chat").css("top", (alto*0.92) ); 
    $("#bt_referencias").css("top", (alto*0.92) ); 
    $("#bt_zona").css("top", (alto*0.85) ); 
    <?php } ?>
    
    <?php if($data["posicion"] == 2) { ?>
    $("#bt_descargar").css("top", (alto*0.73) ); 
    $("#bt_video").css("top", (alto*0.44) ); 
    $("#bt_chat").css("top", (alto*0.92) ); 
    $("#bt_referencias").css("top", (alto*0.92) ); 
    $("#bt_zona").css("top", (alto*0.85) ); 
    <?php } ?>
    
});
    
    function OcultarPopVideos(){
        $("#modal_videos_info").modal("hide");
    }
	
</script>

<script>
    
var api = '<?php echo $api; ?>';
function GuardarDato(user,dato,string){

    jQuery.ajax({
        url: api+"guardar_dato.php",
		type:'post',
		data: {user: user, dato:dato, string:string, url:'<?php echo $pagina[1]; ?>' },
		}).done(function (resp){
				$("#xscript").html(resp);
		})
		.fail(function(resp) {
				console.log(resp);
		})
			.always(function(resp){
		}
    );
	
}

</script>

<?php
if($queryInfo->num_rows == 0){
    echo '<script> $(".bt_descargar").hide(); </script>';
}

if($queryVideo->num_rows == 0){
    echo '<script> $(".bt_video").hide(); </script>';
}

if($queryRef->num_rows == 0){
    echo '<script> $(".bt_referencias").hide(); </script>';
}
echo '<script> $(".bt_chat").hide(); </script>';
$ahora = date("Y-m-d H:i:s");
$chat_inicia = date("Y-m-d")." 08:00:00";
$chat_termina = date("Y-m-d")." 23:00:00";
if($ahora > $chat_inicia & $ahora < $chat_termina ){
    echo '<script> $(".bt_chat").show(); </script>';
}

if($queryChat->num_rows == 0){
    echo '<script> $(".bt_chat").hide(); </script>';
}




if($queryZona->num_rows == 0){
    echo '<script> $(".bt_zona").hide(); </script>';
}
?>



    
        