<div class="row">
    <div class="col-lg-12">
        <ol class="breadcrumb">
            <?php      
            $currentAction = '';
            $agregarNuevo = '';
            if($action =='edit'){ 
                $userAction = $_translator->_getTranslation('Editar Usuario');
                $currentAction = "<li class='active'><i class='fa fa-pencil'></i> ".$_translator->_getTranslation('Editar')."</li>";
                $agregarNuevo = "<a href='User.php' class='btn btn-sm btn-default'><i class='fa fa-plus'></i> ".$_translator->_getTranslation('Agregar usuario')."</a>";
                $agregarNuevo .= '<hr>';
            }elseif($action =='' || $action =='insert'){
                $userAction = 'Agregar Usuario ';
                $currentAction = "<li class='active'><i class='fa fa-plus'></i> ".$_translator->_getTranslation('Agregar')."</li>";
            } ?>
            <li><i class="fa fa-dashboard"></i>  <a href="<?php echo ROOT_HOST?>/Controller/Home.php"><?php echo $_translator->_getTranslation('Home')?></a></li>
            <li class="active"><i class="fa fa-user"></i> <?php echo $_translator->_getTranslation('Usuarios')?></li>
            <?php echo $currentAction?>
        </ol>
    </div>
</div>
<div class="row">
    <div class="col-lg-12">
        <div id="flashmessenger"><?php $flashmessenger->showMessage();?></div>
        <div class="box">
            <div class="box-header"> 
                <h3><i class='fa-fw fa fa-user'></i><?php echo $_translator->_getTranslation($userAction);?></h3>
                <div class='box-icon'><i class='icon fa fa-tasks'></i></div>
            </div>
            <div class='box-content'>
                <div class="row">
                    <div class="col-md-12 col-xs-12 text-right">
                        <?php echo $agregarNuevo;?>                        
                        <div class="clear"></div>
                    </div> 
                    <?php 
                    echo $form->openForm();
                    echo $form->showActionController();
                    echo $form->showId();
                    ?>
                    <div class="col-md-11">
                        <?php echo $form->showElement('usuario');?>
                        <?php echo $form->showElement('contrasena');?>
                        <?php echo $form->showElement('nip');?>
                        <?php // echo $form->showElement('confirmar_nip');?>
                        <?php echo $form->showElement('nombre');?>
                        <?php echo $form->showElement('apellido');?>
                        <?php echo $form->showElement('role');?>
                        <?php echo $form->showElement('sucursal');?>
                         <?php echo $form->showElement('acceso_movil');?>
                        <?php echo $form->showElement('status');?>
                        <div class="form-group">
                            <div class="col-md-3"></div>
                            <div class="col-md-8 p-r-0 text-right">
                                <?php $element = $form->getElement('send'); echo $form->createOnlyElement($element);?>
                                <?php $element = $form->getElement('cancelar'); echo $form->createOnlyElement($element);?>                               
                            </div>
                        </div>
                    </div>      
                    <?php echo $form->closeForm();?>
                </div>
                <div class="row">
                    <div class="col-lg-12">
                        <h3>Lista usuarios</h3>
                        <hr/>
                        <div class='table-responsive'>
                        <table id="tblUsuarios" class="table table-striped table-hover table-condensed">
                            <thead>
                                <th class="text-center col-md-1">Accion</th>
                                <th class="text-center">Usuario</th>
                                <th class="text-center">Nombre</th>
                                <th class="text-center">Apellido</th>
                                <th class="text-center">Rol</th>
                                <th class="text-center">Status</th>
                            </thead>
                            <tfoot>
                                <th></th>
                                <th class="filter"><?php echo $_translator->_getTranslation('Usuario');?></th>                     
                                <th class="filter"><?php echo $_translator->_getTranslation('Nombre');?></th>
                                <th class="filter"><?php echo $_translator->_getTranslation('Apellido');?></th>
                                <th class="filter"><?php echo $_translator->_getTranslation('Rol');?></th>
                                <th class="filter"><?php echo $_translator->_getTranslation('Status');?></th>
                            </tfoot>
                            <tbody>
                            <?php 
                                if($_listaUsuarios){
                                    foreach($_listaUsuarios as $usuario){?>
                                        <tr>
                                            <td>
                                                <a href="User.php?action=edit&id=<?php echo $usuario['id']?>"><i class="fa fa-pencil btn btn-sm btn-default"></i></a>                                                
                                                <a title="<?php echo $_translator->_getTranslation('Cancelar');?>" onclick="return deleteRegistry('User.php?action=delete&id=<?php echo $usuario['id']?>')" 
                                                   href="#"><i class="fa fa-ban btn btn-sm btn-danger"></i></a>
                                            </td>
                                            <td class="text-center"><?php echo $usuario['usuario']?></td>
                                            <td class="text-center"><?php echo $usuario['nombre']?></td>
                                            <td class="text-center"><?php echo $usuario['apellido']?></td>
                                            <td class="text-center"><?php echo $usuario['roleNombre']?></td>
                                            <td class="text-center"><?php echo $usuario['statusNombre']?></td>
                                        </tr><?php
                                    }                   
                                }?>
                            </tbody>
                        </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    tfoot {
    display: table-header-group;
}
</style>

<script type="text/javascript">
    $('#role,#sucursal,#status').select2();
    
    $('#tblUsuarios').DataTable({
        paginate:true,
        filter:true,
        pageLength: 100
    });
    
    $('#tblUsuarios')
            .removeClass( 'display' )
            .addClass('table table-striped table-bordered');
    
    $('#tblUsuarios tfoot th.filter').each( function () {
        var title = $(this).text();
        $(this).html( '<input type="text" placeholder="Buscar" style="width:100%" />' );
    } );  
 
    var table = $('#tblUsuarios').DataTable();
    // Apply the search
    table.columns().every( function () {
        var that = this; 
        $( 'input', this.footer() ).on( 'keyup change', function () {
            if ( that.search() !== this.value ) {
                that
                    .search (this.value.replace("/;/g", "|"), true, false)
                    .draw();
            }
        } );
    } );
</script>