<?php  
include_once "../conexao/functions.php";
$config = buscarConfig();
session_start();
if (isset($_SESSION['verificar_logado']) AND $_SESSION['verificar_logado'] == true) {
  header("Location: ../control");
}

if (isset($_POST['submit'])) {
  $email = trim($_POST['email']);
  $crypted_password = cryptPassword(trim($_POST['senha']), "i9team");
  $senha = $crypted_password;


  $logar = buscarUsuarios($email, $senha);
  if (!empty($logar)) {
    session_start();
    $_SESSION['verificar_logado'] = true;
    $_SESSION['admin_id'] = $logar['ID'];
    header("Location: ../control");
  }else{
    echo "<script>alert('Erro ao logar, tente novamente!');</script>";
  }
}

?>

<!DOCTYPE html>
<html lang="pt-br" class="Gibbu_@hotmail.com">
<head>
  <meta charset="UTF-8">
  <title><?php echo $config['Titulo']; ?></title>
  <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script defer src="https://use.fontawesome.com/releases/v5.0.1/js/all.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.transit/0.9.12/jquery.transit.js" integrity="sha256-mkdmXjMvBcpAyyFNCVdbwg4v+ycJho65QLDwVE3ViDs=" crossorigin="anonymous"></script><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
  <link rel="stylesheet" href="./style.css">
  <link rel="icon" type="imagem/png" href="<?php echo $config['Logotipo_1']; ?>" />

</head>
<body>
  <div id="container">
    <div id="inviteContainer">
      <div class="logoContainer"><img class="logo" src="<?php echo $config['Logotipo_1']; ?>"/><img class="text" src="<?php echo $config['Logotipo_2']; ?>"/></div>
      <div class="acceptContainer">
        <form action="index" method="POST">
          <h1>Apps Panel v1</h1>
          <div class="formContainer">
            <div class="formDiv" style="transition-delay: 0.2s">
              <p>EMAIL</p>
              <input type="email" name="email" required=""/>
            </div>
            <div class="formDiv" style="transition-delay: 0.4s">
              <p>PASSWSORD</p>
              <input type="password" name="senha" required=""/><p>DIGITE OS DADOS DE ACESSO</p>
            </div>
            <div class="formDiv" style="transition-delay: 0.6s">
              <button class="acceptBtn" name="submit" type="submit">Login</button>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

  <!-- partial -->
  <script  src="./script.js"></script>


</body>
</html>
