<?php
/*if((date('H')<="24")&&(date('H')>="19")&&(date('d/m/Y')=="02/09/2018")){
	header('Refresh: 01');
	$controle=1;
}*/
require "_caminho.php";
require $_GLOBALS["caminho"] . "include/conexao.php";
require $_GLOBALS["caminho"] . "include/funcoes.php";
$exe = $_GET['exe'];
if (isset($_POST["btnacao"])) {
	switch (trim($_POST["btnacao"])) {
		case "Entrar":
			$login      = fnc_validacao_sql_injection(fnc_maiusculas(trim($_POST["login"])));
			$senha      = fnc_validacao_sql_injection(fnc_maiusculas(trim($_POST["senha"])));
			$quantidade = 0;
			$sql = "SELECT COUNT(*) AS QUANTIDADE
			        FROM TBL_USUARIO
					WHERE LOGIN = '$login'
					  AND SENHA = '$senha'
					  AND ATIVO = 'S'";
			$res = ibase_query($con, $sql);
			while ($registro = ibase_fetch_object($res)) {
				$quantidade = (int) $registro->QUANTIDADE;
			}
			ibase_close($con);
			if ($quantidade > 0) {
				$sql = "SELECT CODIGO, PHOTOURL
						FROM TBL_USUARIO
						WHERE LOGIN = '$login'
						AND SENHA = '$senha'
						AND ATIVO = 'S'";
				$res = ibase_query($con, $sql);
				while ($registro = ibase_fetch_object($res)) {
					$codigo = (int) $registro->CODIGO;
					$photourl = 	$registro->PHOTOURL;
				}
				$sql = "SELECT CURRENT_TIMESTAMP AS DATA_HORA FROM RDB" . "$" . "DATABASE";
					$res = ibase_query($con, $sql);
					while ($registro = ibase_fetch_object($res)) {
						$data_servidor_temp = $registro->DATA_HORA;
					}

				$sql = "SELECT GEN_ID(GEN_TBL_HISTORICO_ALTERACAO, 1) FROM RDB" . "$" . "DATABASE";
					$res = ibase_query($con, $sql);
					while ($registro = ibase_fetch_object($res)) {
						$codigo_gerado = $registro->GEN_ID;
					}
				$sql ="INSERT INTO TBL_HISTORICO_ALTERACAO
				   (CODIGO, ALTERACAO, TIME_ALTERACAO, USUARIO, SETOR_ALTERADO, CODIGO_INDEXADO_ALTERADO, TIPO)
				   VALUES
				   ($codigo_gerado, 'O usuário <b>ENTROU</b> no Sistema às <b>".$hora_servidor_interpay."</b> no dia <b>".$data_servidor_interpay."</b>.', '$data_servidor_temp', $codigo, 'SISTEMA', NULL, 'R')";
				$res = ibase_query($con, $sql);
				setcookie("cookie_usuario", $codigo, 0, "/");

				if($photourl==""){
					Header("Location: admin/awr/redirect-social.php");
				} else {
					Header("Location: admin/awr/ranking_vendedor.php");
				}
			}
			else {
				$erro = "Login e/ou senha incorreto(s).";
			}
		break;
	}
}
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../favicon.ico">

    <title>AWR Agrícola</title>

    <!-- Bootstrap core CSS -->
    <!-- <link href="include/css/bootstrap.min.css" rel="stylesheet"> -->

	<!-- Bootstrap core CSS -->
	<link href="https://getbootstrap.com/docs/5.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="include/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="https://getbootstrap.com/docs/5.0/examples/sign-in/signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="include/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

	<body class="bg-success text-center">
  		<main class="form-signin">
		  <? if($controle==NULL){?>
			<form method="post" enctype="multipart/form-data" action="<? echo $_SERVER["PHP_SELF"]; ?>">
			<img src="https://i.pinimg.com/originals/3e/ec/5f/3eec5f92195bfc5e4ccf0baaf8d67733.png" alt="Bootstrap" width="128" height="128" class="rounded-circle border border-white border-5 m-3">
				<h1 class="h3 mb-3 text-white display-6 lh-1 fw-bold">AWR Agro</h1>

				<div class="badge bagde-danger"><?php echo $login.$senha."".$erro; ?></div>
				<div class="form-floating">
					<input name="login" type="text" id="inputEmail" class="form-control" id="floatingInput" placeholder="name@example.com">
					<label for="floatingInput">ID InterPay</label>
				</div>
				<div class="form-floating">
					<input name="senha" type="password" id="inputPassword" class="form-control" id="floatingPassword" placeholder="Password">
					<label for="floatingPassword">Senha</label>
				</div>

				<input name="btnacao" value="Entrar" class="w-100 btn btn-lg btn-light shadow" type="submit" onclick='javascript: return Valida_Form();'>
				<p class="mt-5 mb-3 text-white">&copy; 2016–2021</p>
			</form>
			<? } else { ?>
			<div class="col" style="background: #000000; border-radius: 5px; min-height: 300px">
				<br>
				<center>
					<h2 style="color: aliceblue">Servidor em Manutenção</h2>
					<span class="badge badge-danger">Retorno às <b>8h00</b></span>
					<h2 style="color: bisque"><? echo $hora_servidor_interpay;?></h2>
				</center>
			</div>
			<? } ?>
		</main>


    

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="include/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>