<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <?php require '../../session.php';
        require '../../conexion.php';        
        require '../../menu/css_lte.ctp';
        ?>

    </head>
    <body class="hold-transition skin-blue sidebar-mini">
        <div class="wrapper">
            <?php require '../../menu/cabecera.ctp'; ?><!--BARRA DE HERRAMIENTAS-->
            <?php require '../../menu/izquierda.ctp'; ?><!--BARRA DE HERRAMIENTAS-->

            <div class="content-wrapper">
                <div class="content">
                    <div class="row">
                        <!--impresion del titulo de la pagina-->
                        <div class="col-lg-12 col-md-12 col-xs-12">
                            <h3 class="page-header">Listado de Usuarios
                                <a data-toggle="modal" data-target="#registrar" 
                                   class="btn btn-primary btn-circle pull-right" 
                                   rel="tooltip" data-title="Registrar">
                                    <i class="fa fa-plus"></i> AGREGAR
                                </a>                     
                            </h3>
                        </div>     
                        <!--Buscador-->
                        <div class="col-lg-12">
                            <div class="panel-heading">
                                <div class="input-group custom-search-form">
                                    <input id="filtrar" type="text" class="form-control" placeholder="Buscar...">
                                    <span class="input-group-btn">
                                        <button class="btn btn-primary" type="button" rel="tooltip" title="Buscar">
                                            <i class="fa fa-search"></i>
                                        </button>
                                    </span>
                                </div>
                            </div>                      
                        </div>
                        <!--fin Buscador-->
                    </div>
                    <!-- /.row -->
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="panel panel-default">
                                <div class="panel-heading">
                                    Datos
                                </div>
                                <?php
                                $usuarios = consultas::get_datos("select * from v_usuarios order by usu_cod asc ");
                                if (!empty($usuarios)) {
                                    ?>                         
                                    <!--fin-->
                                    <!-- /.panel-heading -->
                                    <div class="panel-body">
                                        <div>
                                            <table id="example1" width="100%" class="table table-striped table-bordered table-hover tablas">
                                                <thead>
                                                    <tr>
                                                        <th>#</th>
                                                        <th class="text-center">Nombres de Usuario</th>   
                                                        <th class="text-center">Nick</th>
                                                        <th class="text-center">Grupo</th>
                                                        <th class="text-center">Imagen</th>
                                                        <th class="text-center">Acciones</th>
                                                    </tr>
                                                </thead>
                                                <tbody class="buscar">
                                                    <?php foreach ($usuarios as $usuario) { ?> 
                                                        <tr>
                                                            <td><?php echo $usuario['usu_cod']; ?></td>
                                                            <td class="text-left"><?php echo $usuario['empleado']; ?></td>
                                                            <td class="text-center"><?php echo $usuario['usu_nick']; ?></td>
                                                            <td class="text-center"><?php echo $usuario['gru_nombre']; ?></td>
                                                            <td class="text-center">
                                                                <img height="45px" src="<?php echo $usuario['usu_foto']; ?>"/>
                                                            </td>
                                                            <td class="text-center">
                                                                <?php if($usuario['usu_estado']==="ACTIVO"){ ?>
                                                                <a href="/farmmedi/configuraciones/usuarios/paginas.php?vgrup=
                                                                   <?php echo $usuario['gru_cod'] . '&vgrunombre=' . $usuario['gru_nombre']; ?>"
                                                                   class="btn btn-sm btn-info" rel="tooltip" title="Permisos">
                                                                    <span class="glyphicon glyphicon-plus"></span>
                                                                </a>
                                                                <?php } ?>
                                                                <a onclick="borrar(<?php echo "'" . $usuario['usu_cod'] . "_" . $usuario['usu_nick'] . "'"; ?>)" class="btn btn-sm btn-<?php echo (($usuario['usu_estado']==="ACTIVO")?"danger":"success") ?>" 
                                                                   role="button" data-title="<?php echo (($usuario['usu_estado']==="ACTIVO")?"Inactivar":"Activar") ?>" data-placement="top" rel="tooltip" data-toggle="modal" data-target="#delete"><i class="<?php echo (($usuario['usu_estado']==="ACTIVO")?"fa fa-remove":"fa fa-check") ?>"></i></a>
                                                            </td>
                                                        </tr>
                                                    <?php } ?>
                                                </tbody>
                                            </table>                         
                                        </div>
                                    <?php } else { ?>
                                        <div class="alert alert-info alert-dismissable">
                                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                            <strong>No se encontraron registro....!</strong>
                                        </div>
                                    <?php } ?>  
                                </div>
                            </div>
                        </div>
                    </div>
                </div> 
            </div>
        </div>
        <?php require '../../menu/js_lte.ctp'; ?>
                    <!--Boton de Registrar-->
                    <div id="registrar" class="modal fade" role="dialog">
                        <div class="modal-dialog">
                            <!-- Modal content-->
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close"     
                                            data-dismiss="modal" arial-label="Close">x</button>
                                    <h4 class="modal-title"><i class="fa fa-plus"></i> <strong>Registrar Usuario</strong></h4>
                                </div>
                                <form action="usuarios_control.php" method="post" accept-charset="utf-8" class="form-horizontal">
                                    <div class="modal-body">
                                        <input type="hidden" name="accion"  value="1">
                                        <input type="hidden" name="idusuario" id="idusuario" value="0"/> 
                                        <input type="hidden" name="codsuc" value="<?php echo $_SESSION['cod_suc']; ?>">

                                        <div class="form-group">
                                            <label class="col-md-2 control-label">Empleado:</label>
                                            <div class="col-lg-8 col-md-8 col-sm-8">
                                                <?php $empleados = consultas::get_datos("SELECT * from v_empleados as emp where not exists (SELECT * from usuarios as u where emp.id_empleado=u.id_empleado);"); ?>                                 
                                                <select name="idempleado" class="select2 form-control" style="width: 100%">
                                                    <?php if (!empty($empleados)) {
                                                        foreach ($empleados as $empleado) { ?>
                                                            <option value="<?php echo $empleado['id_empleado']; ?>">
                                                                <?php echo $empleado['empleado']; ?></option>
                                                            <?php
                                                        }
                                                    } else {
                                                        ?>
                                                        <option value="1">Debe insertar un registro</option>
                                                    <?php } ?>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-md-2 col-sm-2 control-label">Grupo:</label>
                                            <div class="col-lg-8 col-md-8 col-sm-8">
                                                <?php $grupos = consultas::get_datos("select * from grupos where gru_nombre<>'ADMINISTRADOR' order by gru_cod"); ?>                                 
                                                <select name="idgrupo" class="form-control select2" style="width: 100%">
                                                    <?php if (!empty($grupos)) {
                                                        foreach ($grupos as $grupo) { ?>
                                                            <option value="<?php echo $grupo['gru_cod']; ?>">
                                                                <?php echo $grupo['gru_nombre']; ?></option>
                                                            <?php
                                                        }
                                                    } else {
                                                        ?>
                                                        <option value="1">Debe insertar un registro</option>
                                                    <?php } ?>
                                                </select> 
                                            </div>                                            
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-md-2 col-sm-2 control-label">Nick:</label>
                                            <div class="col-lg-6 col-md-6 col-sm-6">
                                                <input type="text" class="form-control" name="vnick" required="" minlength="6" 
                                                       placeholder="Nombre de usuario" 
                                                       pattern="[A-Za-z0-9-.]+">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-md-2 col-sm-2 control-label">Clave:</label>
                                            <div class="col-lg-6 col-md-6 col-sm-6">
                                                <input type="password" class="form-control" id="pass" minlength="8"
                                                       required="" placeholder="Digite contraseña">
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-2 col-md-2 col-sm-2 control-label">Repetir:</label>
                                            <div class="col-lg-6 col-md-6 col-sm-6">
                                                <input type="password" class="form-control" name="vclave" id="pass1" minlength="8" 
                                                       required="" placeholder="Repita la contraseña">
                                            </div>
                                        </div>                                        
                                    <div class="form-group">
                                        <label class="col-md-3 col-sm-3 col-lg-3 control-label">Requisitos Contraseña: </label>
                                        <div class="col-md-6 col-sm-6 col-lg-6">
                                            <span id="8char" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Un minimo de 8 car&aacute;cteres.<br>
                                            <span id="lcase" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Una letra min&uacute;scula.<br>
                                            <span id="ucase" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Una letra may&uacute;scula.<br>
                                            <span id="num" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> Un n&uacute;mero.<br>
                                            <span id="pwmatch" class="glyphicon glyphicon-remove" style="color:#FF0004;"></span> La contraseñas coinciden.<br>
                                        </div>
                                    </div>
                                    </div>

                                    <div class="modal-footer">
                                        <button type="reset" data-dismiss="modal" class="btn btn-default pull-left">
                                            <i class="fa fa-close"></i> Cerrar</button>
                                        <button type="submit" class="btn btn-primary pull-right" id="btn-guardar" disabled="">
                                            <i class="fa fa-floppy-o"></i> Registrar</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>  
                    <!--fin registrar-->
                    <!--borrar-->
                    <div class="modal fade" id="delete" tabindex="-1" role="dialog">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                    <h4 class="modal-title custom_align" id="Heading">Atenci&oacute;n!!!</h4>
                                </div>
                                <div class="modal-body">

                                    <div class="alert alert-info" id="confirmacion"></div>

                                </div>
                                <div class="modal-footer">
                                    <a id="si" role="button" class="btn btn-primary" ><span class="glyphicon glyphicon-ok-sign"></span> Si</a>
                                    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
                                </div>
                            </div>
                        </div>
                    </div> 
        <script>
            function borrar(datos) {
                var dat = datos.split("_");
                $('#si').attr('href', 'usuarios_control.php?idusuario=' + dat[0] +
                        '&idempleado=null' +
                        '&codsuc=null' +
                        '&vnick=' + dat[1] +
                        '&vclave=null' +
                        '&idgrupo=null' +
                        '&accion=3&pagina=usuarios_index.php');
                $('#confirmacion').html
                        ('<span class="glyphicon glyphicon-warning-sign"></span>\n\
                 Desea cambiar de estado al Usuario <i><strong>' + dat[1] + '</strong></i>?');
            };

            $("#mensaje").delay(2000).slideUp(200, function () {
                $(this).alert('close');
            })
        </script>
