<?php include "../index/conexion.inc" ?>
<?php include "../index/validacion.php" ?>
<?php
	if (isset($_POST['Guardar']))
	{
		// VARIABLES FORMULARIO
		$cR01 = $_POST['cV01'];
		$cR02 = $_POST['cV02'];
		$cR03 = $_POST['cV03'];
		$cR04 = $_POST['cV04'];
		$cR05 = $_POST['cV05'];
		$cR06 = substr($_POST['cV06'], 0, strripos($_POST['cV06'], '.'));
		$cR07 = $_POST['cV07'];
		$cR08 = $_POST['cV08'];
		$cR09 = $_POST['cV09'];
		$cR10 = $_POST['cV10'];
		// VARIABLES CLIENTE
		$cC01 = $_POST['CarCod'];
		$cC02 = $_POST['CarNom'];
		$cL03 = $_POST['CarTe1'];
		$cL04 = $_POST['CarTe2'];
		$cL05 = $_POST['CarTe3'];
		// VARIABLES URL
		$cL01 = $_GET['id'];
		$cL02 = $_GET['id2'];
		// conexión
		$servername = $svr_servidor;
		$conectioninfo = array("Database"=>$svr_base, "UID"=>$svr_usuario, "PWD"=>$svr_contrasena, "CharacterSet"=>"UTF-8");
		$conexion = sqlsrv_connect($servername, $conectioninfo);
		if ($conexion == false)
		{
			$mensaje = "Existe un error al intentar conectarse con el servidor...";
		}
		else
		{
			/* INSERTO NUEVAS CAJAS MASTER */
			$sql = "UPDATE PEDVENTACAMPOSLIBRES SET \n"
				  ."FACTURAR = '".$cR01."', \n"
				  ."FORMA_DE_ENVIO = '".$cR02."', \n"
				  ."FORMA_PAGO = '".$cR09."', \n"
				  ."FORMA_PAGO2 = '".$cR10."', \n"
				  ."MUNICIPIO_ENTREGA = '".$cR03."', \n"
				  ."DIAS_DE_VENCIMIENTO = ".$cR04.", \n"
				  ."DIRECCION_ENTREGA = '".$cR05."', \n"
				  ."POBLADO_DE_ENTREGA = '".$cR06."', \n"
				  ."ESTADO_AD = '".$cR07."' \n"
				  ."WHERE (NUMSERIE = '".$cL01."') AND (NUMPEDIDO = ".$cL02.") \n"
				  ."UPDATE CLIENTES SET \n"
				  ."TELEFONO1 = '".$cL03."', \n"
				  ."TELEFONO2 = '".$cL04."', \n"
				  ."MOBIL = '".$cL05."' \n"
				  ."WHERE (CODCLIENTE = ".$cC01.") \n"
				  ."UPDATE PEDVENTACAB SET \n"
				  ."OBSERVRESERVA = '".$cR08."' \n"
				  ."WHERE (NUMSERIE = '".$cL01."') AND (NUMPEDIDO = ".$cL02.")";
			$pa1 = array();
			$op1 = array("scrollable" => SQLSRV_CURSOR_KEYSET);
			$re1 = sqlsrv_query($conexion, $sql, $pa1, $op1);
			if ( $re1 )
			{
				$something = "Submission successful.";
			}
			else
			{
				$something = "Submission unsuccessful.";
				die( print_r( sqlsrv_errors(), true));
			}
			sqlsrv_free_stmt($re1);
		}
		sqlsrv_close($conexion);
	}
	echo "
	<script languaje='javascript' type='text/javascript'>
		self.close();
	</script>
	";
?>