<?php
$fecha_hoy=date('Y-m-d');
$can=mysqli_query($con,"SELECT * FROM empresa WHERE emp_id='1' ") or die(mysqli_error($con)); 
$d=mysqli_fetch_array($can);
$fecha_licencia=$d['fecha_licencia'];

$diasantes = strtotime($fecha_licencia."-8 days");
$diasantes= date("Y-m-d",$diasantes) . "\n";
if ($diasantes <= $fecha_hoy)
{
?>
<div id="licencia" class="modal fade" tabindex="-1" role="dialog" >
	 <div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-body">
				<div class="alert alert-danger alert-dismissable">
					<strong>"SU LICENCIA ESTA PROXIMA A VENCER"  </strong>Pronto ya no podras usar el sistema, <a href="#" class="alert-link"></a>
				</div>

                <?php
                    $year = explode("-", $fecha_licencia); 
                    $ye=$year[0]; 
                    $mes = explode("-", $fecha_licencia); 
                    $me=$mes[1]; 
                    $dia = explode("-", $fecha_licencia); 
                    $di=$dia[2]; 

                    $hora = '00';
                    $min = '00';
                    $seg = '00';
                ?>
                <script type="text/javascript">
                    año="<?php echo $ye; ?>";
                    mes="<?php echo $me; ?>";
                    dia="<?php echo $di; ?>";
                    hora="<?php echo $hora; ?>";
                    minuto="<?php echo $min; ?>";
                    segundo="<?php echo $seg; ?>";
                    urlsitio ='include/cerrar_sesion_licencia.php'; //url del sitio web final     
                    dateFuture = new Date(año, mes-1 , dia, hora, minuto, segundo);   
                    window.onload=function(){GetCount();}
                </script>
                    
                <style type="text/css">
                      
                    #contenedor{
                        margin: 20px auto;
                        width: auto;
                        text-align: center;
                        }
                    #textosuperior{
                        margin-top: 20px;
                        font-family: Arial;
                        font-size: 20px;
                        color: #f05152;
                        }
                    #countbox{
                        font-size: 20px;
                        font-family:Tahoma;
                        background: #f05152;
                        color: #fff;
                        padding: 10px 0;
                        margin: 20px auto 0;
                    }
                    #textoinferior{
                        font-size: 10px;
                        font-family: Arial;
                        margin-top: 20px;
                        }
                </style>
                    
                <div id="contenedor">
                    <div id="countbox"></div>
                    </div>
                  
                    <script type="text/javascript">
                    function GetCount(){
                            dateNow = new Date();                                             
                            amount = dateFuture.getTime() - dateNow.getTime();                
                            delete dateNow;
                    
                            if(amount < 0){
                            location.href=urlsitio;
                            }
                            else
                            {
                                days=0;hours=0;mins=0;secs=0;out="";
                
                                amount = Math.floor(amount/1000);
                
                                days=Math.floor(amount/86400);
                                amount=amount%86400;
                
                                hours=Math.floor(amount/3600);
                                amount=amount%3600;
                
                                mins=Math.floor(amount/60);
                                amount=amount%60;
                
                                secs=Math.floor(amount);
                
                                if(days != 0){out += days +" DIA"+((days!=1)?"S":"")+", ";}
                                if(days != 0 || hours != 0){out += hours +" HORA"+((hours!=1)?"S":"")+", ";}
                                if(days != 0 || hours != 0 || mins != 0){out += mins +" MINUTO"+((mins!=1)?"S":"")+", ";}
                                out += secs +" SEGUNDOS";
                                document.getElementById('countbox').innerHTML=out;
                
                                setTimeout("GetCount()", 1000);
                            }
                    }
                    </script>
                </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-danger" data-dismiss="modal">Cerrar</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div> 
<script>
   $(document).ready(function()
   {
      $("#licencia").modal("show");
   });
</script>
<?php } ?>