<?php require_once "autoload.php"; ?>
<!DOCTYPE html>
<html lang="pt-Br">

<head>
    <meta charset="utf-8">
    <title>Feneva</title>
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="" name="keywords">
    <meta content="" name="description">

    <!-- Favicon -->
    <link href="img/favicon.ico" rel="icon">

    <!-- Google Web Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@400;600&family=Roboto:wght@500;700&display=swap" rel="stylesheet">

    <!-- Icon Font Stylesheet -->
    <link href="<?= __URLSITE__ ?>vendor/fortawesome/font-awesome/css/all.min.css" rel="stylesheet">

    <!-- Libraries Stylesheet -->
    <!-- <link href="lib/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet">
    <link href="lib/tempusdominus/css/tempusdominus-bootstrap-4.min.css" rel="stylesheet" /> -->

    <!-- Customized Bootstrap Stylesheet -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- Template Stylesheet -->
    <link href="css/style.css" rel="stylesheet">
    <!-- <link rel="stylesheet" href="css/style_inscricao.css"> -->
</head>

<body>
    <?php
    if ($_POST) {
        $usuario_login = filter_input(INPUT_POST, "usuario_login");
        $usuario_senha = filter_input(INPUT_POST, "usuario_senha");

        $usuario = new Usuario();
        $usuario->and("usuario_senha", md5($usuario_senha));
        $usuario->and("usuario_login", $usuario_login);
        $usuario = $usuario->consultar();


        
        if ($usuario->usuario_id != '') {
            $_SESSION["usuario_id"] = $usuario->usuario_id;
            $_SESSION["usuario_login"] = $usuario->usuario_login;
            $_SESSION["usuario_nivel"] = $usuario->usuario_nivel;
            $_SESSION["participante"] = false;
		    $_SESSION["bilheteria"] = true;        


            echo "<script language='javascript'>location.href='" . __URLSITE__ . "';</script>";
            echo "<script>
            var url = '" . __URLSITE__ . "';
            $(location).attr('href',url);
            </script>";
            exit(0);
        } else {
            echo "<script language='javascript'>location.href='" . __URLSITE__ . "login.php?error=1';</script>";
            echo "<script>
            var url = '" . __URLSITE__ . "login.php?error=1';
            $(location).attr('href',url);
            </script>";
            exit(0);
        }
    } else {
        $error = $_GET['error'] ?? '';
        if ($_GET['error'] ?? 'true') {
            $erro_login = "Usuário e/ou senha incorreto(s) !";
        }
    }

 ?>



    <div class="container-fluid position-relative d-flex p-0">
        <!-- Sign In Start -->
        <div class="container-fluid">
            <form class="form" method="post" action="login.php">
                <div class="row h-100 align-items-center justify-content-center login-box" style="min-height: 100vh;">
                    <div class="col-12">
                        <div class="bg-secondary rounded p-4 p-sm-5 my-4 mx-3">
                            <div class="d-flex align-items-center justify-content-between mb-3">
                                <a href="index.html" class="">
                                    <h3 class="text-center">
                                        Login
                                    </h3>
                                </a>
                                <!-- <h3>Sign In</h3> -->
                            </div>
                            <div class="form-floating mb-3">
                                <input type="text" class="form-control" id="floatingInput" placeholder="" name="usuario_login">
                                <label for="floatingInput">Usuario</label>
                            </div>
                            <div class="form-floating mb-4">
                                <input type="password" class="form-control" id="floatingPassword" placeholder="Password" name="usuario_senha">
                                <label for="floatingInput">Senha</label>
                            </div>
                            <div class="d-flex align-items-center justify-content-between mb-4">
                                <div>
                                </div>
                                <a href="">Esqueceu a senha?</a>
                            </div>

                            <button type="submit" class="btn btn-primary py-3 w-100 mb-4">Entrar</button>
                            <!-- <p class="text-center mb-0">Novo por aqui? <a href="">Criar Conta</a></p> -->
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <!-- Sign In End -->
    </div>
</body>

</html>