<?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);
        if(!$usuario){
			$err = odbc_errormsg();printf("Imposible ejecutar la consulta a Informix, motivo --->    %s ", $err);}
        $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["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;
		
		

        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/kachafruit.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>
<div data-role="page" id="ofertas">
';
include ("header.php");
include ("navbar.php");
//TODO MUESTRA EL NOMBRE DEL CLIENTE CONECTADO
echo '<div data-role="content" style="overflow: scroll;">';

       include ("hacerOferta3.php"); 
  echo'	</div> ';


include ("footer.php");
echo '</div> ' ;
echo '<div data-role="page" id="comprar" style="overflow: scroll;">';
include ("header.php");
include ("navbar.php");
echo '<div data-role="content" >';

       include ("hacerPedido2.php"); 
  echo'	</div> ';


include ("footer.php");
echo '</div>';
echo '<div data-role="page" id="historico">';
include ("header.php");
include ("navbar.php");
echo '<div data-role="content" id="hist_det" >';
       include ("historicoPedido.php"); 
 
echo '</div>';
include ("footer.php");
echo '</div>';
			
		}
		else{
			echo 'false';
		}
?>
