extranet/www/pages/graydon/methodfield.php
2009-05-04 16:59:52 +00:00

168 lines
5.9 KiB
PHP

<?php
if(!isset($method)){
$pays = $_REQUEST['pays'];
}
$tabInfo = $_SESSION['tabInfo'];
require_once 'graydon/graydonws.php';
require_once 'graydon/log.php';
require_once 'dbbootstrap.php';
Doctrine::loadModels(realpath(dirname(__FILE__)).'/../../dashboard/models');
$firephp->log($pays,'PAYS');
//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);
$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
//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){
require_once 'soaperror.php';
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;
$firephp->log($pays,'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);
$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;
/*
Fault
TransactionIdentifier
FaultType
FaultReturnCode
FaultMessage
FaultTip
*/
require_once 'graydon/error.php';
if(graydon_error($code, $text)!=FALSE){
}else{
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}else{
$methods = unserialize($matchmethods->methods);
}
if (isset($methods)){
$firephp->log($methods,'methods');
//Affichage de la meilleur méthode de recherche OU la première
$lien = 'Effectuer un 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>.';
}
?>