extranet/www/pages/international_recherche.php
2009-05-14 16:44:01 +00:00

332 lines
12 KiB
PHP

<?php
session_start();
if (!$_SESSION['connected']) die();
$tabInfo = $_SESSION['tabInfo'];
$vue = isset($_REQUEST['vue']) ? $_REQUEST['vue'] : 'recherche';
require_once 'graydon/graydon_log.php';
require_once 'dbbootstrap.php';
/* Affichage du formulaire de recherche */
if($vue=='recherche'){
?>
<script type="text/javascript">
$(document).ready(function(){
$('#mode').change(function(){
var mode = $('#mode :selected').val();
document.location.href='<?php print EXTRANET_URL; ?>?page=international_recherche&mode='+mode;
});
$('#pays').change(function(){
var pays = $('#pays :selected').val();
$('#method').html('<p><img src="./img/ajax/19-1.gif" /></p>');
$('#method').load('./pages/graydon/methodfield.php', {'pays': pays});
});
});
</script>
<div id="international">
<h2 class="StyleRechercheTitre">RECHERCHE INTERNATIONALE</h2>
<form name="recherche" method="post" action="index.php?page=international_recherche">
<input type="hidden" name="vue" value="list">
<div class="fieldgrp">
<label>Mode : </label>
<div class="field">
<select id="mode" name="mode">
<option value="demo" <?php $_REQUEST['mode']=='demo' ? print ' selected' : '' ;?>>Démonstration</option>
<option value="normal" <?php $_REQUEST['mode']=='normal' ? print ' selected' : '' ;?>>Normal</option>
</select>
</div>
</div>
<div id="subsearch">
<?php
//Si les paramètres mode, method sont dans l'url alors on force la méthode de recherche
if(isset($_REQUEST['method']))
{
$method = $_REQUEST['method'];
$pays = $_SESSION['graydon']['pays'];
}
require_once 'international_rechercheform.php';
?>
</div>
</form>
</div>
<?php
}elseif($vue=='list'){
//*********** Mode démonstration
if($_REQUEST['mode']=='demo'){
$pays = $_REQUEST['frmDemo']['Country'];
$_SESSION['graydon']['pays'] = $pays;
$_SESSION['graydon']['mode'] = 'demo';
?>
<div id="internationallist">
<span class="StyleInfoLib">Résultat de la recherche de démonstration :</span>
<?php
require_once 'i18n/cleanchar.php';
require_once 'graydon/graydonws.php';
// Create the request parameters
$request = new StdClass();
// Initialise the request object
$request->Authentication_Parameters = $authentication;
$request->Country = $pays;
try
{
// Make a request on the web service
$result = $graydon->getDemoCompanies($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getDemoCompanies', $transactionIdentifier, $sessionID, $manager);
//Log de la requete dans la bdd
setDbConn('graydon');
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getDemoCompanies';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = 'demo';
$log->save();
//Get the list of companies
$demoCompaniesCountry = $result->DemoCompanies->CountryAndCompany;
?>
<br/>
<span class="StyleInfoLib">Pays :</span> <span><?php print $demoCompaniesCountry->Country; ?></span>
<ol>
<?php
$demoCompanies = array();
//Enregitrement de la liste en session
$count = count($demoCompaniesCountry->Companies->Company);
if ($count>1){
$demoCompanies = $demoCompaniesCountry->Companies->Company;
}elseif($count==1){
$demoCompanies[] = $demoCompaniesCountry->Companies->Company;
}
$firephp->log($demoCompanies,'demoCompanies');
$counterCompany = 1;
foreach($demoCompanies as $company){
?>
<li class="StyleInfoData" type="1" value="<?php print $counterCompany++; ?>">
<b><a title="Voir la fiche d'identit&eacute; de cet &eacute;tablissement" href="index.php?page=international_identite&mode=demo&identifier=<?php print $company->CompanyMatchIdentifier;?>">
<?php print cleanutf8($company->Name); ?></a></b><br />
Adresse :
<?php
print cleanutf8($company->RegisteredAddress->EntireAddress);
?><br/><br/>
</li>
<?php
}
?>
</ol>
</div>
<?php
}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);
}
}
//*********** Mode normal
}elseif($_REQUEST['mode']=='normal'){
$paysCode = $_REQUEST['frmDemo']['CountryCode'];
//Lire le libélé du pays graydon en fonction du code
setDbConn('graydon');
$q = Doctrine_Query::Create()
->select('graydon_country')
->from('Country')
->where('code = ?', $paysCode);
$result = $q->fetchOne();
$pays = $result->graydon_country;
$_SESSION['graydon']['pays'] = $pays;
$_SESSION['graydon']['paysCode'] = $paysCode;
$_SESSION['graydon']['mode'] = 'normal';
?>
<div id="internationallist">
<span class="StyleInfoLib">Résultat de la recherche :</span>
<?php
require_once 'i18n/cleanchar.php';
require_once 'graydon/graydonws.php';
// Create the request parameters
$request = new StdClass();
// Initialise the request object
$request->Authentication_Parameters = $authentication;
// Create a new country parameters object
$company = new StdClass();
// Initialise the country object
$company->Country = $pays;
$company->ClientReference = '';
$request->Authentication_Parameters = $authentication;
$request->CompanyMatches_Parameters = $company;
if($_REQUEST['method'] == 'keyword'){
$request->Keyword = $_REQUEST['frmRecherche']['Keywords'];
$request->City = isset($_REQUEST['frmRecherche']['City']) ? $_REQUEST['frmRecherche']['City'] : '' ;
$request->PostCode = isset($_REQUEST['frmRecherche']['PostCode']) ? $_REQUEST['frmRecherche']['PostCode'] : '' ;
}elseif($_REQUEST['method'] == 'identifier'){
$request->Identifier = $_REQUEST['frmRecherche']['Identifier'];
}elseif($_REQUEST['method'] == 'name'){
$request->Name = $_REQUEST['frmRecherche']['Name'];
$request->City = isset($_REQUEST['frmRecherche']['City']) ? $_REQUEST['frmRecherche']['City'] : '' ;
$request->PostCode = isset($_REQUEST['frmRecherche']['PostCode']) ? $_REQUEST['frmRecherche']['PostCode'] : '' ;
}elseif($_REQUEST['method'] == 'postcode'){
$request->PostCode = isset($_REQUEST['frmRecherche']['PostCode']) ? $_REQUEST['frmRecherche']['PostCode'] : '' ;
}
$firephp->log($request,'requete');
try
{
// Make a request on the webservice
if($_REQUEST['method'] == 'keyword'){
$result = $graydon->getCompanyMatchesByKeyword($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchesByKeyword', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
setDbConn('graydon');
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyMatchesByKeyword';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = 'normal';
$log->save();
}elseif($_REQUEST['method'] == 'identifier'){
$result = $graydon->getCompanyMatchesByIdentifier($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchesByIdentifier', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
setDbConn('graydon');
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyMatchByIdentifier';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = 'normal';
$log->save();
}elseif($_REQUEST['method'] == 'name'){
$result = $graydon->getCompanyMatchesByName($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchesByName', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
setDbConn('graydon');
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyMatchesByName';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = 'normal';
$log->save();
}elseif($_REQUEST['method'] == 'postcode'){
$result = $graydon->getCompanyMatchesByPostCode($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchesByPostCode', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
setDbConn('graydon');
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyMatchesByPostCode';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = 'normal';
$log->save();
}
$_SESSION['graydon']['SessionID'] = $result->Service_Log->SessionID;
$_SESSION['graydon']['TransactionIdentifier'] = $result->Service_Log->TransactionIdentifier;
?>
<br/>
<span class="StyleInfoLib">Pays :</span> <span><?php print $result->Service_Log->Country; ?></span>
<ol>
<?php
$count = count($result->CompanyMatches->Company);
if ($count>1){
$companies = $result->CompanyMatches->Company;
}elseif($count==1){
$companies[] = $result->CompanyMatches->Company;
}
$firephp->log($companies,'companies');
$counterCompany = 1;
foreach($companies as $company){
?>
<li class="StyleInfoData" type="1" value="<?php print $counterCompany++; ?>">
<b><a title="Voir la fiche d'identit&eacute; de cet &eacute;tablissement" href="index.php?page=international_identite&identifier=<?php print $company->CompanyMatchIdentifier;?>">
<?php print cleanutf8($company->Name); ?></a></b><br />
Addresse :
<?php
print cleanutf8($company->RegisteredAddress->EntireAddress);
?><br />
</li>
<?php
}
?>
</ol>
<br/>
<p class="StyleInfoLib">Si aucun résultat ne correspond à votre recherche. <a href="#">Cliquez-ici.</a></p>
</div>
<?php
}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';
$error = graydon_error($code, $text);
if($error==FALSE){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}elseif($error['Code'] == 'CWS5000'){
?>
<br/>
<p class="StyleInfoLib">Aucun résultat n'a été trouvé. <a href="#">Cliquez-ici pour retourner au formulaire de recherche.</a></p
<?php
//Proposition commande de rapport
//Proposition enquete
}
}
}
}
?>