<?php
  defined('BASEPATH') or exit('No direct script access allowed');
  
  ?>
<div class="content-wrapper" style="overflow-y: scroll;">
  <section class="content-header">
    <?php echo $pagetitle; ?>
    <?php echo $breadcrumb; ?>
  </section>
  <section class="content">
    <div class="row">
      <div class="filterable">
        <div class="col-md-12">
          <div class="box">
            <div class="box-body">
              <?php
                if (!empty($message)) {
                    echo '<pre>';
                    echo '<b>'.$message.'</b>';
                    echo '</pre>';
                }
                ?>
              <?php if ($habilitado_gen or $habilitado_sis) : ?>
              <div class="panel panel-default">
                <div class="panel-body">
                  <?php echo anchor('expedientes/expedientes/create', 'Crear expediente', array('class' => 'btn btn-alert')); ?>
                </div>
              </div>
              <?php endif; ?>
              <div class="panel panel-default">
                <div class="panel-body">
                  <div style="overflow-y: visible;">
                    <table id="tabla_expedientes" class="table table-striped table-hover" style="width: 100%;">
                      <thead>
                        <tr class="colorMOPC">
                          <?php if ($habilitado_sis) : ?>
                          <th><?php echo lang('expedientes_id');?></th>
                          <?php endif  ?>
                          <th><?php echo lang('expedientes_codigo_unico');?></th>
                          <!-- <th><?php echo lang('expedientes_codigo_dbi');?></th> -->
                          <th><?php echo lang('expedientes_estado');?></th>
                          <th><?php echo lang('expedientes_distrito');?></th>
                          <th><?php echo lang('expedientes_tramo');?></th>
                          <th><?php echo lang('expedientes_franja');?></th>
                          <th><?php echo lang('expedientes_tipo_afectacion');?></th>
                          <th><?php echo lang('expedientes_nombre_y_apellido');?></th>
                          <th><?php echo lang('expedientes_meu');?></th>
                          <th><?php echo anchor('expedientes/expedientes/reset_busqueda/', '<i title="Limpiar busqueda" class="glyphicon glyphicon-refresh btn btn-primary"></i>'); ?>
                        </tr>
                        <tr>
                          <?php echo form_open(current_url(), array('class' => 'form-horizontal', 'id' => 'form-create_expedientes')); ?>
                          <?php if ($habilitado_sis) : ?>
                          <th>
                            <input id="id" name="id" type="text" class="form-control"
                              placeholder="<?php echo lang('expedientes_id');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['id'])) {
                                echo $_SESSION['arraywhere_expedientes']['id'];
                                    } else {
                                        echo '';
                                    } ?>"
                              enable autofocus maxlength="10">
                          </th>
                          <?php endif  ?>
                          <th>
                            <input id="des_codigo_unico" name="des_codigo_unico" type="text" class="form-control"
                              placeholder="<?php echo lang('expedientes_codigo');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['des_codigo_unico'])) {
                                echo $_SESSION['arraywhere_expedientes']['des_codigo_unico'];
                                } else {
                                    echo '';
                                } ?>"
                              enable>
                          </th>
                          <!-- <th>
                            <input id="codigo_dbi" name="codigo_dbi" type="text" class="form-control"
                                placeholder="<?php echo lang('expedientes_codigo_dbi');?>"
                                value="<?php if (isset($_SESSION['arraywhere_expedientes']['codigo_dbi'])) {
                              echo $_SESSION['arraywhere_expedientes']['codigo_dbi'];
                              } else {
                                  echo '';
                              } ?>"
                                enable>
                            </th> -->
                          <th>
                            <input id="seg_estado" name="seg_estado" type="text" class="form-control"
                              placeholder="<?php echo lang('expedientes_estado');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['seg_estado'])) {
                                echo $_SESSION['arraywhere_expedientes']['seg_estado'];
                                    } else {
                                        echo '';
                                    } ?>"
                              enable>
                          </th>
                          <th>
                            <input id="distrito" name="distrito" type="text" class="form-control"
                              placeholder="<?php echo lang('expedientes_distrito');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['des_distrito'])) {
                                echo $_SESSION['arraywhere_expedientes']['des_distrito'];
                                    } else {
                                        echo '';
                                    } ?>"
                              enable>
                          </th>
                          <th>
                            <input id="tramo" name="tramo" type="text" class="form-control"
                              placeholder="<?php echo lang('expedientes_tramo');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['des_tramo'])) {
                                echo $_SESSION['arraywhere_expedientes']['des_tramo'];
                                    } else {
                                        echo '';
                                    } ?>"
                              enable>
                          </th>
                          <th><input id="franja_dominio" name="franja_dominio" type="text" class="form-control"
                            placeholder="<?php echo lang('expedientes_franja');?>"
                            value="<?php if (isset($_SESSION['arraywhere_expedientes']['franja_dominio'])) {
                              echo $_SESSION['arraywhere_expedientes']['franja_dominio'];
                              } else {
                                  echo '';
                              } ?>"
                            enable>
                          </th>
                          <th><input id="tipo_afectacion" name="tipo_afectacion" type="text" class="form-control"
                            placeholder="<?php echo lang('expedientes_tipo_afectacion');?>"
                            value="<?php if (isset($_SESSION['arraywhere_expedientes']['des_tipo_afectacion'])) {
                              echo $_SESSION['arraywhere_expedientes']['des_tipo_afectacion'];
                                  } else {
                                      echo '';
                                  } ?>"
                            enable></th>
                          <th><input id="nombre_completo" name="nombre_completo" type="text" class="form-control"
                            placeholder="<?php echo lang('expedientes_nombre_y_apellido');?>"
                            value="<?php if (isset($_SESSION['arraywhere_expedientes']['nombre_completo'])) {
                              echo $_SESSION['arraywhere_expedientes']['nombre_completo'];
                                  } else {
                                      echo '';
                                  } ?>"
                            enable></th>
                          <th>
                            <input id="codigo_meu" name="codigo_meu" type="number" max="999999" min="0"
                              class="form-control" placeholder="<?php echo lang('expedientes_meu');?>"
                              value="<?php if (isset($_SESSION['arraywhere_expedientes']['codigo_meu'])) {
                                echo $_SESSION['arraywhere_expedientes']['codigo_meu'];
                                } else {
                                    echo '';
                                } ?>"
                              enable>
                          </th>
                          <th><?php echo form_button(array('type' => 'submit', 'class' => 'btn btn-primary', 'content' => ' Buscar Exp. ', 'id' => 'boton', 'style' => 'padding: 3px;'));?>
                          </th>
                          <!-- <th><input id="expe_entrada" name="expe_entrada" type="text" class="form-control"
                            placeholder="<?php echo lang('expedientes_expe_entrada');?>"
                            value="<?php if (isset($_SESSION['arraywhere_expedientes']['expe_entrada'])) {
                              echo $_SESSION['arraywhere_expedientes']['expe_entrada'];
                                  } else {
                                      echo '';
                                  } ?>"
                            enable data-provide="datepicker" data-date-format="yyyy-mm-dd"></th> -->
                          <!-- <th><input id="expe_salida" name="expe_salida" type="text" class="form-control"
                            placeholder="<?php echo lang('expedientes_expe_salida');?>"
                            value="<?php if (isset($_SESSION['arraywhere_expedientes']['expe_salida'])) {
                              echo $_SESSION['arraywhere_expedientes']['expe_salida'];
                                  } else {
                                      echo '';
                                  } ?>"
                            enable data-provide="datepicker"></th> -->
                          <?php echo form_close();?>
                        </tr>
                      </thead>
                      <tbody class="muestra_expedientes">
                        <?php
                          $i = 0;
                          if (isset($expedientes)) : ?>
                        <?php foreach ($expedientes as $values) :
                          $i = $i + 1;
                          ?>
                        <tr>
                          <?php if ($habilitado_sis) : ?>
                          <td><?php echo htmlspecialchars($values->id, ENT_QUOTES, 'UTF-8'); ?></td>
                          <?php endif ?>
                          <td><?php echo htmlspecialchars($values->des_codigo_unico, ENT_QUOTES, 'UTF-8'); ?></td>
                          <!-- <td><?php echo htmlspecialchars($values->codigo_dbi, ENT_QUOTES, 'UTF-8'); ?></td> -->
                          <td><?php echo htmlspecialchars($values->seg_estado, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->des_distrito, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->des_tramo, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->franja_dominio, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->des_tipo_afectacion, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->nombre_completo, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td><?php echo htmlspecialchars($values->codigo_meu, ENT_QUOTES, 'UTF-8'); ?></td>
                          <td>
                            <?php //if ($values->existe_poligono == 0): ?>
                            <!--a href="#" id='vergrafico' onclick="return false">
                              <i title="Sin gráfico" class="fa fa-map btn btn-xs bg-gray color-palette"></i>
                              </a-->
                            <?php //endif ?>
                            <?php //if (grupo_usuario(3) || $values->existe_poligono > 0)  { 
                              //echo anchor('expedientes/mantenimiento/vergrafico/'.$values->codigo, '<i title="Ver Terreno" class="fa fa-info-circle btn btn-xs bg-red color-palette"></i>',array('disabled' => TRUE)); 
                              // }
                              ?> 
                            <?php //echo '&nbsp;';?>
                            <div class="btn-group">
                              <button type="button" class="btn btn-flat dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Acciones<span class="caret"></span>
                              </button>
                              <div class="dropdown-menu pull-right">
                                <table class="tablaCentrada"  style="width: 100%;">
                                  <tbody>
                                    <tr>
                                      <td><?php echo anchor('expedientes/mantenimiento/vergrafico/'.$values->codigo.'/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Ver Terreno</button>'); ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php echo anchor('expedientes/expedientes/ver_exp/'.$values->id, '<button title="Ver Expediente" class="btn btn-xs btn-primary" style="width:100%;">Ver expediente</button>', array('disabled' => true)); ?></td>
                                    </tr>
                                    <?php if ($habilitado_gen or $habilitado_sis) : ?>
                                    <tr>
                                      <td>
                                        <?php
                                          echo anchor('expedientes/expedientes/edit_expe/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Editar expediente</button>');
                                          
                                          ?>
                                      </td>
                                    </tr>
                                    <?php endif; ?>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_ubi['sup'] or $habilitado_ubi['op'] or $habilitado_coor or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/edit_expe_ubi/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">UBI</button>');
                                        }
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_dao['sup'] or $habilitado_dao['op'] or $habilitado_coor or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/edit_expe_dao/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">DAO</button>');
                                        }
                                            
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_daj['sup'] or $habilitado_daj['op'] or $habilitado_coor or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/edit_expe_daj/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">DAJ</button>');
                                        }
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_dao['sup'] or $habilitado_dao['op'] or $habilitado_coor or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/seg_dao/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Seguimiento DAO</button>');
                                        }
                                            
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_daj['sup'] or $habilitado_daj['op'] or $habilitado_coor or $habilitado_coor_daj or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/seg_daj/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Seguimiento DAJ</button>');
                                        }
                                            
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php
                                        if ($habilitado_finan or $habilitado_coor or $habilitado_sis) {
                                            echo anchor('expedientes/expedientes/seg_financiero/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Seguimiento financiero</button>');
                                        }
                                            
                                        ?></td>
                                    </tr>
                                    <tr>
                                      <td><?php if ($habilitado_ubi['sup'] or $habilitado_coor or $habilitado_sis) {
                                        echo anchor('expedientes/mantenimiento/expe_mantenimiento/'.$values->id, '<button class="btn btn-xs btn-primary" style="width:100%;">Gestion Espacial</button>');
                                        }
                                        ?></td>
                                    </tr>
                                    <?php if ($habilitado_coor or $habilitado_sis) : ?>
                                    <tr>
                                      <td>
                                        <button type="button" class="btn btn-xs btn-primary" data-toggle="modal" data-target="#modalEliminar" style="width:100%;">Eliminar expediente</button>
                                      </td>
                                    </tr>
                                    <?php endif ?>
                                  </tbody>
                                </table>
                              </div>
                            </div>
                          </td>
                        </tr>
                        <div class="modal fade" id="modalEliminar" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                          <div class="modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="box box-option">
                                <div class="modal-header">
                                  <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                  <h4 class="modal-title" id="myModalLabel">Eliminar expediente</h4>
                                </div>
                                <div class="modal-body">
                                  ¿Está seguro que desea eliminar el expediente?
                                </div>
                                <div class="modal-footer">
                                  <button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
                                  <?php echo anchor('expedientes/expedientes/delete/'.$values->id, '<i class="btn btn-danger ">Eliminar</i>'); ?>
                                </div>
                              </div>
                            </div>
                          </div>
                        </div>
                        <?php endforeach;?>
                        <?php else : ?>
                        <tr>
                          <td align="center" colspan="12"><b>No hay resultados</b></td>
                        </tr>
                        <?php endif ?>
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
              <?php echo $pagination; ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </section>
</div>