<?php
header('Content-Type: text/html; charset=ISO-8859-1');
$q = (!$_GET["q"])? "" : strtolower($_GET["q"]);
if (!$q) return;
$firephp->log($q, 'q');
$separator = " , "; //Le separateur doit être le même que celui présent dans le code javascript
/** Utilisation du WS **/
$client = new SoapClient(null, array(	'trace'			=> 1,
										'soap_version'	=> SOAP_1_1,
										'location'		=> WEBSERVICE_URL,
										'uri'			=> WEBSERVICE_URI,
										'login'			=> $_SESSION['tabInfo']['login'],
										'password'		=> $_SESSION['tabInfo']['password'],
//										'encoding'		=> 'UTF-8'
));

//raisonSociale adresse codePostal Ville Siege actif deb nbRep maxRep Pertinence AvecSIREN naf
try {
	$O = $client->searchNomAdr($q, '', '', '', true, true, 0, 20, 200, false, true, '6910Z');
	$tableResults = array();
	$tableResults = $O['results']['reponses'];

	$firephp->log($tableResults, 'Result');
	$firephp->log(count($tableResults), 'count');

	if( count($tableResults)>0 ){
		$i=0;
		foreach ($tableResults as $value){
			$return = $value['Nom'];
			$return.= $separator;
			$return.= $value['CP'];
			$return.= $separator;
			$return.= $value['Ville'];
			$return.= $separator;
			$return.= $value['Siret'];
			$return.= "\n";
			print html_entity_decode($return);
		}
	}
}catch (SoapFault $fault){
	print 'Erreur durant la recherche';
}
?>