<?php
  $page_title = 'Lista de Operaciones';
  require_once('../../includes/load.php');
?>
<?php
// Checkin What level user has permission to view this page
 page_require_level(5);
//pull out all user form database
 $all_users = find_all_user();
?>
<?php include_once('../../layouts/header.php'); ?>
<div class="row">
   <div class="col-md-12">
     <?php echo display_msg($msg); ?>
   </div>
</div>
<div class="row">
  <div class="col-md-12">
    <div class="panel panel-default">
      <div class="panel-heading clearfix">
        <div class="pull">
        <strong>
          <span class="glyphicon glyphicon-th-list"></span>
          <span>Listado de Operaciones</span>
       </strong>
       </div> 
        <div class="pull-right">  
          <a href="operacion.php" class="btn btn-primary" id="operacion"><i class="glyphicon glyphicon-plus"></i> Operación</a>
          <a href="../reportes/indicador.php" class="btn btn-success"><i class="fi fi-sr-pennant"></i> Ind. PSP</a>
          <a href="../reportes/operaciones.php" class="btn btn-success"><i class="fi fi-sr-traffic-light"></i> Ind. Redondos </a>
          <a href="../reportes/actividad.php" class="btn btn-success"><i class="fi fi-sr-rectangle-list"></i> Lst. de Actividad </a>
          <a href="../reportes/granjasoperacion.php" class="btn btn-success"><i class="fi fi-sr-farm"></i> Granjas Cerradas </a>
        </div>
      </div>
     <div class="panel-body">
      <table class="table table-bordered table-striped" id="mytable">
        <thead>
          <tr>
            <th>ID </th>
            <th>Pro</th>
            <th style="text-align: center; padding-right: 10px;">Area</th>
            <th style="text-align: center; padding-right: 10px;">Registro</th>
            <th style="text-align: center; padding-right: 10px;">Campaña</th>
            <th style="text-align: center; padding-right: 10px;">Reuso</th>
            <th style="text-align: center; padding-right: 10px;">Granja</th>
            <th style="text-align: center; padding-right: 10px;">Destino</th>
            <th style="text-align: center; padding-right: 10px;">Servicio</th>
            <th style="text-align: center; padding-right: 10px;">Estado</th>
            <th style="text-align: center; padding-right: 10px;">Opcion</th>
          </tr>
        </thead>
     </table>
     </div>
    </div>
  </div>
</div>
  <?php include_once('../../layouts/footer.php'); ?>

<script type="text/javascript">
$( 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:'idOperacion'},
                { mData:'id'}, 
                { mData:'NombreAreaGerenciaOperaciones'},
                { mData:'FechaRegistroOperacion'},
                { mData:'Campana'},
                { mData:'Reuso'}, 
                { mData:'GNombre'}, 
                { mData:'TipoGranja'},
                { mData:'TSNombre'}, 
                { mData:'Estado'}, 
                { 
                   "render": function (data, type, full, row) {
                        if ( user_level === '2' || user_level === '3') {
                            return '<center><a style="margin-right: 3pt" href="view_operacion.php?id='+ full.idOperacion +'" class="btn btn-xs btn-warning"  title="Ver"><span class="glyphicon glyphicon-eye-open"></span></a></center>';
                        }

                        if (full['Estado'] === 'Proceso') {
                            return '<center><a style="margin-right: 3pt" href="../actividad/actividad.php?id='+ full.idOperacion +'" class="btn btn-xs btn-success" title="Agregar Recursos"><span class="glyphicon glyphicon-plus"></span></a>    <a style="margin-right: 3pt" href="edit_operacion.php?id='+ full.idOperacion +'" class="btn btn-xs btn-danger confirmEditar"  title="Editar"><span class="glyphicon glyphicon-pencil"></span></a> </center>'; 

                        }
                        else{
                            return '<center><a style="margin-right: 3pt" href="view_operacion.php?id='+ full.idOperacion +'" 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 operacion = document.getElementById("operacion");

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

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