<?php


		session_start();
		if(isset($_SESSION['carro']))
		$carro=$_SESSION['carro'];else $carro=false;
		$error = 0;
		//PARTE MENSAJE VENDEDOR
		$mail = $_POST['Mail'];
		$mailcliente = $_POST['Mail'];
		$nombre = $_POST['Nombre'];
		$apellido = $_POST['Apellidos'];
		$direccion = $_POST['DirecciÃ³n'];
		$informacion = $_POST['Mensaje'];
		
			if (!isset($mail) || $mail == '') {
   	 	$error=1;
		}

			if (!isset($nombre) || $nombre == '') {
   	 	$error=1;
		}	 
		
		if ($error==1){?>
			<!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>
<link href="../CSS/AltolandonIntranet.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Refresh" CONTENT="3; URL=../Ingles/Buy.php" />
<title>ALTOLANDON</title>
<link rel="shortcut icon" href="../Imagenes/Icono.ico"> 
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js"></script>
	<script type="text/javascript" src="../includes/mootools/sexyalertbox.v1.2.moo.js"></script>
	<link rel="stylesheet" type="text/css" media="all" href="../includes/mootools/sexyalertbox.css"/>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
	<script type="text/javascript" src="../includes/jQuery/jquery.easing.1.3.js"></script>
	<script type="text/javascript" src="../includes/jQuery/sexyalertbox.v1.2.jquery.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="../includes/jQuery/sexyalertbox.css"/>

</head>

<body>
<div id="superior">
<div id="logo"><img src="../Imagenes/logo.png" border="0" usemap="#Map"/>
            <map name="Map" id="Map">
              <area shape="rect" coords="4,5,271,62" href="Start.html" />
            </map>
</div
></div>
</body>
</html>

    <?php 
		
	
	echo '
	<script type="text/javascript">
	function test(){
	Sexy.alert("Please, complete the required fields.");}
	window.onload=test;
	</script>';


	die();}
		$total=0;
		if($carro[md5(1)]){$total= $total+($carro[md5(1)]['cantidad']*$carro[md5(1)]['precio']);}
		if($carro[md5(2)]){$total= $total+($carro[md5(2)]['cantidad']*$carro[md5(2)]['precio']);}
		if($carro[md5(3)]){$total= $total+($carro[md5(3)]['cantidad']*$carro[md5(3)]['precio']);}
		if($carro[md5(4)]){$total= $total+($carro[md5(4)]['cantidad']*$carro[md5(4)]['precio']);}

		$mensaje  ="SOLICITUD DE PEDIDO \r\n";
		$mensaje .= "Este mensaje fue enviado por " . $nombre ." ". $apellido . " \r\n";
		$mensaje .= "Su e-mail es: " . $mail . " \r\n";
		$mensaje .= "Direccion: ". $direccion . "\r\n";
		$mensaje .= "PRODUCTOS SOLICITADOS \r\n";
		//for($aux=1; $aux<=$producto; $aux++)
		//{
		if($carro[md5(1)]){$mensaje.="- ". $carro[md5(1)]['producto']. ". Number of units: ".$carro[md5(1)]['cantidad']." Total Price: ".($carro[md5(1)]['cantidad']*$carro[md5(1)]['precio']). " Euros \r\n";}
		if($carro[md5(2)]){$mensaje.="- ". $carro[md5(2)]['producto']. ". Number of units: ".$carro[md5(2)]['cantidad']." Total Price: ".($carro[md5(2)]['cantidad']*$carro[md5(2)]['precio']). " Euros \r\n";}
		if($carro[md5(3)]){$mensaje.="- ". $carro[md5(3)]['producto']. ". Number of units: ".$carro[md5(3)]['cantidad']." Total Price: ".($carro[md5(3)]['cantidad']*$carro[md5(3)]['precio']). " Euros \r\n";}
		if($carro[md5(4)]){$mensaje.="- ". $carro[md5(4)]['producto']. ". Number of units: ".$carro[md5(4)]['cantidad']." Total Price: ".($carro[md5(4)]['cantidad']*$carro[md5(4)]['precio']). " Euros \r\n";}
		$mensaje .= "Precio Total del pedido: ".number_format($total,2)." Euros \r\n";
		$mensaje .= "Mensaje: " . $informacion . " \r\n";


		//PARTE FIJA ^^
		require "../includes/class.phpmailer.php";
		$mail = new phpmailer();
		$mail->PluginDir = "../includes/";
		$mail->Mailer = "smtp";
		$mail->Host = "mail.altolandon.com";
        $mail->SMTPAuth = true;
		$mail->Username = "tienda@altolandon.com"; 
        $mail->Password = "shoplandon";
		$mail->From = "tienda@altolandon.com";
		//$mail->AddEmbeddedImage('../Imagenes/logo.png','AltoLANDON'); 	

		//PARTE FIJA ^^
        $mail->FromName = "Tienda AltoLANDON";
		$mail->Timeout=60;
		//$mail->AddAddress("mtreik@gmail.com");
		$mail->CharSet = "utf8_decode()";
		$mail->AddAddress("tienda@altolandon.com");//cambiar por el de rosalia
		$mail->Subject = "PEDIDO AltoLANDON";
        //$mail->Body = "<b>Mensaje de prueba mandado con phpmailer en formato html</b>";
		//$mensaje= nl2br(htmlentities($mensaje));
		//$mail->headers = "Content-type: text/html\r\n";
		$mail->Body = $mensaje;
		//$mail->AltBody = "Mensaje de prueba mandado con phpmailer en formato solo texto";
		$exito = $mail->Send();
		
		//PARTE MENSAJE CLIENTE
		
		$mensajec ="ORDER CONFIRMATION \r\n";
		$mensajec .= "Verify your order details are correct \r\n";
		$mensajec .= "Name: " . $nombre ." ". $apellido . " \r\n";
		$mensajec .= "E-mail: " . $mailcliente . " \r\n";
		$mensajec .= "Address: ". $direccion . "\r\n";
		$mensajec .= "REQUESTED PRODUCTS \r\n";
		//for($aux=1; $aux<=$producto; $aux++)
		//{
		if($carro[md5(1)]){$mensajec.="- ". $carro[md5(1)]['producto']. ". Number of units: ".$carro[md5(1)]['cantidad']." Total Price: ".($carro[md5(1)]['cantidad']*$carro[md5(1)]['precio']). " Euros \r\n";}
		if($carro[md5(2)]){$mensajec.="- ". $carro[md5(2)]['producto']. ". Number of units: ".$carro[md5(2)]['cantidad']." Total Price: ".($carro[md5(2)]['cantidad']*$carro[md5(2)]['precio']). " Euros \r\n";}
		if($carro[md5(3)]){$mensajec.="- ". $carro[md5(3)]['producto']. ". Number of units: ".$carro[md5(3)]['cantidad']." Total Price: ".($carro[md5(3)]['cantidad']*$carro[md5(3)]['precio']). " Euros \r\n";}
		if($carro[md5(4)]){$mensajec.="- ". $carro[md5(4)]['producto']. ". Number of units: ".$carro[md5(4)]['cantidad']." Total Price: ".($carro[md5(4)]['cantidad']*$carro[md5(4)]['precio']). " Euros \r\n";}
		
		$mensajec .= "Total order price: ".number_format($total,2)." Euros \r\n";
		$mensajec .= "In short we will contact you to confirm your order and provide a payment. \r\n";
		$mensajec .= "A greeting and thank you very much for trusting AltoLANDON. \r\n";
		
		$mailc = new phpmailer();
		$mailc->PluginDir = "../includes/";
		$mailc->Mailer = "smtp";
		$mailc->Host = "mail.altolandon.com";
        $mailc->SMTPAuth = true;
		$mailc->Username = "tienda@altolandon.com"; 
        $mailc->Password = "shoplandon";
		$mailc->From = "tienda@altolandon.com";
		//PARTE FIJA ^^
        $mailc->FromName = "Tienda AltoLANDON";
		$mailc->Timeout=60;
		$mailc->CharSet = "utf8_decode()";
		$mailc->AddAddress($mailcliente);
		//$mail->AddAddress("tienda@altolandon.com");//cambiar por el de rosalia
		$mailc->Subject = "PEDIDO AltoLANDON";
        //$mail->Body = "<b>Mensaje de prueba mandado con phpmailer en formato html</b>";
		//$mensajec= nl2br(htmlentities($mensajec));
		$mailc->Body = $mensajec;
		//$mail->AltBody = "Mensaje de prueba mandado con phpmailer en formato solo texto";
		$exitoc = $mailc->Send();
		
		
		$intentos=1; 
  while ((!$exito) && ($intentos < 5)) {
	sleep(5);
     	//echo $mail->ErrorInfo;
     	$exito = $mail->Send();
     	$intentos=$intentos+1;	
	
   }
   
   		$intentosc=1; 
  while ((!$exitoc) && ($intentosc < 5)) {
	sleep(5);
     	//echo $mail->ErrorInfo;
     	$exitoc = $mailc->Send();
     	$intentosc=$intentosc+1;	
	
   }
 
		
   if(!$exito)
   {
	 ?>
	<!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>
<link href="../CSS/AltolandonIntranet.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Refresh" CONTENT="3; URL=../Ingles/Cart.php" />
<title>ALTOLANDON</title>
<link rel="shortcut icon" href="../Imagenes/Icono.ico"> 
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js"></script>
	<script type="text/javascript" src="../includes/mootools/sexyalertbox.v1.2.moo.js"></script>
	<link rel="stylesheet" type="text/css" media="all" href="../includes/mootools/sexyalertbox.css"/>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
	<script type="text/javascript" src="../includes/jQuery/jquery.easing.1.3.js"></script>
	<script type="text/javascript" src="../includes/jQuery/sexyalertbox.v1.2.jquery.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="../includes/jQuery/sexyalertbox.css"/>

</head>

<body>
<div id="superior">
<div id="logo"><img src="../Imagenes/logo.png" border="0" usemap="#Map"/>
            <map name="Map" id="Map">
              <area shape="rect" coords="4,5,271,62" href="Start.html" />
            </map>
</div
></div>
</body>
</html>

    <?php 
		
	
	echo '
	<script type="text/javascript">
	function test(){
	Sexy.alert("Error when making your purchase.");}
	window.onload=test;
	</script>';


	die();}
   else
   {session_destroy(); ?>
	<!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>
<link href="../CSS/AltolandonIntranet.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Refresh" CONTENT="3; URL=../Ingles/Cart.php" />
<title>ALTOLANDON</title>
<link rel="shortcut icon" href="../Imagenes/Icono.ico"> 
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.1/mootools-yui-compressed.js"></script>
	<script type="text/javascript" src="../includes/mootools/sexyalertbox.v1.2.moo.js"></script>
	<link rel="stylesheet" type="text/css" media="all" href="../includes/mootools/sexyalertbox.css"/>
	<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
	<script type="text/javascript" src="../includes/jQuery/jquery.easing.1.3.js"></script>
	<script type="text/javascript" src="../includes/jQuery/sexyalertbox.v1.2.jquery.js"></script>
    <link rel="stylesheet" type="text/css" media="all" href="../includes/jQuery/sexyalertbox.css"/>

</head>

<body>
<div id="superior">
<div id="logo"><img src="../Imagenes/logo.png" border="0" usemap="#Map"/>
            <map name="Map" id="Map">
              <area shape="rect" coords="4,5,271,62" href="Start.html" />
            </map>
</div
></div>
</body>
</html>

    <?php 
		
	
	echo '
	<script type="text/javascript">
	function test(){
	Sexy.info("Purchase with success.");}
	window.onload=test;
	</script>';


	die();}
			
			

?>











     
