<?php include_once('../../../config.php') ?>
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
?>


<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Sisplan Web | Permissões</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css?versao=3.263.17.1">
  <!-- Ionicons -->
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="dist/css/adminlte.min.css?versao=3.263.17.1">
  <!-- overlayScrollbars -->
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css?versao=3.263.17.1">
  <!-- Daterange picker -->
  <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,600,700,400italic' rel='stylesheet' type='text/css'>

  <link rel="stylesheet" href="dist/css/PesquisaVariosSelect2.css?versao=3.263.17.1">
  <link rel="stylesheet" href="dist/css/custom.css?versao=3.263.17.1">
  <link rel="stylesheet" href="dist/css/sisplan.css?versao=3.263.17.1">
  <link rel="stylesheet" type="text/css" href="dist/css/dataTables.bootstrap4.min.css?versao=3.263.17.1" />
  <link rel="stylesheet" href="plugins/select2/css/select2.min.css?versao=3.263.17.1">
  <link rel="stylesheet" href="plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css?versao=3.263.17.1">
  <!-- iCheck for checkboxes and radio inputs -->
  <link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css?versao=3.263.17.1">
  <link rel="shortcut icon" href="favicon.ico">
  <link rel="stylesheet" type="text/css" href="dist/css/driver.min.css?versao=3.263.17.1" />
  <!-- Google Font: Source Sans Pro -->
  <style>
    .info-box-text {
      font-size: 20px;
      font-weight: bold;
      color: grey;
    }
  </style>
  <!-- Toastr -->
  <link rel="stylesheet" href="plugins/toastr/toastr.min.css">

</head>

