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

<head>
	<title>Feneva Inscrição</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<script src="<?= __URLSITE__ ?>vendor/components/jquery/jquery.min.js" referrerpolicy="no-referrer"></script>

	<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 $mod = 'participante'; ?>
<?php
if ($_POST) {

	$participante_cpf = filter_input(INPUT_POST, "participante_cpf");



	$participante = new Participante();
	$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 {
		$participante = new Participante();
		$participante->dados([
			"participante_cpf" => Funcao::ConvertToInt($participante_cpf),
			"participante_data_cadastro" =>  date('Y-m-d H:i:s')
		]);
		if ($participante->cadastrar()) {
			$login = new Participante();
			$login->and("participante_cpf", Funcao::ConvertToInt($participante_cpf));
			$login = $login->consultar();

			if ($login->participante_cpf != '' && $login->participante_id != '') {
				$_SESSION["usuario_id"] = $login->participante_id;
				$_SESSION["usuario_login"] = $login->participante_nome;
				$_SESSION["participante_cpf"] = $login->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__ . "inscricao?error=1';</script>";
				echo "<script>
            var url = '" . __URLSITE__ . "inscricao?error=1';
            $(location).attr('href',url);
            </script>";
				exit(0);
			}
		}
	}
}
?>

<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>Faça sua inscrição abaixo ou clique em entrar no sistema</p>
							</div>
						</div>
						<div class="login-wrap p-4 p-md-5">
							<h3 class="mb-3 text-center">Inscrições</h3>

							<form action="inscricao" 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" title="Digite um cpf valido" placeholder="000.000.000-00" name="participante_cpf" maxlength="12" required>
										</div>
									</div>

									<div class="col-md-12 my-4">
										<div class="form-group">
											<div class="w-100">
												<label class="checkbox-wrap checkbox-primary">Aceito todos os Termos do Serviço
													<input type="checkbox" checked>
													<span class="checkmark"></span>
												</label>
											</div>
										</div>
									</div>
								</div>
								<div class=" text-center">
									<button type="submit" class="btn btn-primary btn-lg btn-block p-3 ">Entrar no Sistema</button>
								</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>
<?php
if ($_GET["error"] ?? 0 == 1) {
	echo "<script>alert('Erro ao registrar, Digija-se a recepção')</script>";
}

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