<? 
include_once("lib/config.php");

$ID_PAGINA = "INDEX";

unset($_SESSION['_usu_id']);

$mensaje_login = "";
$email=(isset($_POST['email'])?$_POST['email']:"");
$password=(isset($_POST['pswd'])?$_POST['pswd']:"");
if (($email!="")||($password!=""))
{
	$usuari_login->load_email($email);
	if($usuari_login->usu_id==-1)
		$mensaje_login = getTexto("LOG_txt_incorrecto");

	if($usuari_login->usu_estat!=_USU_ESTAT_ACTIU)
		$mensaje_login = getTexto("LOG_txt_incorrecto");

	if($mensaje_login == "")
	{
		if($usuari_login->usu_pswd!=$password)
			$mensaje_login = getTexto("LOG_txt_incorrecto");
		else
		{
			$_SESSION['_usu_id'] = $usuari_login->usu_id;
			if($usuari_login->usu_perfil==_PERFIL_BASIC)
				$web = _WEB_SOLC;
			else
				$web = _WEB_RESOLC;
			if($usuari_login->usu_acceptar_condicions==1)
			{
				include("condicions_conf.php");
			}
			elseif($usuari_login->dades_incompletes==1)
			{
				include("dades.php");
			}
			else
				include("home.php");
			die();
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<? include("cabecera_common_info.php")?>

<script>
function enviarLogin()
{
	var res = validarForm("fLogin"
		,"email","<?=getTexto("LOG_email")?>","E","R"
		,"pswd","<?=getTexto("LOG_pswd")?>","T","R"
		);	
	return res;
}
function contrasenya()
{
	window.open("contrasenya.php","<?=getTexto("LOG_pswd")?>","width=495,height=250");
}
</script>

</head>
<body>
<div id="page_contents">
	
<? include("cabecera.php")?>
<? include("menu_publico.php")?>
	
	<div id="login">
		<h1><?=getTexto("LOG_situa")?></h1>
		<form name="fLogin" action="index.php" method="post" onsubmit="return enviarLogin();">
			<table cellpadding="5" cellspacing="0" border="0" align="center">
				<tr>
					<td class="form_campo_titulo"><?=getTexto("LOG_email")?>:</td>
					<td><input type="text" name="email" size="40"></td>
				</tr>
				<tr>
					<td class="form_campo_titulo"><?=getTexto("LOG_pswd")?>:</td>
					<td><input type="password" name="pswd" size="20"></td>
				</tr>
				<tr>
					<td></td>
					<td><input type="submit" value="<?=getTexto("LOG_btn_entrar")?>" title="<?=getTexto("LOG_btn_entrar")?>" class="boton_gris"></td>
				</tr>
				<tr>
					<td></td>
					<td align="left"><a href="javascript:contrasenya()" title="<?=getTexto("LOG_btn_olvido")?>"><?=getTexto("LOG_btn_olvido")?></a></td>
				</tr>
			</table>
		</form>
	</div>
	
<? include("pie.php")?>
</div>
<? if((isset($mensaje_login)) && ($mensaje_login!="")) { ?>
<script>alert("<?=$mensaje_login?>")</script>
<? } ?>
</body>
</html>