<body class="hold-transition sidebar-mini layout-fixed">
  <div class="wrapper">


    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
      <!-- Content Header (Page header) -->
      <div class="content-header">
        <div class="container-fluid">
          <div class="row mb-2">
            <div class="col-sm-6 flex">
              <h1 class="m-0 text-dark">Permissões Tela</h1>
              <button class="btn btn-info btn-sm ml-2" id="tutorial">
                <i class="fas fa-question-circle"></i>
              </button>
            </div><!-- /.col -->
            <div class="col-sm-6">

            </div><!-- /.col -->
          </div><!-- /.row -->
        </div><!-- /.container-fluid -->
      </div>
      <!-- /.content-header -->

      <!-- Main content -->
      <section class="content">

        <div class="card">
          <div class="card-body">
            <div class="container-fluid p-4">
              <div class="row pb-4">
                <div class="col-sm-6">
                  <button id="btn-filtros" class="btn btn-success btn-sisp" type="button" data-toggle="modal" data-target="#modal-filtros">
                    <span class="fas fa-filter"></span> Filtros
                  </button>
                  <button id="btn-copiar-acessos" class="btn btn-secondary btn-sisp" type="button" data-toggle="modal" data-target="#modal-copiar-acessos">
                    Copiar Permissões
                  </button>
                </div>
              </div>

              <div class="row">
                <div class="col-sm-12">

                  <div class="d-inline pb-2">
                    <h5>Selecionar todos: </h5>
                  </div>
                  <div class="icheck-primary">
                    <input class="form-check-input" type="checkbox" id="check_todos" value="option5">
                    <label class="form-check-label" for="check_todos" id="check_todosTour">Todos</label>
                  </div>
                </div>
              </div>

              <div style="background-color: var(--widget-color)" class="row">
                <div class="col-sm-12 pb-2" id="aplicarTodosTour">
                  <div class="d-inline pb-2">
                    <h5>Aplicar a todos selecionados: </h5>
                  </div>
                  <div class="icheck-primary d-inline pb-2">
                    <input class="form-check-input" type="checkbox" id="check_permissao" value="option1">
                    <label class="form-check-label" for="check_permissao">Permissão</label>
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col-sm-12 table-responsive">
                  <table id="tabelaAcessos" class="table table-sm table-select table-hover" width="100%">
                    <thead>
                      <th>Sel</th>
                      <th>Cod. Usuário</th>
                      <th>Usuário</th>
                      <th>Tela</th>
                      <th>Ação</th>
                      <th>Permissão</th>
                    </thead>
                    <tbody>
                    </tbody>
                  </table>
                </div>
                <div class="col-sm-12">
                  <button id="btn-liberar" class="btn btn-danger btn-sisp">Confirmar</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>
      <!-- /.content -->
    </div>

    <div id="modal-filtros" class="modal" tabindex="-1" role="dialog">
      <div class="modal-dialog modal-xl" role="document">
        <div class="modal-content" id="modalBody">
          <div class="modal-header">
            <h4 class="modal-title">Filtros</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-4 col-12">
                <label data-error="wrong" data-success="right" id="labelUsuario" for="txtUsuario2">Usuário: </label>
                <div class="relative">
                  <div class="input-group">
                    <select class="js-example-programmatic js-states form-control" id="txtUsuario2" name="txtusuario2" multiple="multiple">
                    </select>
                    <div class="input-group-append">
                      <button class="btn bg-danger" id="btnUsuario2" name="btnUsuario2" data-button="absolute" type="button"><i class="m-0 p-0 fas fa-search"></i></button>
                      <button class="btn bg-danger" id="btnLimpaUsuario2" type="button"><i class="m-0 p-0 fas fa-trash"></i></button>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-12 col-lg-4">
                <label data-error="wrong" class="labelGeral" data-success="right" for="txtFuncao">Função</label>
                <div class="input-group">
                  <input type="text" class="input-default focus form-control" required aria-describedby="ufError" id="txtFuncao" name="txtFuncao" class="form-control" placeholder="Função">
                  <div class="input-group-append">
                    <button class="btn bg-danger" id="btnFuncao" name="btnFuncao" data-button="absolute" type="button">
                      <i class="m-0 p-0 fas fa-search"></i>
                    </button>
                    <button class="btn bg-danger" id="btn-Limpa-Funcao" type="button">
                      <i class="m-0 p-0 fas fa-trash"></i>
                    </button>
                  </div>
                  <span id="ufError" class="error invalid-feedback" style="display: inline;"></span>
                </div>
              </div>
              <div class="col-lg-4 col-12">
                <label data-error="wrong" data-success="right" id="labelTela" for="txtTela">Tela: </label>
                <div class="relative">
                  <div class="input-group">
                    <select class="js-example-programmatic js-states form-control" id="txtTela" name="txtTela" multiple="multiple">
                    </select>
                    <div class="input-group-append">
                      <button class="btn bg-danger" id="btnTela" name="btnTela" data-button="absolute" type="button"><i class="m-0 p-0 fas fa-search"></i></button>
                      <button class="btn bg-danger" id="btnLimpaTela" type="button"><i class="m-0 p-0 fas fa-trash"></i></button>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <div class="group-button">
              <button id="btn-fechar" class="btn btn-danger btn-sisp" type="button" data-dismiss="modal">Fechar</button>
              <button id="btn-consultar" class="btn btn-primary btn-sisp" type="button">Consultar</button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div id="modal-copiar-acessos" class="modal" tabindex="-1" role="dialog">
      <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content" id="modalBody">
          <div class="modal-header">
            <h4 class="modal-title">Copiar Permissões</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-lg-12  col-12 form-group">
                <label data-error="wrong" class="labelGeral" data-success="right" for="txtCopia">Copiar Permissões de:</label>
                <div class="input-group">
                  <input type="text" placeholder="Copiar Permissões de:" class="input-default focus form-control validate" id="txtCopia" name="txtCopia">
                  <div class="input-group-append">
                    <button class="btn bg-danger" id="btnCopia" name="btnCopia" data-button="absolute" type="button">
                      <i class="m-0 p-0 fas fa-search"></i>
                    </button>
                    <button class="btn bg-danger" id="btnACopia" type="button">
                      <i class="m-0 p-0 fas fa-trash"></i>
                    </button>
                  </div>
                </div>
              </div>
              <div class="col-lg-12  col-12 form-group">
                <label data-error="wrong" class="labelGeral" data-success="right" for="txtCopiaPara">Para:</label>
                <div class="input-group">
                  <input type="text" placeholder="Copiar Permissões para:" class="input-default focus form-control validate" id="txtCopiaPara" name="txtCopiaPara">
                  <div class="input-group-append">
                    <button class="btn bg-danger" id="btnCopiaPara" name="btnCopiaPara" data-button="absolute" type="button">
                      <i class="m-0 p-0 fas fa-search"></i>
                    </button>
                    <button class="btn bg-danger" id="btnACopiaPara" type="button">
                      <i class="m-0 p-0 fas fa-trash"></i>
                    </button>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="modal-footer">
            <div class="row">
              <button id="btn-confirmar-copia" class="btn btn-danger btn-sisp" type="button" data-dismiss="modal">
                Confirmar
              </button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- Control Sidebar -->
    <aside class="control-sidebar control-sidebar-dark">
      <!-- Control sidebar content goes here -->
    </aside>
    <!-- /.content-wrapper -->
    <?php
    include_once('../../../modais.php');
    ?>
    <!-- /.control-sidebar -->
  </div>
  <!-- ./wrapper -->

  <!-- jQuery -->
  <script src="plugins/jquery/jquery.min.js?versao=3.263.17.1"></script>
  <!-- jQuery UI 1.11.4 -->
  <script src="plugins/jquery-ui/jquery-ui.min.js?versao=3.263.17.1"></script>
  <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
  <script>
    if ($('[type="date"]').prop('type') != 'date') {
      $('[type="date"]').datepicker();
    }
    $.widget.bridge('uibutton', $.ui.button);
  </script>

  <!-- Bootstrap 4 -->
  <script src="plugins/bootstrap/js/bootstrap.bundle.min.js?versao=3.263.17.1"></script>
  <script src="dist/js/sisplan.js?versao=3.263.17.1"></script>
  <script type="text/javascript" src="utils/funcoes.js?versao=3.263.17.1"></script>
  <script src="dist/js/adminlte.min.js?versao=3.263.17.1"></script>
  <script type="text/javascript" src="dist/js/jquery.dataTables.min.js?versao=3.263.17.1"></script>
  <script type="text/javascript" src="dist/js/loadingoverlay.min.js?versao=3.263.17.1"></script>
  <script type="text/javascript" src="dist/js/dataTables.bootstrap4.min.js?versao=3.263.17.1"></script>
  <script src="dist/js/jquery.maskMoney.min.js?versao=3.263.17.1"></script>
  <script src="dist/js/dataTables.keyTable.js?versao=3.263.17.1"></script>
  <script src="utils/cookies.js?versao=3.263.17.1"></script>
  <script src="dist/js/requisicoes.js?versao=3.263.17.1"></script>
  <script src="plugins/select2/js/select2.full.min.js?versao=3.263.17.1"></script>
  <!-- SweetAlert2 -->
  <script src="plugins/sweetalert2/sweetalert2.min.js?versao=3.263.17.1"></script>
  <script src="plugins/toastr/toastr.min.js?versao=3.263.17.1"></script>
  <script src="dist/js/driver.min.js?versao=3.263.17.1"></script>
  <script type="text/javascript" src="config.js?versao=3.263.17.1"></script>
  <script>
    $(document).ready(async function() {
      if (getCookie('usuario') == "") {
        window.location.href = `${BASE_URI}/login`;
        return;
      }

      let usuario = getCookie('usuario');
      let empresa = getCookie('empresa');

      ipInterno = IP_INTERNO;
      ipExterno = IP_EXTERNO;
      basicAuth = BASIC_AUTH;

      const temAcesso = await temAcessoTela('PERMISSOES_TELA');
      if (!temAcesso.resultado) {
        toastrAcesso(temAcesso, BASE_URI);
        return;
      }

      sArquivo = `${BASE_URI}/pages/sistema/permissoes_tela/permissoes_tela.js?versao=3.263.17.1`;
      insereJavaScriptPagina(sArquivo);

    });
  </script>
</body>

</html>