<?php  
include_once "sistema/functions.php";
session_start();
if ($_SESSION['usuario'] == true) {
  header("Location: cad_app.php");
  exit();
}

    if(isset($_POST['login'])){
        $username = $_POST['username'];
        $password = $_POST['password'];
 
     $dados = fazerLogin($username, $password);
     $nivel = $dados['nivel'];

        if (count($dados) >= 1){
            echo "<div class='alert alert-success'>Credenciais confirmadas!</div>";
              session_start();
            $_SESSION[$username] = true;
            $_SESSION['nivel'] = $nivel;
            $_SESSION['usuario'] = $username;

            header("Location: cad_app.php");
        }else{
            echo "<div class='alert alert-danger'>Usuário ou senha inválido</div>";
        }
    }
?>
<!DOCTYPE html>
<html lang="en">
<?php 
include_once "head.php";
?>
  <body>
    <div class="container-scroller">
      <div class="container-fluid page-body-wrapper full-page-wrapper">
        <div class="row w-100 m-0">
          <div class="content-wrapper full-page-wrapper d-flex align-items-center auth login-bg">
            <div class="card col-lg-4 mx-auto">
              <div class="card-body px-5 py-5">
                <h3 class="card-title text-left mb-3">Acesso Restrito</h3>
                <form method="post">
                  <div class="form-group">
                    <label>Usuario *</label>
                    <input type="text" name="username" class="form-control p_input">
                  </div>
                  <div class="form-group">
                    <label>Senha *</label>
                    <input type="password" name="password" class="form-control p_input">
                  </div>
                  <div class="text-center">
                    <button type="submit" name="login" class="btn btn-primary btn-block enter-btn">Entrar</button>
                  </div>
                  <p class="sign-up">Para suporte <br> <a href="https://wa.me/<?=$whatsapp;?>"> Entre em Contato</a></p>
                </form>
              </div>
            </div>
          </div>
          <!-- content-wrapper ends -->
        </div>
        <!-- row ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->
    <!-- plugins:js -->
    <script src="assets/vendors/js/vendor.bundle.base.js"></script>
    <!-- endinject -->
    <!-- Plugin js for this page -->
    <!-- End plugin js for this page -->
    <!-- inject:js -->
    <script src="assets/js/off-canvas.js"></script>
    <script src="assets/js/hoverable-collapse.js"></script>
    <script src="assets/js/misc.js"></script>
    <script src="assets/js/settings.js"></script>
    <script src="assets/js/todolist.js"></script>
    <!-- endinject -->
  </body>
</html>