<?php
require_once("../../config/conexion.php");
require_once("../../models/Permisos.php");
require_once("../../models/Biometrico.php");
$permiso = new Permisos();
$resultado = $permiso->Permisos_por_Perfil("BIOMETRICO", $_SESSION["perfil"]);
foreach ($resultado as $row) {
    $crear = $row["crear"];
    $estado = $row["estado"];
    $actualizar = $row["actualizar"];
    $eliminar = $row["eliminar"];
    $contacto = $row["contacto"];
    $leer = $row["leer"];
}
if (isset($_SESSION["usuariodbk"])) {
    ?>
    <!DOCTYPE html>
    <html lang="es">
        <head>
            <?php
            require_once '../html/MainHead.php';
            ?>
            <title>SIED | BIOMETRICO GESTION</title>
            <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
            <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-theme/0.1.0-beta.10/select2-bootstrap.min.css" integrity="sha512-kq3FES+RuuGoBW3a9R2ELYKRywUEQv0wvPTItv3DSGqjpbNtGWVdvT8qwdKkqvPzT93jp8tSF4+oN4IeTEIlQA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
        </head>
        <body class="hold-transition sidebar-mini layout-fixed">           
            <?php require_once '../html/MainMenu.php'; ?> 
            <?php require_once '../html/MainHeader.php'; ?>             
            <div class="content-wrapper ">
                <div class="content-header">
                    <div class="container-fluid">
                        <div class="row mb-2">
                            <div class="col-sm-6">
                                <h1 class="m-0">BIOMETRICO GESTION</h1>
                            </div>
                            <div class="col-sm-6">
                                <ol class="breadcrumb float-sm-right">
                                    <li class="breadcrumb-item"><a href="../UsuHome/">Inicio</a></li>
                                    <li class="breadcrumb-item active">Biometrico Gestion</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="br-pagebody mg-t-5 pd-x-30">
                    <section class="content">
                        <div class="container-fluid">
                            <div class="row row-sm mg-t-20">
                                <div class="col-12">
                                    <div class="card">
                                        <div class="card-header">
                                            <h3 class="card-title"><b>Biometrico Gestion</b></h3>

                                            <div class="card-tools">
                                                <?php
                                                if ($crear == 1) {
                                                    echo"<button class='btn btn-primary btn-sm' id='add_button' onclick='nuevo()'><i class='fa fa-plus-square mg-r-10 mr-2'></i>Nuevo Registro</button>";
                                                }
                                                ?>
                                            </div>

                                        </div>
                                        <div class="card-body responsive">
                                            <form class="mb-4" id="form_filter">
                                                <div class="row">
                                                    <div class="col-md-3">
                                                        <label for="">Año</label>
                                                        <select name="" id="anio_select" class="form-control" required>
                                                            <?php 
                                                                $year_actual = date("Y");

                                                                for ($i = $year_actual; $i >= 1900; $i--) {
                                                                    echo "<option value='$i'>$i</option>";
                                                                }
                                                            ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <label for="">Mes</label>
                                                        <select name="" id="mes_select" class="form-control" required>
                                                            <option value="1">Enero</option>
                                                            <option value="2">Febrero</option>
                                                            <option value="3">Marzo</option>
                                                            <option value="4">Abril</option>
                                                            <option value="5">Mayo</option>
                                                            <option value="6">Junio</option>
                                                            <option value="7">Julio</option>
                                                            <option value="8">Agosto</option>
                                                            <option value="9">Septiembre</option>
                                                            <option value="10">Octubre</option>
                                                            <option value="11">Noviembre</option>
                                                            <option value="12">Diciembre</option>
                                                        </select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <label for="">Dia</label>
                                                        <select name="" id="dia_select" class="form-control" required>
                                                            <?php 
                                                                for ($i = 1; $i <= 31; $i++) {
                                                                    echo "<option value='$i'>$i</option>";
                                                                }
                                                            ?>
                                                        </select>
                                                    </div>
                                                    <div class="col-md-3">
                                                        <label for="">Usuario</label>
                                                        <select name="" id="empleado_select" class="form-control" required>
                                                        </select>
                                                    </div>
                                                </div>
                                                <button class="btn btn-primary btn-sm mt-4 mr-2" id="clear_filter" type="button">
                                                    <i class="fa fa-filter mr-2"></i> Limpiar
                                                </button>

                                                <button class="btn btn-success btn-sm mt-4" type="submit">
                                                    <i class="fa fa-search mr-2"></i> Buscar
                                                </button>
                                            </form>

                                            <table id="data-biometric" class="table table-bordered display table-striped responsive nowrap tablas" cellspacing="0" width="100%">
                                                <thead>
                                                    <tr>
                                                        <th>Fecha</th>
                                                        <th>Usuario</th>
                                                        <th>Hora</th>
                                                        <th>Estado</th>
                                                        <th>Observacion</th>
                                                        <th>Tipo de Registro</th> 
                                                        <th>Acciones</th>                                              
                                                    </tr>
                                                </thead>
                                                <tbody>                                                    
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>

                    <div id="registro_biometrico" class="modal fade" data-backdrop="static" data-keyboard="false">
                        <div class="modal-dialog modal-md" role="document">
                            <div class="modal-content bd-0">
                                <div class="modal-header pd-y-20 pd-x-25">
                                    <h5 class="tx-14 mg-b-0 tx-uppercase tx-inverse tx-bold modal-titl">
                                        Registro Biometrico
                                    </h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div class="callout callout-info">
                                        Bienvenid@
                                        <b><?php echo $_SESSION["pnombre"]." ".$_SESSION["papellido"]." ".$_SESSION["snombre"]." ".$_SESSION["sapellido"]; ?></b>
                                        por favor seleccion el tipo de registro, recuerda que todos los campos con <span class="text-danger">(*)</span> son obligatorios.
                                    </div>

                                    <div class="row mt-2">
                                        <div class="col-md-12">
                                            <span class="fw-bold"><b>Fecha Actual: </b></span>
                                            <span id="MyDateDisplay"></span>
                                        </div>
                                        <div class="col-md-12">
                                            <span class="fw-bold"><b>Hora Actual: </b></span>
                                            <span id="MyClockDisplay"></span>
                                        </div>
                                    </div>

                                    <form id="register_form">
                                        <div class="mt-4">
                                            <div class="mb-3 mt-3 border p-3">
                                                <input type="hidden" value="" id="biometricodbk" name="biometricodbk">
                                                <input type="hidden" id="personadbk" name="personadbk">
                                                <div class="form-group">
                                                    <label class="form-label fw-bold">Formato de registro <span class="text-danger">(*)</span></label>
                                                    <select name="tipo" required class="form-control" id="register_format">
                                                        <option selected value="">Seleccionar horario</option>
                                                        <option value="ENTRADA_INICIAL" id="entryInitial">Entrada Inicial</option>
                                                        <option value="ENTRADA_ALMUERZO">Entrada de Almuerzo</option>
                                                        <option value="SALIDA_ALMUERZO">Salida de Almuerzo</option>
                                                        <option value="SALIDA_FINAL" id="finalExit">Salida Final</option>
                                                    </select>
                                                </div>
                                                <div class="form-group">
                                                    <label class="form-label">Fecha <span class="text-danger">(*)</span></label>
                                                    <input type="date" name="fecha" id="date_register" class="form-control" required>
                                                </div>
                                                <div class="form-group">
                                                    <label class="form-label">Hora <span class="text-danger">(*)</span></label>
                                                    <input type="time" name="hora" id="hour_register" class="form-control" required>
                                                </div>
                                                <div class="form-group">
                                                    <label class="form-label">Usuario <span class="text-danger">(*)</span></label>
                                                    <select name="empleado" required class="form-control" id="user_select">
                                                    </select>
                                                </div>

                                                <div id="user_current" class="d-none">
                                                    <p class="text-muted"><b>Usuario Actual</b>: <span id="person_update"></span></p>
                                                </div>

                                                <div class="form-group">
                                                    <label for="">Estado <span class="text-danger">(*)</span></label>
                                                    <select name="status" id="status" class="form-control" required>
                                                        <option value="" selected>Seleccione un estado</option>
                                                        <option value="REGULAR">Regular</option>
                                                        <option value="TARDANZA">Tardanza</option>
                                                        <option value="SALIDA ANTICIPADA">Salida Anticipada</option>
                                                    </select>
                                                </div>

                                                <div class="form-group">
                                                    <label for="">Observacion <span class="text-danger">(*)</span></label>
                                                    <textarea name="observation" class="form-control" id="observation" cols="30" rows="3" required></textarea>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                </div>  

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-warning btn-sm" id="save_register">
                                        <i class="fas fa-save mr-2"></i> Guardar
                                    </button>   
                                    </button>
                                    <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">
                                        <i class="fas fa-times mr-2"></i> Cerrar
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            
            <?php require_once '../html/MainFooter.php'; ?> 
            <aside class="control-sidebar control-sidebar-dark">
            </aside>
            <?php require_once 'visualizar.php'; ?>
            <?php require_once '../html/MainJS.php'; ?>
            <script type="text/javascript" src="gestion.js"></script>
            <script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
        </body>
    </html>
    <?php
} else {
    header("Location:" . Conexion::ruta() . "view/404/");
}
?>