<?php
session_set_cookie_params(0);
session_start();
require_once('conexion.php');
?>

<!doctype html>
<html>
<head>

<link rel="shortcut icon" href="img\logos_vicpos/vic_logo.ico" type="image/x-icon">
<title>Vicpos</title>

<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<script type='text/javascript' src='https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js'></script>
<script type='text/javascript' src='https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/js/bootstrap.min.js'></script>
<script src="js/jquery-2.1.4.min.js" type="text/javascript"></script>
<script src="js/bootstrap.min.js"></script>
<link href="js\plugins\lightbox\themes\evolution-dark\jquery.css" rel="stylesheet"> 
<link href='https://stackpath.bootstrapcdn.com/bootstrap/5.0.0-alpha1/css/bootstrap.min.css' rel='stylesheet'>
<link href='' rel='stylesheet'>

</head>
<body oncontextmenu='return false' class='snippet-body'>
    <section class="body">
        <div class="container">
            <div class="login-box">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="logo">
                            <img src="img/login/vicpos.png"  width="60%" >
                        </div>
                    </div>
                </div>
               
                <div class="row">
                    <div class="col-sm-6">
                    <br>
                    <?php 
                     if(!empty($_SESSION["usu_id"])) 
                        {
                            echo '<meta http-equiv="refresh" content="0;url=inicio.php">';
                        }
                    $cero=0;
                    if(!empty($cero)=='0')
                    {
                        if (!empty($_POST['usu_clave'])=='usu_clave')
                            { 
                                $usu_nombre=mysqli_real_escape_string($con, $_POST['usu_nombre']);
                                $usu_clave=mysqli_real_escape_string($con,$_POST['usu_clave']);
                                $empresa=mysqli_real_escape_string($con,$_POST['empresa']);
                                         
                                $sql=mysqli_query($con,"SELECT usu_id, usu_nombre, usu_clave,bodega, sucursal, empresa_emp_id,rol_rol_id FROM usuario 
                                WHERE ( usu_correo='$usu_nombre' OR usu_username='$usu_nombre') AND usu_clave='".$usu_clave."' AND empresa_emp_id='".$empresa."' and usu_estado='Activo' ") or die(mysqli_error($con));
                                    if($row = mysqli_fetch_array($sql))  
                                    {
                                        $_SESSION['usu_nombre'] = $row["usu_nombre"]; 
                                        $_SESSION['usu_id'] = $row["usu_id"]; 
                                        $_SESSION['empresa'] = $row["empresa_emp_id"];
                                        $_SESSION['bod_id'] = $row["bodega"]; 
                                        $_SESSION['sucursal'] = $row["sucursal"]; 
                                        $_SESSION['rol_rol_id'] = $row["rol_rol_id"];
                                        $rol = $row["rol_rol_id"];

                                        $sucursal=$row["sucursal"];

                                        $can=mysqli_query($con,"SELECT * FROM rol where empresa='".$row["empresa_emp_id"]."' and rol_id='".$row["rol_rol_id"]."'") or die(mysqli_error($con)); 
                                        $ro=mysqli_fetch_array($can);
                                        $_SESSION['rol_nombre'] = $ro["rol_nombre"];

                                        $suc=mysqli_query($con,"SELECT * FROM sucursal where suc_id='$sucursal' ") or die(mysqli_error($con)); 
                                        $suc=mysqli_fetch_array($suc);
                                        $suc_estado = $suc["suc_estado"];
                                        if ($suc_estado=='inactivo') {
                                            echo '<h3 align="center" style="padding: 5px"><img  src="img/inicio.png" alt="" width="40%" /></h3></br>';
                                            echo '<div class="alert alert-danger"><center><strong>Su cuenta ha sido suspendida</strong></center></div>';
                                            echo '<center><a href="inicio.php" class="btn"><strong>Intentar de Nuevo</strong></a></center>';
                                            echo '<div class="bottom">
                                                </br></br>
                                                </div>';

                                            // Finalmente, destruir la sesión.
                                            session_destroy();
                                        }
                                        else
                                        {
                                            echo '<h3 align="center" style="padding: 5px"><img  src="img/inicio.png" alt="" width="40%" /></h3></br>';
                                            echo '<center><strong><h4>BIENVENIDO</h4><br>'.$row['usu_nombre'].'</strong></center><br>';
                                            echo '<center><img src="img/ajax-loader.gif"></center><br>';
                                            echo '<meta http-equiv="refresh" content="2;url=inicio.php">';
                                            echo '<div class="bottom">
                                                </br></br>
                                                </div>';

                                        }

                                          
                                       
                                    }
                                    else 
                                    {
                                        echo '<h3 align="center" style="padding: 5px"><img  src="img/inicio.png" alt="" width="40%" /></h3></br>';
                                        echo '<div class="alert alert-danger"><center><strong>Usuario y Contraseña Incorrecto</strong></center></div>';
                                        echo '<center><a href="index.php" class="btn"><strong>Intentar de Nuevo</strong></a></center>';
                                        echo '<div class="bottom">
                                              </br></br>
                                              </div>';
                                    }
                            } 
                        else
                        {   ?>                        
                            <div class="show" id="inicio">
                                <h3 class="header-title">Ingresa a tu cuenta</h3>
                                <form class="login-form" action="" method="post" >
                                    <div class="form-group">
                                        <input type="text"  id="usu_nombre" name="usu_nombre" class="form-control" required="" value="" placeholder="Usuario">
                                    </div>
                                    <div class="form-group">
                                        <input type="password" id="usu_clave" name="usu_clave" class="form-control" required="" value="" placeholder="Contraseña">
                                       
                                    </div>
                                    
                                    <div class="form-group">
                                         <label>Empresa:</label>
                                   
                                        <select name="empresa" id="empresa"  class="form-control " >
                                        <?php
                                            $datos = mysqli_query($con,"SELECT * FROM empresa  ") ;
                                            while( $fila = mysqli_fetch_array( $datos ) )
                                            {
                                                echo' <option value="'.$fila['emp_id'].'">'.ucfirst($fila['emp_nombre']).'</option>';
                                            }
                                        ?>
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <button class="btn btn-primary btn-block">Acceder</button>
                                    </div>
                                    <div class="form-group">
                                        <label  onclick="cambiaVisibilidad()" class="forgot-password">Recuperar contraseña</label>
                                    </div>
                                </form>
                            </div>
                <?php   } 
                    } ?>

                            <div style="display:none;" id="recu_contra">
                                <h3 class="header-title">Recuperar contraseña</h3>
                                <div id="resultados_contra" class="header-title"></div>
                                <p align="center"><label >Ingresa tu correo y documento.<br>
                                Si no recibes el correo, no olvides revisar<br> la carpeta de spam.</label></p>
                                
                                <form class="login-form" method="post" action="" id="contrasena" name="contrasena" >
                                    <div class="form-group">
                                        <input class="form-control" class="" type="email" name="correo" id="correo"  value="" required placeholder="Email/Correo">
                                    </div>
                                    <div class="form-group">
                                        <input class="form-control" type="number" name="documento" id="documento"  value="" required placeholder="Documento">
                                       
                                    </div>
                                    <div class="form-group">
                                        <button type="submit" id="enviar" name="enviar" class="btn btn-primary btn-block">Enviar</button>
                                    </div>
                                    <div class="form-group">
                                        <label  onclick="cambiaVisibilidad()" class="forgot-password">Iniciar sesión</label>
                                    </div>
                                </form>
                            
                            </div>
                        </div>


                        <div class="col-sm-6 hide-on-mobile">
                            <div id="demo" class="carousel slide" data-ride="carousel">
                                <div class="carousel-inner">
                                    <div class="carousel-item active">
                                        <div class="slider-feature-card">
                                         <center> <img src="img/login/factura.png" class="d-block " alt=""></center>
                                            <h5 class="slider-title">FACTURACIÓN ELECTRONICA</h5>
                                            <p class="slider-description">¡Activa la facturación electrónica a un clic con todos los requisitos exigidos por la DIAN.!  </p>
                                        </div>
                                    </div>
                                    <div class="carousel-item ">
                                        <div class="slider-feature-card">
                                          <center> <img src="img/login/documento.png" class="d-block " alt=""></center>
                                            <h5 class="slider-title">DOCUMENTO SOPORTE</h5>
                                            <p class="slider-description">Cumple fácil con cada requisito legal.</p>
                                        </div>
                                    </div>
                                     <div class="carousel-item ">
                                        <div class="slider-feature-card">
                                          <center> <img src="img/login/nomina.png" class="d-block " alt=""></center>
                                            <h5 class="slider-title">NOMINA ELECTRONICA</h5>
                                            <p class="slider-description">¡No te estreses! Emite y liquida en segundos tu nómina.</p>
                                        </div>
                                    </div>
                                    <a class="carousel-control-prev" type="button" data-target="#demo" data-slide="prev">
                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                              </a>
                              <a class="carousel-control-next" type="button" data-target="#demo" data-slide="next">
                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                              </a>
                              </div>
                              
                            </div>
                        </div>
                </div>
            </div>
        </div>
    </section>
</body>
</html>

<script type="text/javascript">

$("#contrasena").submit(function( event ) {
    $('#enviar').attr("disabled", true);
    var parametros = $(this).serialize();
    $.ajax({
        type: "post",
        url: "libraries/pdf/pdf_correos/email_contraseña.php",
        data: parametros,
        beforeSend: function(objeto){
            $('#resultados_contra').html('<center><img src="./img/ajax-loader.gif"> CARGANDO...</center>');
        },
        success: function(datos){
        $("#resultados_contra").html(datos);
        $('#enviar').attr("disabled", false);
         document.getElementById("contrasena").reset();
        }
    });
event.preventDefault();
})

</script>

<!-- CAMBIO DE DIV FORMULARIOS INICIO- CONTRASEÑA-->
<script type="text/javascript">
function cambiaVisibilidad() {
       var div1 = document.getElementById('inicio');
       var div2 = document.getElementById('recu_contra');
       if(div2.style.display == 'block'){
           div2.style.display = 'none';
           div1.style.display = 'block';
       }else{
          div2.style.display = 'block';
          div1.style.display = 'none';
         }
   }
</script>



<!-- ESTILOS DE PAGINA -->
<style>
/*@import url(https://fonts.googleapis.com/css?family=Roboto:300,400,700&display=swap);*/

body {
    background: #f5f5f5;
}

@media only screen and (max-width: 767px) {
    .hide-on-mobile {
        display: none;
    }
}

.login-box {
    margin: 50px;
    background: url(img/login/fondo.png);
    background-size: cover;
    background-position: center;
    padding: 40px;
    min-height: 100%;
    -webkit-box-shadow: 0 2px 60px -5px rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 60px -5px rgba(0, 0, 0, 0.1);
}

.logo {

    text-align: center;
    margin-bottom: 10px;
}

.header-title {
    text-align: center;
    margin-bottom: 30px;
}

.login-form {
    max-width: 300px;
    margin: 0 auto;
}

.login-form .form-control {
    border-radius: 0;
    margin-bottom: 30px;
}

.login-form .form-group {
    position: relative;
}

.login-form .form-group .forgot-password {
    position: absolute;
    color: #FF5500;
   text-decoration: none;
    right: 15px;
}

.login-form .btn {
    border-radius: 0;
    -webkit-box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
}

.login-form .btn.btn-primary {
    background: #FF5500;
    border-color: #FF5500;
}

.slider-feature-card {
    background: #ffffff;
    max-width: 350px;
    margin: 0 auto;
    padding: 60px;
    text-align: center;
    -webkit-box-shadow: 0 2px 25px -3px rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 25px -3px rgba(0, 0, 0, 0.1);
}

.slider-feature-card img {
    height: 100px;
    margin-top: 00px;
    margin-bottom: 10px;
}

.slider-feature-card h3,
.slider-feature-card p {
    margin-bottom: 20px;
}

.carousel-indicators {
    bottom: -50px;
}

.carousel-indicators li {
    cursor: pointer;
}</style>







<!---- MODAL DE LA LICENCIA --->
<?php
$fecha_hoy=date('Y-m-d');
$can=mysqli_query($con,"SELECT * FROM empresa order by emp_id limit 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)
{
?>



<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">

<script async src="https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.min.js" crossorigin="anonymous"></script>

<script type="importmap">
{
"imports": {
"@popperjs/core": "https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.6/dist/umd/popper.min.js",
"bootstrap": "https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.esm.min.js"
}
}
</script>

<script type="module">
import * as bootstrap from 'bootstrap'
new bootstrap.Popover(document.getElementById('popoverButton'))
</script>



    <!-- Modal -->
<div class="modal fade" id="licencia" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h1 class="modal-title fs-5" id="exampleModalLabel"></h1>
            </div>
            <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>
                    
               
                    
                <div id="contenedor1">
                    <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" style="background-color: #FF5500;border-color: #FF5500;" class="btn btn-primary" data-bs-dismiss="modal">Cerrar</button>
            </div>
        </div>
    </div>
</div>

    <!-- Button trigger modal 
    <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#licencia">
    Launch demo modal
    </button>-->


<script>
   $(document).ready(function()
   {
      $("#licencia").modal("show");
   });
</script>
<?php } ?>


<style type="text/css">
  
#contenedor1{
    margin: 20px auto;
    width: auto;
    text-align: center;
    }

#countbox{
    font-size: 20px;
    font-family:Tahoma;
    background: #f05152;
    color: #fff;
    padding: 10px 0;
    margin: 20px auto 0;
}

</style>
