<?php
	error_reporting(E_ALL);
	ini_set('display_errors', 1);
	ini_set('memory_limit', '512M');
	date_default_timezone_set('Europe/Madrid');
	//include("conexion.php");
	if(isset($_REQUEST["code"])) 
		$code=$_REQUEST["code"]; else $code=0;
	if(isset($_REQUEST["desc1"]))
		$desc1=$_REQUEST["desc1"]; else $desc1=0;
	if(isset($_REQUEST["desc2"]))
		$desc2=$_REQUEST["desc2"]; else $desc2=0;
		
	function mssql_escape($str)
	{
		if(get_magic_quotes_gpc())
		{
			$str= stripslashes($str);
		}
		return str_replace("'", "''", $str);
	}

	$serverName = "localhost";
	$connectionInfo = array( "Database"=>"ICF", "UID"=>"VAIO", "PWD"=>"VAIO");

	$connNavision=false;
	$retries=0;
	while(!$connNavision && $retries<3){
		$connNavision = sqlsrv_connect( $serverName, $connectionInfo);
		$retries++;
	}

	if( $connNavision ) {
		//echo "Conexion establecida con Navision.\r\n";
	}else{
		//echo "Conexion no se pudo establecer con Navision.\r\n";
		die( print_r( sqlsrv_errors(), true));
	}

	$objects=[];
	$sql='UPDATE [Item] 
		SET [Description] = \''.utf8_decode($desc1).'\', [Description 2]=\''.utf8_decode($desc2).'\', [Descripcion larga]=\''.utf8_decode($desc1).''.utf8_decode($desc2).'\'
		WHERE [No.] = \''.$code.'\'';

$stmt = sqlsrv_query( $connNavision, $sql );

header('Content-Type: application/json');
echo json_encode($stmt, JSON_PRETTY_PRINT);
?>
