<?php
  $Seccion    = 'Cursos';
  $Position   = '../../';
  $SecLine      = array('Cursos', 'Categorías');
  require_once($Position.'config/config.php');
  require_once($Position.'config/conexion.php');
  require_once($Position.'config/user.php');
  require_once($Position.'funciones/acces.php');
  require_once($Position.'funciones/logout.php');
  require_once($Position.'funciones/funciones.php');
  require_once($Position.'funciones/extras.php');


  //Eliminar Administrador
  if( $_POST['Borrar']=='Ok' ){
    $Id = $_POST['Id'];
    $Query = "
      DELETE FROM CMS_CrusosCategorias WHERE Id = '$Id'
    ";
    $Result = mysqli_query($mysqli, $Query);
  }

  //Categorias
  $Query = "
    SELECT
      cat.Id,
      cat.Nombre
    FROM CMS_CrusosCategorias cat
    ORDER BY cat.Nombre
  ";
  $Cats = $mysqli->query($Query);
?>

<!DOCTYPE html>
<html lang="en">

<?php require_once($Position.'head.php'); ?>

<body class="fix-sidebar fix-header card-no-border">
    <div class="preloader">
        <svg class="circular" viewBox="25 25 50 50">
            <circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10" /> </svg>
    </div>
    <div id="main-wrapper">
      <?php require_once($Position.'header.php'); ?>
      <?php require_once($Position.'menu.php'); ?>
      <div class="page-wrapper">
        <div class="container-fluid">
          <div class="row page-titles">

            <?php require_once($Position.'title.php'); ?>

            <!-- Botones -->
            <div class="col-md-7 align-self-center text-right">
              <div class="btn-group" role="group" aria-label="Basic example">
                <?php if( $Perms[2] ){ ?>
                  <a href="item">
                    <button type="button" class="btn btn-sm btn-secondary">
                      Nuevo
                      <i class="fa fa-plus mar-l-10"></i>
                    </button>
                  </a>
                <?php } ?>
              </div>
            </div>
            <!-- End Botones -->

          </div>
          <div class="row">
              <div class="col-12">
                <!-- Usuarios -->
                <div class="card">
                  <div class="card-body">
                    <h4 class="card-title">Listado de Categorias</h4>
                    <div class="table-responsive m-t-20">
                      <table id="example23" class="display nowrap table table-hover table-striped table-bordered" cellspacing="0" width="100%">
                        <thead>
                          <tr>
                            <!-- <th width="20">Id</th> -->
                            <th>Nombre</th>
                            <th width="20"></th>
                            <th width="20"></th>
                          </tr>
                        </thead>
                        <tbody>
                            <?php
                              mysqli_data_seek($Cats, 0);
                              while($Cat = mysqli_fetch_array($Cats)) {
                            ?>
                              <tr>

                                <!-- Id -->
                                <!-- <td>
                                  <?php echo $Cat['Id'];?>
                                </td> -->
                                <!-- End Id -->

                                <!-- Nombre -->
                                <td>
                                  <div><?php echo $Cat['Nombre']; ?></div>
                                </td>
                                <!-- End Nombre -->

                                <!-- Editar -->
                                <td>
                                  <?php if( $Perms[3] ){ ?>
                                    <a href="item?Id=<?php echo $Cat['Id']; ?>">
                                      <button class="btn btn-secondary btn-sm" data-toggle="tooltip" data-placement="top" title="" data-original-title="Editar">
                                        Editar<i class="fa fa-pencil m-l-10"></i>
                                      </button>
                                    </a>
                                  <?php } ?>
                                </td>
                                <!-- Ebd Editar -->

                                <!-- Eliminar -->
                                <td>
                                  <?php if( $Perms[4] ){ ?>
                                    <a data-toggle="modal" href="#Borrar<?php echo $Cat[Id];?>">
                                      <button class="btn btn-danger btn-sm ml-2" data-toggle="tooltip" data-placement="top"  title="Eliminar" data-original-title="Eliminar">
                                      <i class="fa fa-times"></i></button>
                                    </a>

                                    <!--Modal Eliminar-->
                                    <form method="POST">
                                      <div id="Borrar<?php echo $Cat[Id];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                                        <div class="modal-dialog">
                                          <div class="modal-content">
                                            <div class="modal-header">
                                              <h4 class="modal-title">Eliminar Categoría</h4>
                                              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            </div>
                                            <div class="modal-body p-4">
                                              <div class="row">
                                                <div class="col-md-12">
                                                  <p>¿Desea eliminar esté categoría?</p>
                                                  <?php echo $Cat['Nombre'];?>
                                                </div>
                                              </div>
                                            </div>
                                            <div class="modal-footer">
                                                <input name="Borrar"   type="hidden" value="Ok">
                                                <input name="Id" type="hidden" value="<?php echo $Cat[Id];?>">
                                                <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Cancelar</button>
                                                <button type="submit" class="btn btn-danger waves-effect waves-light">Eliminar</button>
                                              </div>
                                          </div>
                                        </div>
                                      </div>
                                    </form>
                                    <!-- End Modal Eliminar-->
                                  <?php } ?>
                                </td>
                                <!-- End Eliminar -->

                              </tr>
                            <?php } ?>
                          </tbody>
                      </table>
                    </div>
                  </div>
                </div>
                <!-- End Usuarios -->
              </div>
            </div>
        </div>
        <?php require_once($Position.'footer.php'); ?>
      </div>
    </div>
    <?php require_once($Position.'scripts.php'); ?>
    <script>

    </script>
    <script src="<?php echo $Position; ?>assets/plugins/styleswitcher/jQuery.style.switcher.js"></script>

</body>
</html>
