<?php

	if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
		$ip = $_SERVER['HTTP_CLIENT_IP'];
	} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
		$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	} else {
		$ip = $_SERVER['REMOTE_ADDR'];
	}	
	
/*            $ip_address= '192.99.4.107';
           
            $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
            $addrDetailsArr = unserialize(file_get_contents($geopluginURL)); 
            
            $city = $addrDetailsArr['geoplugin_city']; 
            
            $country = $addrDetailsArr['geoplugin_countryName'];
            
            if(!$city){
               $city='Not Define';
            }if(!$country){
               $country='Not Define';
            }
            echo '<strong>IP Address</strong>: '.$ip_address.'<br/>';
            echo '<strong>City</strong>: '.$city.'<br/>';
            echo '<strong>Country</strong>: '.$country.'<br/>';
*/


	 $query = "SELECT * FROM votos_registro WHERE votos_registro.ip = '".$ip."' ORDER BY votos_registro.id LIMIT 1";
	 $validar_visita = $engine->DB->QueryToArray($query);

	 if(!isset($validar_visita)){
	 
		 $query_registrovotos = "INSERT INTO votos_registro (ip, seo_key) 
								   VALUES ( 
									'".$ip."',
									'visit')";
		
		 $registrarvoto = $engine->DB->QueryToArray($query_registrovotos);
	 }
		
		
	if($_POST['navigation_terms'] == 'accept_terms'){
		
					$_SESSION['navigation_terms'] 	= 'accept_terms';
		
					 $query_visitas = "UPDATE votos_registro SET seo_key = '".$_POST['navigation_terms']."' WHERE votos_registro.ip = '".$validar_visita[0]['ip']."'";
					 
					 $update_visitas = $engine->DB->QueryToArray($query_visitas);
		
		}
		


		if(!isset($_SESSION['navigation_terms'])){ ?>
        
        <style>
		
        #navigation_terms{
			position:fixed;
			bottom:0px;
			border-top:2px solid #999;
			z-index:10000 !important;
			color:#FFF;
			overflow:hidden;
			width:100%;
			height:auto;
			background:#333;	
			}
        #navigation_terms p{
			color:#CCC;
			max-width:960px;
			margin:auto;
			padding:20px;
			}
			
			.accept_btn{
				float:right;
				padding:8px 20px;
				color:#FFF;
				background:#09F;
				border:2px solid #0CF;
				border-radius:7px;}
			
        </style>
        <div id="navigation_terms">
                <p>
                    <button class="accept_btn" onclick="navigation_terms()">Aceptar!</button>
                    Usamos cookies propias y de terceros para mejorar la experiencia de navegación y realizar tareas de analítica.
                    <br />
                    Si continúa navegando, consideramos que acepta nuestra <a href="http://afterfuture.net/nuestra-empresa/politica-de-cookies">política de cookies.</a>
                    <br />
					 
                </p>
        </div>
        
        {literal}
        <script>
        function navigation_terms(){
			
				$('#navigation_terms').hide();
				$.ajax({
						  type: "POST",
						  url: "{/literal}{$SITE_URL}{literal}",
						  data: "navigation_terms=accept_terms",
						  success: function(res){
							  	
							}
					 }) 
			}
        </script>
		{/literal}
			<? }	
			else{

				}

?>
