186 lines
6.8 KiB
PHP
186 lines
6.8 KiB
PHP
<?php
|
|
if(!isset($method)){
|
|
$pays = $_REQUEST['pays'];
|
|
}
|
|
|
|
$tabInfo = $_SESSION['tabInfo'];
|
|
$mode = $_SESSION['graydon']['mode'];
|
|
|
|
require_once 'graydon/graydonws.php';
|
|
require_once 'graydon/graydon_log.php';
|
|
require_once 'dbbootstrap.php';
|
|
require_once 'dbgraydon.php';
|
|
|
|
//Disponibilité des pays
|
|
$q = Doctrine_Query::create()
|
|
->from('Countryavailability')
|
|
->where('country = ?', $pays);
|
|
|
|
$countryavailability = new Countryavailability();
|
|
$countryavailability = $q->fetchOne();
|
|
$nbResult = $q->count();
|
|
|
|
if($nbResult == 0){
|
|
// Create the request parameters
|
|
$request = new StdClass();
|
|
// Initialise the request object
|
|
$request->Authentication_Parameters = $authentication;
|
|
$request->Country = $pays;
|
|
try
|
|
{
|
|
$result = $graydon->getCountryAvailability($request);
|
|
|
|
//Enregistrement de l'action dans les logs
|
|
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
|
|
$sessionID = $result->Service_Log->SessionID;
|
|
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCountryAvailability', $transactionIdentifier, $sessionID);
|
|
|
|
//Log de la requete dans la bdd
|
|
$log = new Requetelog();
|
|
$log->login = $_SESSION['tabInfo']['login'];
|
|
$log->action = 'getCountryAvailability';
|
|
$log->request = serialize($request);
|
|
$log->transactionIdentifier = $transactionIdentifier;
|
|
$log->sessionID = $sessionID;
|
|
$log->mode = $mode;
|
|
$log->save();
|
|
|
|
$count = count($result->CountryAvailablity->CountryAndProduct->Products->Product);
|
|
if ($count>1){
|
|
$availability = $result->CountryAvailablity->CountryAndProduct->Products->Product;
|
|
}elseif($count==1){
|
|
$availability[] = $result->CountryAvailablity->CountryAndProduct->Products->Product;
|
|
}
|
|
|
|
//Stockage du résultat de la méthode en cache
|
|
$countryavailability = new Countryavailability();
|
|
$countryavailability->country = $pays;
|
|
$countryavailability->availability = serialize($availability);
|
|
$countryavailability->replace();
|
|
|
|
//file_put_contents($path.'/'.$fileName, serialize($availability));
|
|
|
|
}catch(SoapFault $fault){
|
|
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
|
|
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
|
|
$firephp->log($text,'texterror');
|
|
require_once 'graydon/graydon_error.php';
|
|
if(graydon_error($code, $text)==FALSE){
|
|
graydon_processSoapFault($graydon,$fault,$tabInfo);
|
|
}
|
|
}
|
|
}else{
|
|
$availability = unserialize($countryavailability->availability);
|
|
}
|
|
|
|
|
|
//Méthodes de recherche disponible pour les pays
|
|
$q = Doctrine_Query::create()
|
|
->from('Matchmethods')
|
|
->where('country = ?', $pays);
|
|
|
|
$matchmethods = new Matchmethods();
|
|
$matchmethods = $q->fetchOne();
|
|
$nbResult = $q->count();
|
|
|
|
if($nbResult == 0){
|
|
// Create the request parameters
|
|
$request = new StdClass();
|
|
// Initialise the request object
|
|
$request->Authentication_Parameters = $authentication;
|
|
$request->Country = $pays;
|
|
|
|
try
|
|
{
|
|
$result = $graydon->getCompanyMatchMethods($request);
|
|
|
|
//Enregistrement de l'action dans les logs
|
|
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
|
|
$sessionID = $result->Service_Log->SessionID;
|
|
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchMethods', $transactionIdentifier, $sessionID);
|
|
|
|
//Log de la requete dans la bdd
|
|
$log = new Requetelog();
|
|
$log->login = $_SESSION['tabInfo']['login'];
|
|
$log->action = 'getCompanyMatchMethods';
|
|
$log->request = serialize($request);
|
|
$log->transactionIdentifier = $transactionIdentifier;
|
|
$log->sessionID = $sessionID;
|
|
$log->mode = $mode;
|
|
$log->save();
|
|
|
|
$count = count($result->CompanyMatchMethods->CompanyMatchMethod->MatchMethods->MatchMethod);
|
|
if ($count>1){
|
|
$methods = $result->CompanyMatchMethods->CompanyMatchMethod->MatchMethods->MatchMethod;
|
|
}elseif($count==1){
|
|
$methods[] = $result->CompanyMatchMethods->CompanyMatchMethod->MatchMethods->MatchMethod;
|
|
}
|
|
|
|
//Stockage du résultat de la méthode en cache
|
|
$matchmethods = new Matchmethods();
|
|
$matchmethods->country = $pays;
|
|
$matchmethods->methods = serialize($methods);
|
|
$matchmethods->replace();
|
|
|
|
}catch( SoapFault $fault ){
|
|
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
|
|
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
|
|
$firephp->log($text,'texterror');
|
|
require_once 'graydon/graydon_error.php';
|
|
if(graydon_error($code, $text)!=FALSE){
|
|
if($code=='CWS0112'){
|
|
//Stockage du résultat de la méthode en cache
|
|
$matchmethods = new Matchmethods();
|
|
$matchmethods->country = $pays;
|
|
$matchmethods->methods = serialize('false');
|
|
$matchmethods->replace();
|
|
}
|
|
}else{
|
|
graydon_processSoapFault($graydon,$fault,$tabInfo);
|
|
}
|
|
}
|
|
}else{
|
|
$methods = unserialize($matchmethods->methods);
|
|
}
|
|
|
|
if (isset($methods) && $methods!='false'){
|
|
$firephp->log($methods,'methods');
|
|
//Affichage de la meilleur méthode de recherche OU la première
|
|
$lien = 'Effectuer une recherche : ';
|
|
$flagBestMethod = false;
|
|
$countMethods = 0;
|
|
foreach($methods as $item){
|
|
$WithCity = $item->WithCity;
|
|
$WithPostCode = $item->WithPostCode;
|
|
if( ($item->BestMethod==TRUE && $item->MatchingMethod=='Keyword') && !isset($method) || $method=='keyword' ){
|
|
$flagBestMethod = TRUE;
|
|
require_once realpath(dirname(__FILE__)).'/method_keyword.php';
|
|
}elseif( ($item->BestMethod==TRUE && $item->MatchingMethod=='Identifier') && !isset($method) || $method=='identifier' ){
|
|
$flagBestMethod = TRUE;
|
|
require_once realpath(dirname(__FILE__)).'/method_identifier.php';
|
|
}elseif( ($item->BestMethod==TRUE && $item->MatchingMethod=='Name') && !isset($method) || $method=='name' ){
|
|
$flagBestMethod = TRUE;
|
|
require_once realpath(dirname(__FILE__)).'/method_name.php';
|
|
}elseif( ($item->BestMethod==TRUE && $item->MatchingMethod=='PostCode') && !isset($method) || $method=='postcode' ){
|
|
$flagBestMethod = TRUE;
|
|
require_once realpath(dirname(__FILE__)).'/method_postcode.php';
|
|
}
|
|
|
|
$countMethods++;
|
|
|
|
//Affichage des propostions des méthodes de recherche
|
|
if($item->MatchingMethod=='Keyword'){ $lien .= '<a href="?page=international_recherche&mode=normal&method=keyword&pays='.$pays.'">Par mots clés</a>'; }
|
|
if($item->MatchingMethod=='Identifier'){ $lien .= '<a href="?page=international_recherche&mode=normal&method=identifier&pays='.$pays.'">Par identifiant</a>'; }
|
|
if($item->MatchingMethod=='Name'){ $lien .= '<a href="?page=international_recherche&mode=normal&method=name&pays='.$pays.'">Par nom</a>'; }
|
|
if($item->MatchingMethod=='PostCode'){ $lien .= '<a href="?page=international_recherche&mode=normal&method=postcode&pays='.$pays.'">Par Post Code</a>'; }
|
|
|
|
if($countMethods>=count($methods)){ $separator=''; break; }else{ $separator=' - '; }
|
|
|
|
$lien = $lien.$separator;
|
|
}
|
|
|
|
print '<span class="left">'.$lien.'</span>';
|
|
}else{
|
|
print 'Il n\'est pas possible de faire une recherche dans la base de ce pays. Pour commander une enquête sur ce pays rendez-vous sur cette <a href="/?page=international_enquete&pays='.$pays.'">page</a>.';
|
|
}
|
|
?>
|