<!--
=========================================================
Painel P2P Plus - v1.0
=========================================================
Created by Albeci Nogueira (PLAYLIVE.TOP)
=========================================================
-->
<!DOCTYPE html>
<html lang="en">
<?php 
include_once "sistema/functions.php";
include_once "head.php";
?>
  <body>
    <div class="container-scroller">
      <!-- partial:partials/_sidebar.html -->
<?php 
include_once "header.php";
?>
        <!-- partial -->
        <div class="main-panel">
          <div class="content-wrapper">
            <div class="row">
              <div class="col-12 grid-margin stretch-card">
                <div class="card corona-gradient-card">
                  <div class="card-body py-0 px-0 px-sm-3">
                    <div class="row align-items-center">
                      <div class="col-4 col-sm-3 col-xl-2">
                        <img src="assets/images/dashboard/Group126@2x.png" class="gradient-corona-img img-fluid" alt="">
                      </div>
                      <div class="col-5 col-sm-7 col-xl-8 p-0">
                        <h4 class="mb-1 mb-sm-0">Precisa de ajuda?</h4>
                        <p class="mb-0 font-weight-normal d-none d-sm-block">Temos suporte especializado, é só chamar!!!</p>
                      </div>
                      <div class="col-3 col-sm-2 col-xl-2 pl-0 text-center">
                        <span>
                          <a href="https://wa.me/<?=$whatsapp;?>" target="_blank" class="btn btn-outline-light btn-rounded get-started-btn">Clique para Suporte</a>
                        </span>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
<?php
if(isset($_GET['msg'])){
if($_GET["msg"] == "sucesso"){?>
<div class="alert alert-success" role="alert">
  <h4 class="alert-heading">Sucesso!</h4>
  <hr>
  <p class="mb-0">Seus dados foram alterados.</p>
</div>
<?php
}else{
  ?>
<div class="alert alert-danger" role="alert">
  <h4 class="alert-heading">Erro!</h4>
  <hr>
  <p class="mb-0">Seus dados não foram alterados.</p>
</div>
<?php
}
}
?>
            <div class="col-lg-14 grid-margin stretch-card">
                <div class="card">
                  <div class="card-body">
                    <h4 class="card-title">Usuarios Cadastradas</h4>
                    <!-- <p class="card-description"> Add class <code>.table-dark</code>
                    </p> -->
                    <div class="table-responsive">
                      <table class="table table-dark">
                        <thead>
                          <tr>
                            <th> # </th>
                            <th> Nome</th>
                            <th> Usuario </th>
                            <th> Nivel </th>
                            <th> AÇÕES </th>
                          </tr>
                        </thead>
                        <?php
                        $dadosUser = buscarUsuarios();
                        foreach ($dadosUser as $value) {
                          $id = $value['id'];
                          $nome = $value['nome'];
                          $usuario = $value['usuario'];
                          $nivel = $value['nivel'];
                          ?>
                        <tbody>
                          <tr>
                          <td><?=$id;?></td>
                          <td><?=$nome;?></td>
                          <td><?=$usuario;?></td>
                          <td><?php echo $nivel == 1 ? "Admin" : "Usuário";?></td>
                            <td>
                          <a href="edit_usuario.php?update=<?=$id?>">  
                          <button type="button" class="btn btn-inverse-primary btn-rounded btn-icon">
                            <i class="mdi mdi-lead-pencil"></i>
                          </button></a>
                           <a href="actions/usuarios/excluir.php?id=<?=$id?>">
                          <button type="button" class="btn btn-danger btn-rounded btn-icon">
                            <i class="mdi mdi-delete-forever"></i>
                          </button></a>
                        </td>
                          </tr>
                    </tbody>
                            <?php } ?>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
                  <a href="cad_usuarios.php" class="btn btn-primary btn-rounded btn-fw">Cadastrar Usuários</button></a>
          <!-- content-wrapper ends -->
<?php
include_once "footer.php";
?>
        <?php 
        if (isset($_GET["r"])) {
          $result = $_GET["r"];
          switch ($result) {
            case "add_sucesso":
            echo "<script>
            setTimeout(function() {
              const Toast = Swal.mixin({
                toast: true,
                position: 'bottom-start',
                showConfirmButton: false,
                timer: 7000
                })
                Toast.fire({
                  type: 'success',
                  title: 'Usuario cadastrado com sucesso!'
                  })
                }, 1000);</script>";
                break;
            case "atualizado":
            echo "<script>
            setTimeout(function() {
              const Toast = Swal.mixin({
                toast: true,
                position: 'bottom-start',
                showConfirmButton: false,
                timer: 7000
                })
                Toast.fire({
                  type: 'success',
                  title: 'Usuario atualizado com sucesso!'
                  })
                }, 1000);</script>";
                break;
            case "erro_att":
            echo "<script>
            setTimeout(function() {
              const Toast = Swal.mixin({
                toast: true,
                position: 'bottom-start',
                showConfirmButton: false,
                timer: 7000
                })
                Toast.fire({
                  type: 'error',
                  title: 'Erro ao atualizar o Usuario!'
                  })
                }, 1000);</script>";
                break;
            case "erro_delete":
            echo "<script>
            setTimeout(function() {
              const Toast = Swal.mixin({
                toast: true,
                position: 'bottom-start',
                showConfirmButton: false,
                timer: 7000
                })
                Toast.fire({
                  type: 'error',
                  title: 'Erro ao excluir o Usuario!'
                  })
                }, 1000);</script>";
                break;
            case "deletado":
            echo "<script>
            setTimeout(function() {
              const Toast = Swal.mixin({
                toast: true,
                position: 'bottom-start',
                showConfirmButton: false,
                timer: 7000
                })
                Toast.fire({
                  type: 'success',
                  title: 'Usuario excluido com sucesso!'
                  })
                }, 1000);</script>";
                break;
              }
            }
            ?> 
  </body>
</html>