<?php 
session_start();
include_once '../../conexao/index.php';

$user = $_POST['user'];
$pass = $_POST['pass'];

if ($user == NULL || $pass == NULL) {
	echo "<script>alert('Preencha todos os campos por favor!')</script>";
	echo "<script>window.location.href='../../'</script>";
}else{
	$sql = "SELECT id, categoria, nome FROM users WHERE user = '$user' AND pass = '$pass'";
	$rs = mysqli_query($db, $sql);
	$dados = mysqli_fetch_array($rs);
	if (mysqli_num_rows($rs) > 0) {
		$_SESSION['idUsuario'] = $dados['id'];
		$_SESSION['categoriaUsuario'] = $dados['categoria'];
		$_SESSION['nomeUsuario'] = $dados['nome'];
		echo "<script>window.location.href='../../views/admin/'</script>";
	}else{
		echo "<script>alert('Usuario ou senha incorretos!')</script>";
		echo "<script>window.location.href='../../'</script>";
	}
}
