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

<head>
	<title>Inscrições</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

	<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" rel="stylesheet">

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

</head>


<?php
if ($_POST) {
	$participante_cpf = filter_input(INPUT_POST, "participante_cpf");
	$participante_senha = filter_input(INPUT_POST, "participante_senha");


	$participante = new Participante();
	$participante->and("participante_senha", md5($participante_senha));
	$participante->and("participante_cpf", Funcao::ConvertToInt($participante_cpf));
	$participante = $participante->consultar();


	if ($participante->participante_cpf != '' && $participante->participante_id != '') {
		$_SESSION["usuario_id"] = $participante->participante_id;
		$_SESSION["usuario_login"] = $participante->participante_nome;
		$_SESSION["participante_cpf"] = $participante->participante_cpf;
		$_SESSION["usuario_nivel"] = 'participante';
		$_SESSION["participante"] = 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_participante?error=1';</script>";
		echo "<script>
            var url = '" . __URLSITE__ . "login_participante?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) !";
	}
}

?>

<body>


	<section class="ftco-section">
		<div class="container">
			<div class="row justify-content-center">
				<div class="col-lg-12">
					<div class="wrap d-md-flex">
						<div class="text-wrap p-4 p-lg-5 d-flex img d-flex align-items-end" style="background-image: url(img/bg.jpg);">
							<div class="text w-100">
								<h2 class="mb-4">Bem vindo ao <span class="text-danger">Feneva</span> 2024</h2>
								<p>Utilize suas credenciais para logar</p>
							</div>
						</div>
						<div class="login-wrap p-4 p-md-5">
							<h3 class="mb-3 text-center">Entrar no Sistema</h3>
							<form action="login_participante.php" class="signup-form" method="Post">
								<div class="row">
									<div class="col-md-12">
										<div class="form-group d-flex align-items-center">
											<label class="label" for="website">CPF</label>
											<input type="text" class="form-control cpf" id="floatingInput" placeholder="000.000.000-00" name="participante_cpf" maxlength="12" required>
										</div>
									</div>
									<div class="col-md-12">
										<div class="form-group d-flex align-items-center">
											<label class="label" for="password">Senha</label>
											<input type="password" class="form-control" id="floatingInput" placeholder="Exemplo$09" name="participante_senha" required>
										</div>
									</div>
									<div class="col-md-12">
										<div class="form-group text-center">
											<button type="submit" class="btn btn-secondary submit p-3 ">Entrar</button>
										</div>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
</body>

</html>
<script src="<?= __URLSITE__ ?>js/main.js"></script>
<script src="<?= __URLSITE__ ?>js/mask.js"></script>
<script src="<?= __URLSITE__ ?>js/mascaras.js"></script>

<script>
	$(document).ready(function() {
		mascaras();
	})
</script>