<?php
include($_SERVER['DOCUMENT_ROOT'].'/_configs/conecta.php' );
include($_SERVER['DOCUMENT_ROOT'].'/_configs/conecta2.php' );

$usu = $_POST["usu"];
$pass = $_POST["pass"];

$usu_sql = ("SELECT nom_client, cif_client, ema_faxcli, cod_client,min(porcentaje) porcentaje 
		FROM fsclient, fsfaxcli,outer margen
		WHERE emp_client = emp_faxcli
		and cod_client = cliente and cod_client = '$usu' and cod_client = cli_faxcli
		and ema_faxcli IS NOT NULL  GROUP BY 1,2,3,4 ; ");
$usuario = odbc_exec($conexion_resdis, $usu_sql);
/***********USUARIO INEXISTENTE*********************************/
if(!$usuario){
	$err = odbc_errormsg();
        echo false;
}

/***********CLAVE INCORRECTA*********************************/
$cod_client = trim(odbc_result($usuario,"cod_client"));
$nom_cli = trim(odbc_result($usuario,"nom_client"));
$cif_cli = trim(odbc_result($usuario,"cif_client"));
$ema_faxcli = trim(odbc_result($usuario,"ema_faxcli"));
$por_client = trim(odbc_result($usuario,"porcentaje"));
$contraa=substr(md5(trim($cif_cli).trim($ema_faxcli).trim($cod_client)),6,6);

if ($contraa == $pass){
	session_start();
        $_SESSION["autentificado"]= "SI";
        $_SESSION["ultimoAcceso"]= date("j-n-Y H:i:s");
        $_SESSION["nif"]= $cif_cli;
        $_SESSION["nombre"]= $nom_cli;
		$_SESSION['user_name']= $nom_cli;
        $_SESSION["email_cli"]= $ema_faxcli;
        $_SESSION["codigo"]= $cod_client;
        $_SESSION["cliente"]='';
        $_SESSION["contra"]='';
        $_SESSION["porcentaje"]= $por_client;	
	echo true;
}
else {
	echo false;
}
odbc_free_result($usuario); 

?>