<?php
session_start();

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

$cliente = $_POST['username'];
$contrasena =$_POST['password'];
setcookie("codigoCliente", $cliente,time()+3600);

$usu = ("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 = '$cliente' and cod_client = cli_faxcli
		and ema_faxcli IS NOT NULL  GROUP BY 1,2,3,4 ; ");
$usuario = odbc_exec($conexion_resdis, $usu);
/***********USUARIO INEXISTENTE*********************************/
if(!$usuario){
	$err = odbc_errormsg();
        echo $err;
	//printf("Usuario Inexistente", $err);
}
/***fin*****USUARIO INEXISTENTE*********************************/


/***********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 == $contrasena){
	$_SESSION["autentificado"]= "SI";
	$_SESSION["codigo"]= $cod_client;
	odbc_free_result($usuario); 
	echo '
            <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
            <link rel="stylesheet" href="css/obrador.css" />            
            <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
            <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>';
	/***********ELABORACION POR DIAS **********************/
	echo '<div data-role="page" id="pestana1">';
			include ("header.php");
			include ("navbar.php");
			echo '<div data-role="content" style="overflow: scroll;">';
				include ("pestana1.php"); 
			echo'	</div> ';
			include ("footer.php");
	echo '</div> ' ;
	/**FIN******ELABORACION POR DIAS **********************/
	/***********ELABORACION POR CLIENTE******************/
	echo '<div data-role="page" id="pestana2">';
			include ("header.php");
			include ("navbar.php");
			echo '<div data-role="content"  style="overflow: scroll;">';
				include ("pestana2.php"); 
			echo'	</div> ';
			include ("footer.php");
	echo '</div>';
	/**FIN******ELABORACION POR CLIENTE******************/
	echo '</div>';	
}else{
$err = odbc_errormsg();
echo $err;
//printf("Contraseña incorrecta", $err);
}
/***fin*****CLAVE INCORRECTA*********************************/
?>
