<?php
require_once('../class/class.wsdlcache.php');
require_once('../class/nusoap.php');

$login = array('Name'=>'Automasters', 'Password'=>'342be991'); $origin = array('LoginData'=>$login, 'Signature'=>'Automastersltd');
$etg_header = array('VersionRequest'=>'1.0.6', 'Originator'=>$origin, 'Request'=>'Test');
$settings = array("ISOcountryCode"=>"BE", "ISOlanguageCode"=>"FR", "ISOcurrencyCode"=>"EUR");
$dloc = "http://webservices.eurotaxglass.com/wsdl/specification.wsdl";

echo (getPrice("85733"));

function getPrice($ncode){
	global $settings, $etg_header, $dloc;
	$vehicle = array('NationalVehicleCode'=>$ncode);
	
	$cache = new wsdlcache();
	$wsdl = $cache->get($dloc);
	if ($wsdl == null) { $wsdl = new wsdl($dloc); $cache->put($wsdl);}
	
	$client = new nusoap_client($wsdl, true);
	$err = $client->getError();
	$client->useHTTPPersistentConnection();
	if(!$err){
		$client->call("GetListHistoricalPrice", array("Settings"=>$settings, "Vehicle"=>$vehicle), "urn:com:eurotaxglass:spec",	"http://www.eurotax.com/GetListHistoricalPrice", array("ETGHeader"=>$etg_header), true, "rpc", "literal");
		$arr = fetchParts($client->response);
		$arr = $arr[0][1];
		$arr = explode("EUR",$arr);
		
		$t = $arr[sizeof($arr)-2];
		$p = strrpos($t,".");
		$p = strrpos(substr($t,0,$p),".");
		
		return ltrim(substr($t,$p+1),"0");
	}else{
		return "0";
	}
}
function fetchParts($res) {
	$t[] = explode("\r\n\r\n",$res);
	return $t;
}
?>