<?php require_once('../Connections/conn_sustentabilidade.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['login_usuario'])) {
  $loginUsername=$_POST['login_usuario'];
  $password=$_POST['senha_usuario'];
  $MM_fldUserAuthorization = "nivel_usuario";
  $MM_redirectLoginSuccess = "index.php";
  $MM_redirectLoginFailed = "invasor.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_conn_sustentabilidade, $conn_sustentabilidade);
  	
  $LoginRS__query=sprintf("SELECT login_usuario, senha_usuario, nivel_usuario FROM tbusuarios WHERE login_usuario=%s AND senha_usuario=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $conn_sustentabilidade) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'nivel_usuario');
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login</title>
<link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="../css/estilo.css" rel="stylesheet" type="text/css">
<link href="../css/font-face/stylesheet.css" rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous"><!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>

<body>
<main class="container">
	<section>
		<article>
		
			<div class="row">
  <!-- DIV USUÁRIOS -->
  <div class="col-xs-12 col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3" style="margin-top: 15px;">
    <div class="breadcrumb">
		<h1 class="text-success text-center">Faça seu login</h1>
		<hr>
      <img src="../imagens/sustentaitape1.png" class="img-responsive" alt="...">
<br>
<div class="alert alert-success" role="alert">
<form METHOD="POST" action="<?php echo $loginFormAction; ?>" name="form_login" id="form_login">
	<label for="login_usuario">Login</label>
	<p class="input-group">
		<span class="input-group-addon">
			<i class="fa fa-user fa-lg text-success" aria-hidden="true"></i>
		</span>
		<input type="text" name="login_usuario" id="login_usuario" class="form-control input" placeholder="Digite seu Login">
	</p>
	<label for="senha_usuario">Senha</label>
	<p class="input-group">
		<span class="input-group-addon">
			<i class="fa fa-key fa-lg text-success" aria-hidden="true"></i>
		</span>
		<input type="password" name="senha_usuario" id="senha_usuario" class="form-control input" placeholder="Digite sua senha">
	</p>
	<p class="text-right">
		<input class="btn btn-custom btn-primary" type="submit" value="Entrar">
	</p>
</form>
<hr>
<p class="text-center">
	<a class="btn btn-custom btn-green " href="../index.php"><span class="glyphicon glyphicon-log-out"></span>&nbsp;Área Pública</a>
</p>


</div>
    </div>
  </div>
  
</div>
		</article>
	</section>
</main>
</body>
</html>








