<?php
$page_title = 'Listado de Abastecimiento';
require_once('../../includes/load.php');
// Checkin What level user has permission to view this page
page_require_level(5);
?>
<?php include_once('../../layouts/header.php'); ?>
<div class="row">
 <div class="col-md-12">
   <?php echo display_msg($msg); ?>
 </div>
<div class="col-md-16">
  <div class="panel panel-default">
    <div class="panel-heading clearfix">
        <strong>
          <span class="glyphicon glyphicon-th-list"></span>
          <span>Listado de Abastecimiento</span> 
        </strong>
        <div class="pull-right">
            <a href="abastecimiento.php" class="btn btn-primary" id="abastecimiento" ><i class="glyphicon glyphicon-plus"></i>Abastecimiento</a>
        </div>
    </div>
    <div class="col-12">          
                <div class="panel-body">
                <table class="table table-bordered table-striped"  id="mytable">
                    <thead>
                        <tr>
                            <th style="text-align: center; padding-right: 10px;">Id</th>
                            <th style="text-align: center; padding-right: 10px;">Id P</th>
                            <th style="text-align: center; padding-right: 10px;">Galones</th>
                            <th style="text-align: center; padding-right: 10px;">Fecha Inicio</th>
                            <th style="text-align: center; padding-right: 10px;">Fecha Final</th>
                            <th style="text-align: center; padding-right: 10px;">Responsable</th>
                            <th style="text-align: center; padding-right: 10px;">Estado</th>
                            <th style="text-align: center; padding-right: 10px;">Opciones</th>
                        </tr>
                    </thead>
                </table>
            </div>
    </div>
  </div>
</div>
</div>
<?php include_once('../../layouts/footer.php'); ?>
<script>
$( document ).ready(function() {
var user_level = '<?= remove_junk($user['user_level'])?>';
var table = $('#mytable').dataTable({
          responsive: true,
          deferRender: true,
          columnDefs: [{
                "defaultContent": "-",
                "targets": "_all"
              }],
          dom: '<"row"<"col-sm-12 col-md-4"l><"col-sm-12 col-md-4"<"dt-buttons btn-group flex-wrap"B>><"col-sm-12 col-md-4"f>>t<"row"<"col-sm-12 col-md-6"i><"col-sm-12 col-md-6"p>>',
              buttons: [
                'copyHtml5',
                'excelHtml5',
                'csvHtml5',
             ],
         "autoWidth": false,
         "bProcessing": true,
         "aLengthMenu": [[7, 10, 25, 50, -1], [7, 10, 25, 50, "All"]],
         "language":{
            "lengthMenu": "Mostrar _MENU_ registros por pagina",
            "info": "Mostrando pagina _PAGE_ de _PAGES_",
            "infoEmpty": "No hay registros disponibles",
            "infoFiltered": "(filtrada de _MAX_ registros)",
            "loadingRecords": "Cargando...",
            "processing":     "Procesando...",
            "search": "Buscar:",
            "zeroRecords":    "No se encontraron registros coincidentes",
            "paginate": {
                "next":       "Siguiente",
                "previous":   "Anterior"
            },  
         },
         "sAjaxSource": "data/data.php",
          "bPaginate":true,
          "iDisplayLength": 7,
          "order": [[0, "ASC"]],
         "aoColumns": [
                { mData:'id'},
                { mData:'idproyeccion'}, 
                { mData:'GalonesIngresado'},
                { mData:'FechaInicioAbastecimiento'},
                { mData:'FechaFinalAbastecimiento'},
                { mData:'NombreResponsableAbastecimiento'},  
                { mData:'EstadoAbastecimiento'},
                { 
                   "render": function (data, type, full, row) {
                        if ( user_level === '2' || user_level === '3'  || user_level === '4'  || user_level === '5') {
                            return '<center><a style="margin-right: 3pt" href="view_abastecimiento.php?id='+ full.id +'" class="btn btn-xs btn-warning" title="Ver"><span class="glyphicon glyphicon-eye-open"></span></a></center>';
                        }
                        else{
                            return '<center><a style="margin-right: 3pt" href="data/cambiarEstado.php?id='+ full.id +'" class="btn btn-xs btn-primary confirmEstado"  title="Estado"><span class="glyphicon glyphicon-ok"></span></a>         <a style="margin-right: 3pt" href="view_abastecimiento.php?id='+ full.id +'" class="btn btn-xs btn-warning" title="Ver"><span class="glyphicon glyphicon-eye-open"></span></a></center>';
                        }
                             
                                                    
                   }

                }    
                           
        ]


}); 

});


 //VISUALIZAR CAMPOS DEPENDIENDO AL USUARIO QUE ENTRA 
 var abastecimiento = document.getElementById("abastecimiento");

 var user_level = '<?= remove_junk($user['user_level'])?>';

 if ( user_level === '2' || user_level === '3'  || user_level === '4'  || user_level === '5') {
// O bien, para esconderlo
abastecimiento.style.display = "none";
 }
</script>