<script>
    $("input[type=password]").keyup(function () {
        var ucase = new RegExp("[A-Z]+");
        var lcase = new RegExp("[a-z]+");
        var num = new RegExp("[0-9]+");
        var valido = true;

        if ($("#pass").val().length >= 8) {
            $("#8char").removeClass("glyphicon-remove");
            $("#8char").addClass("glyphicon-ok");
            $("#8char").css("color", "#00A41E");
            valido = true;
        } else {
            $("#8char").removeClass("glyphicon-ok");
            $("#8char").addClass("glyphicon-remove");
            $("#8char").css("color", "#FF0004");
            valido = false;
        }

        if (ucase.test($("#pass").val())) {
            $("#ucase").removeClass("glyphicon-remove");
            $("#ucase").addClass("glyphicon-ok");
            $("#ucase").css("color", "#00A41E");
            valido = true;
        } else {
            $("#ucase").removeClass("glyphicon-ok");
            $("#ucase").addClass("glyphicon-remove");
            $("#ucase").css("color", "#FF0004");
            valido = false;
        }

        if (lcase.test($("#pass").val())) {
            $("#lcase").removeClass("glyphicon-remove");
            $("#lcase").addClass("glyphicon-ok");
            $("#lcase").css("color", "#00A41E");
            valido = true;
        } else {
            $("#lcase").removeClass("glyphicon-ok");
            $("#lcase").addClass("glyphicon-remove");
            $("#lcase").css("color", "#FF0004");
            valido = false;
        }

        if (num.test($("#pass").val())) {
            $("#num").removeClass("glyphicon-remove");
            $("#num").addClass("glyphicon-ok");
            $("#num").css("color", "#00A41E");
            valido = true;
        } else {
            $("#num").removeClass("glyphicon-ok");
            $("#num").addClass("glyphicon-remove");
            $("#num").css("color", "#FF0004");
            valido = false;
        }

        if (($("#pass").val() === $("#pass1").val()) && $("#pass").val().length>0) {
            $("#pwmatch").removeClass("glyphicon-remove");
            $("#pwmatch").addClass("glyphicon-ok");
            $("#pwmatch").css("color", "#00A41E");
            valido = true;
            
        } else {
            $("#pwmatch").removeClass("glyphicon-ok");
            $("#pwmatch").addClass("glyphicon-remove");
            $("#pwmatch").css("color", "#FF0004");
            valido = false;            
        }
        if(valido){
            $("#btn-guardar").prop("disabled", false);
        }else{
            $("#btn-guardar").prop("disabled", true);
        }
    });
</script>
    </body>
</html>
