<?php
  session_start();
  ob_start();
  include_once('../php/seguranca.php');
  include_once('../php/Repositorio/BuscaGrupos.php');
  $consulta = new GerenciadorGrupos();

  // Busque os dados do banco de dados
  $dados = $consulta->buscarGrupo();
?>
<!DOCTYPE html>
<html lang="pt-br" translate="yes">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Control DB - Intersolid ERP </title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- DataTables -->
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Content Wrapper. Contains page content -->
  <div class="content">
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <!-- /.card -->

            <div class="card">
              <!-- /.card-header -->
              <div class="card-header">
                <br>
                <h3 class="card-title">Configuração de Grupos</h3>
                <br>
                 <div style="width: 300px; height: 50px;">
                    <a href = "CadastroGrupoAcesso.php?idgrupo=0"><button type="button" class="btn btn-block btn-success">Incluir</button></a>
                </div>

              </div>
              <div class="card-body">
                <table id="Listagem" class="table table-bordered table-striped">
                  <thead>
                  <tr>
                    <th>Grupo</th>
                    <th>Editar</th>
                    <th>Excluir</th>
                    <th>Tabela/Constraint</th>
                    <th>View</th>
                    <th>Sequence</th>
                    <th>Procedure/Functions</th>
                    <th>Trigger</th>
                    <th>Indice</th>
                  </tr>
                  </thead>
                  <tbody>
                    <tr>
                    <?php
                        foreach($dados as $dado){
                          echo "<td style='text-align: center; vertical-align: middle;'>".$dado['descricao']."</td>";
                          echo "<td style='text-align: center; vertical-align: middle;'><a href='CadastroGrupoAcesso.php?idgrupo=".$dado['IdGrupo']."'><button type='button' class='btn btn-block btn-warning'>Editar</button></a></td>";
                          echo "<td style='text-align: center; vertical-align: middle;'><a href='#'><button type='submit' class='btn btn-block btn-danger'>Excluir</button></a></td>";
                          /*echo '<td>
                                  <form action = "../php/Repositorio/CadUsuarios.php" method="POST">
                                  <input type="hidden" name="idGrupo" value = "'.$dado['IdGrupo'].'">
                                  <input type="hidden" name="acao" value = "excluir">
                                  <button type="submit" class="btn btn-block btn-danger" onclick="confirmarExclusao('.$dado['IdGrupo'].')">Excluir</button>
                                  </form>
                                </td>';*/

                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          echo "        <th> Select </th>";
                          echo "        <th> Update </th>";
                          echo "        <th> Delete </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['TBCriar']."</td>";
                          echo "        <td>".$dado['TBAlterar']."</td>";
                          echo "        <td>".$dado['TBExcluir']."</td>";
                          echo "        <td>".$dado['TBSelect']."</td>";
                          echo "        <td>".$dado['TBUpdate']."</td>";
                          echo "        <td>".$dado['TBDelete']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          //echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          //echo "        <th> Select </th>";
                          //echo "        <th> Update </th>";
                         // echo "        <th> Delete </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['VWCriar']."</td>";
                          //echo "        <td>".$dado['TBAlterar']."</td>";
                          echo "        <td>".$dado['VWDelete']."</td>";
                          //echo "        <td>".$dado['TBSelect']."</td>";
                          //echo "        <td>".$dado['TBUpdate']."</td>";
                          //echo "        <td>".$dado['TBDelete']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                          /*SEQUENCE*/
                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          echo "        <th> Select </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['SQCriar']."</td>";
                          echo "        <td>".$dado['SQAlterar']."</td>";
                          echo "        <td>".$dado['SQExcluir']."</td>";
                          echo "        <td>".$dado['SQSelect']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                          /*PROCEDURE*/
                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['PRCriar']."</td>";
                          echo "        <td>".$dado['PRAlterar']."</td>";
                          echo "        <td>".$dado['PRExcluir']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                           /*TRIGGER*/
                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['PRCriar']."</td>";
                          echo "        <td>".$dado['PRAlterar']."</td>";
                          echo "        <td>".$dado['PRExcluir']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                          /*INDEX*/
                          echo "<td style='text-align: center;'>";
                          echo "  <table> ";
                          echo "    <thead>";
                          echo "      <tr>";
                          echo "        <th> Criar </th>";
                          echo "        <th> Editar </th>";
                          echo "        <th> Excluir </th>";
                          echo "      </tr>";
                          echo "    </thead>";
                          echo "    <tbody>";
                          echo "      <tr>";
                          echo "        <td>".$dado['IDXCriar']."</td>";
                          echo "        <td>".$dado['IDXAlterar']."</td>";
                          echo "        <td>".$dado['IDXExcluir']."</td>";
                          echo "      </tr>";
                          echo "    </tbody>";
                          echo " </table>";
                          echo "</td>";
                          echo "</tr>";
                        }
                      ?>
                      <!--td style="text-align: center;">
                          <table>
                            <thead>
                              <tr>
                                <th> Criar </th>
                                <th> Editar </th>
                                <th> Excluir </th>
                                <th> Select </th>
                                <th> Update </th>
                                <th> Delete </th>
                              </tr>
                            </thead>
                            <tbody>
                              <tr>
                                <td> Sim </td>
                                <td> Não </td>
                                <td> Sim </td>
                                <td> Não </td>
                                <td> Não </td>
                                <td> Não </td>
                              </tr>
                            </tbody>
                          </table>
                      </td-->

                    </tr>
                  </tbody>
                  <tfoot>
                  <tr>
                    <th>Grupo</th>
                    <th>Editar</th>
                    <th>Excluir</th>
                    <th>Tabela/Constraint</th>
                    <th>View</th>
                    <th>Sequence</th>
                    <th>Procedure/Functions</th>
                    <th>Trigger</th>
                    <th>Indice</th>
                  </tr>
                  </tfoot>
                </table>
              </div>
              <!-- /.card-body -->
            </div>
            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div>
      <!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
   <!-- Control Sidebar -->
  <!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="../plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../plugins/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../plugins/jszip/jszip.min.js"></script>
<script src="../plugins/pdfmake/pdfmake.min.js"></script>
<script src="../plugins/pdfmake/vfs_fonts.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../plugins/datatables-buttons/js/buttons.colVis.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>

<script>
  $(function () {
    $("#Listagem").DataTable({
      "responsive": true, "lengthChange": false, "autoWidth": false,
      "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"],
      "pageLength": 6 // Define o número de registros por página
    }).buttons().container().appendTo('#Listagem_wrapper .col-md-6:eq(0)');
    $('#example2').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": false,
      "ordering": true,
      "info": true,
      "autoWidth": false,
      "responsive": true,
    });
  });
    function confirmarExclusao(idGrupo) {
        // Exibir modal de confirmação
        if (confirm("Tem certeza que deseja excluir este registro?")) {
            // Se o usuário confirmar, enviar o formulário de exclusão
            document.getElementById('formExcluir_' + idGrupo).submit();
        }
    }
</script>
<?php
    if (isset($_SESSION['Erro']) && !empty(trim($_SESSION['Erro']))) {

      $mensagemDeErro = $_SESSION['Erro'];
      echo '<script>';
      echo 'console.log("Mensagem de erro:", "' . $mensagemDeErro . '");';
      echo 'alert("' . $mensagemDeErro . '");';
      echo '</script>';
      // echo '<script>alert("' . $mensagemDeErro . '");</script>';
      unset($_SESSION['Erro']); // Remove a variável de sessão após exibição
    }
  ?>
</body>
</html>
