<?php
//clear session
session_start();
session_unset();

if(!empty($_POST)){
	include("db.php");
	$result = mysql_query("SELECT * FROM users WHERE utente = '".$_POST['utente']."' AND password = '".$_POST['password']."'");
	if(mysql_num_rows($result) == 1){
		$_SESSION['logged'] = 1;
		$_SESSION['dir'] = mysql_result($result,0,'dir');
		$_SESSION['user']['anagrafica'] = mysql_result($result,0,'anagrafica');
		$_SESSION['user']['id'] = mysql_result($result,0,'userid');
		setcookie("logged", "1", time()+3600);
		
		if(!empty($_REQUEST['url']))
			$goto = base64_decode($_REQUEST['url']);
		else
			$goto = $_SESSION['dir']."/";
			
		header("Location: ".$goto);
	}else{
		$error = '<div class="error">Nome utente e/o Password errati</div>';
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Osservatorio Edile Biella - R.L.S.T.</title>
<link rel="stylesheet" type="text/css" href="css/public.css" />
</head>

<body>
<div class="formLogin">
<form name="formLogin" action="/" method="post">
	<strong>LOGIN PROCEDURA</strong><br /><br />
	utente:<br /> <input type="text" name="utente" /><br />
	password:<br /> <input type="password" name="password" /><br />
    <button type="submit">Entra</button>
    <input type="hidden" name="url" value="<?php echo $_REQUEST['url'];?>" />
	<?php echo $error;?>
</form>
</div>
</body>
</html>