298 lines
11 KiB
PHP
Raw Normal View History

2013-11-05 11:18:30 +00:00
<?php
ini_set('soap.wsdl_cache_enabled', 0);
ini_set('default_socket_timeout', 30);
2013-12-26 14:25:59 +00:00
class MAmabis
{
2013-11-05 11:18:30 +00:00
private $client;
2014-06-02 08:41:24 +00:00
public function __construct()
2013-11-05 11:18:30 +00:00
{
$this->client = new SoapClient(null, array(
2014-06-02 08:41:24 +00:00
'location' => 'http://sw2.amabis.com:5100/',
'uri' => 'http://www.amabis.com/ns.xsd',
'connection_timeout' => 2,
'soap_version' => SOAP_1_1,
'trace' => 1,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
2013-11-05 11:18:30 +00:00
));
}
2014-06-02 08:41:24 +00:00
public function getZonage($adrNum, $adrIndRep, $adrTypeVoie, $adrLibVoie, $cp, $ville='', $codeRivoli='', $rnvp=false, $raisonSociale='TEST', $debug=false)
2013-12-26 14:25:59 +00:00
{
2013-11-05 11:18:30 +00:00
$tabRep=array();
if (!$rnvp) {
if ($cp<10000) $cp='0'.$cp;
$dep2=substr($cp,0,2)*1;
$dep3=substr($cp,0,3)*1;
switch ($dep2) {
case 0:
2013-12-26 14:25:59 +00:00
/*case 5:
2013-11-05 11:18:30 +00:00
case 9:
case 15:
case 19:
case 23:
case 32:
case 46:
case 48:
2013-12-26 14:25:59 +00:00
case 82:*/
2013-11-05 11:18:30 +00:00
case 97: // DOM
case 98: // TOM
case 99: // Etranger
return $tabRep;
break;
default:
//if ($dep3==975) return $tabRep;
break;
}
}
$iDb=new WDB();
$adresse=addslashes(trim(preg_replace('/ +/',' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie")));
$ville=addslashes($ville);
2013-12-26 14:25:59 +00:00
$majForcee=false;
$ret=$iDb->select( 'zonage', 'zus, zru, zfu, cucs, rnvpStatut, rnvpCorr, rnvpTrt, adr3, adr4, adr5, adr6, adr7, numVoieA, indRepA,
typeVoieAlong, typeVoieAcourt, corpVoie, motDir, motDirD, libVoieSec, adr4n32, adr4n38, clePostaleVoie,
secteur, cleRoutage, cpx, cleAd, codPaysIso2, codPaysIso3, libPays, codeInsee',
"address='$adresse' AND adr_cp='$cp' AND adr_ville='$ville'",false, MYSQL_ASSOC);
$zones=@$ret[0];
2013-11-05 11:18:30 +00:00
if (count($ret)>0) {
2013-12-26 14:25:59 +00:00
if ($zones['rnvpStatut']===null && $rnvp) $majForcee=true;
2013-11-05 11:18:30 +00:00
$tabRep['ZUS']=$tabRep['ZFU']=$tabRep['ZRU']=$tabRep['CUCS']='NON';
2013-12-26 14:25:59 +00:00
//$tabRep['NZUS']=$tabRep['NZFU']=$tabRep['NZRU']=$tabRep['NCUCS']='';
2013-11-05 11:18:30 +00:00
if (trim($zones['zus'])<>'') {
if (trim($zones['zus'])=='NSP') $tabRep['ZUS']='NSP';
else $tabRep['ZUS']='OUI';
$tabRep['NZUS']=$zones['zus'];
}
if (trim($zones['zru'])<>'') {
if (trim($zones['zru'])=='NSP') $tabRep['ZRU']='NSP';
else $tabRep['ZRU']='OUI';
$tabRep['NZRU']=$zones['zru'];
}
if (trim($zones['zfu'])<>'') {
if (trim($zones['zfu'])=='NSP') $tabRep['ZFU']='NSP';
else $tabRep['ZFU']='OUI';
$tabRep['NZFU']=$zones['zfu'];
}
if (trim($zones['cucs'])<>'') {
if (trim($zones['cucs'])=='NSP') $tabRep['CUCS']='NSP';
else $tabRep['CUCS']='OUI';
$tabRep['NCUCS']=$zones['cucs'];
}
2013-12-26 14:25:59 +00:00
2013-11-05 11:18:30 +00:00
} else {
2013-12-26 14:25:59 +00:00
/** Autres Informations de la RNVP
**/
if ($rnvp) {
//$tabRep['ADR1']=@trim($tabZones['ADR1']);
//$tabRep['ADR2']=@trim($tabZones['ADR2']);
if (strtoupper(@trim($zones['adr7']))=='FRANCE') $zones['adr7']='';
$tabRep['ADR3']=@trim($zones['adr3']);
$tabRep['ADR4']=@trim($zones['adr4']);
$tabRep['ADR5']=@trim($zones['adr5']);
$tabRep['ADR6']=@trim($zones['adr6']);
$tabRep['ADR7']=trim($zones['adr7']);
}
}
if (count($ret)==0 || $majForcee) {
2013-11-05 11:18:30 +00:00
try {
if (trim($raisonSociale)=='') $raisonSociale='TEST'; // Le RNVP ne fonctionne pas sans la Raison Sociale qui est la 1ère ligne d'adresse
$rep=$this->client->zonage( new SoapParam(strtr("$raisonSociale:$adresse:$cp:$ville",
'¿°ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûýýþÿ??',
' aaaaaaaceeeeiiiidnoooooouuuuybsaaaaaaaceeeeiiiidnoooooouuuyybyRr'),'adresse'),
new SoapParam(':','separateur'),
new SoapParam('type=M','options')
);
/*$rep=$this->client->zonage( "<adresse></adresse>".
"<separateur>:</separateur>".
"<options>type=M</options>");*/
/** Découpage des ZFU, CUCS etcs...
**/
$fp=fopen(LOG_PATH.'/amabis.log', 'a');
fwrite($fp, date('d-m-Y H:i:s').' - '.implode("\n", $rep)."\n============================================================================\n");
fclose($fp);
$tabZones=explode(',',$rep['zonage']); // ZUS=OUI,NZUS=1127020,ZFU=OUI,NZFU=11270ZF,CUCS=OUI,NCUCS=1127020
foreach ($tabZones as $zone) {
$tabTmp=explode('=',$zone);
if (trim($tabTmp[0])<>'')
$tabRep[$tabTmp[0]]=$tabTmp[1];
}
2013-12-26 14:25:59 +00:00
if (@$tabRep['ZUS']=='NSP') $tabRep['NZUS']='NSP';
if (@$tabRep['ZRU']=='NSP') $tabRep['NZRU']='NSP';
if (@$tabRep['ZFU']=='NSP') $tabRep['NZFU']='NSP';
if (@$tabRep['CUCS']=='NSP') $tabRep['NCUCS']='NSP';
2013-11-05 11:18:30 +00:00
$adresse=stripslashes(trim(preg_replace('/ +/',' ', "$adrNum $adrIndRep $adrTypeVoie $adrLibVoie")));
$ville=stripslashes($ville);
2013-12-26 14:25:59 +00:00
$tabRepTmp=array();
$tabTmp=explode('=',utf8_decode($rep['objdesc']));
//print_r($tabTmp);
//die();
$tabZones=array();
foreach ($tabTmp as $iZone=>$zone) {
$pos=strrpos($zone,',');
if ($iZone==0) {
$nomZoneSuiv=$zone;
continue;
}
$tabZones[$nomZoneSuiv]=substr($zone,0,$pos);
$nomZoneSuiv=substr($zone,$pos+1);
}
if (strtoupper(@trim($tabZones['ADR7']))=='FRANCE') $tabZones['ADR7']='';
$tabTmp=explode('|', $tabZones['VOIEA']);
$typeVoieAcourt=@trim($tabTmp[1]);
$tabInsert=array(
'address'=>$adresse,
'adr_cp'=>$cp,
'adr_ville'=>$ville,
'zus'=>@$tabRep['NZUS'],
'zru'=>@$tabRep['NZRU'],
'zfu'=>@$tabRep['NZFU'],
'cucs'=>@$tabRep['NCUCS'],
);
$tabUpdate=array(
'adrNum'=>$adrNum,
'adrIndRep'=>$adrIndRep,
'adrTypeVoie'=>$adrTypeVoie,
'adrLibVoie'=>$adrLibVoie,
'rivoli'=>$codeRivoli,
// Ajouté le 16/12/2013
'rnvpStatut' => substr($tabZones['STATUTC'],0,2),
'rnvpCorr' => substr($tabZones['STATUTC'],2,1),
'rnvpTrt' => trim(substr($tabZones['STATUTC'],3,2)),
'adr3' => @trim($tabZones['ADR3']),
'adr4' => @trim($tabZones['ADR4']),
'adr5' => @trim($tabZones['ADR5']),
'adr6' => @trim($tabZones['ADR6']),
'adr7' => trim($tabZones['ADR7']),
'numVoieA' => @trim($tabZones['NUM1']),
'indRepA' => @trim($tabZones['BTQC1']),
'typeVoieAlong' => @trim($tabZones['TYPVOIEL']),
'typeVoieAcourt' => $typeVoieAcourt,
'corpVoie' => @trim($tabZones['CORPSVOIE']),
'motDir' => @trim($tabZones['MOTDIR']),
'motDirD' => @trim($tabZones['MOTDIRD']),
'libVoieSec' => @trim($tabZones['VOIREFLIBS']),
'adr4n32' => @trim($tabZones['VOIREFLIBPOS']),
'adr4n38' => @trim($tabZones['VOIREFLIBPOS2']),
'clePostaleVoie' => @trim($tabZones['VOIREFCLEPOST']),
'secteur' => @trim($tabZones['SECTEUR']),
'cleRoutage' => @trim($tabZones['CLER']),
'cpx' => @trim($tabZones['CPX']),
'cleAd' => @trim($tabZones['CLEAD']),
'codPaysIso2' => @trim($tabZones['NATREFISO2']),
'codPaysIso3' => @trim($tabZones['NATREFISO3']),
'libPays' => @trim($tabZones['NATREFLIB']),
'codeInsee' => @trim($tabZones['LOCREFCLEO']),
'source' => 'Amabis',
);
$dateInsert=0;
if ($majForcee) {
$adresseL=addslashes($adresse);
$villeL=addslashes($ville);
$ret=$iDb->select('zonage', 'dateInsert*1 as dateInsert', "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
$dateInsert=@$ret[0]['dateInsert']*1;
$iDb->update('zonage', array_merge($tabUpdate,array('dateInsert'=>$dateInsert)), "address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'", false);
//echo "Mise à jour de l'adresse du $dateInsert pour address='$adresseL' AND adr_cp='$cp' AND adr_ville='$villeL'".EOL;
}
if ($dateInsert==0) {
$iDb->insert('zonage', array_merge($tabInsert,$tabUpdate), false);
//echo "Insertion de l'adresse (".$zones['rnvpStatut'].")!".EOL;
}
$tabTmp[0]=explode(',', $tabZones['LOCREFCLEP']);
$tabTmp[1]=explode(',', $tabZones['LOCREFCP']);
$tabTmp[2]=explode(',', $tabZones['LOCREFTYPP']);
$tabTmp[3]=explode(',', $tabZones['LOCREFLIBD']);
$tabTmp[4]=explode(',', $tabZones['LOCREFLIBD2']);
foreach($tabTmp[0] as $iCleP=>$cleP) {
$tabInsert=array(
'codeInsee' => @trim($tabZones['LOCREFCLEO']),
'villeLib' => @trim($tabZones['LOCREFLIBP']),
'villePopu' => @trim($tabZones['LOCREFPOP']),
'cleAchPost'=> $cleP,
'codePostal'=> $tabTmp[1][$iCleP],
'typePostal'=> $tabTmp[2][$iCleP],
'libAchP32' => @preg_replace('/^\//','',$tabTmp[3][$iCleP]),
'libAchP38' => @preg_replace('/^\//','',$tabTmp[4][$iCleP]),
'source' => 'Amabis',
'dateInsert'=> date('YmdHis'),
);
$iDb->insert('villesCP', $tabInsert);
//echo mysql_error().EOL;
}
2013-11-05 11:18:30 +00:00
/** Autres Informations de la RNVP
**/
2013-12-26 14:25:59 +00:00
if ($rnvp) {
//$tabRep['ADR1']=@trim($tabZones['ADR1']);
//$tabRep['ADR2']=@trim($tabZones['ADR2']);
$tabRep['ADR3']=@trim($tabZones['ADR3']);
$tabRep['ADR4']=@trim($tabZones['ADR4']);
$tabRep['ADR5']=@trim($tabZones['ADR5']);
$tabRep['ADR6']=@trim($tabZones['ADR6']);
$tabRep['ADR7']=trim($tabZones['ADR7']);
2013-11-05 11:18:30 +00:00
}
} catch (SoapFault $fault) {
2013-12-26 14:25:59 +00:00
//echo 'ERREUR SOAP :'.EOL;
//print_r($fault);
//echo $this->client->__getLastRequest()."\n";
//echo $this->client->__getLastResponse()."\n";
2013-11-05 11:18:30 +00:00
$fp=fopen(LOG_PATH.'/amabis.log', 'a');
fwrite($fp, date('d-m-Y H:i:s').' - ERREUR SOAP : Requete = '.$this->client->__getLastRequest()."\n Reponse = ".$this->client->__getLastResponse()."\n============================================================================\n");
fclose($fp);
}
//return $tabRep;
}
2013-12-26 14:25:59 +00:00
/** Zonages AFR et ZRR
**/
2013-11-05 11:18:30 +00:00
$codeInsee=substr($codeRivoli,0,5);
$ret=$iDb->select( 'zonageInsee', 'typeZone, arreteDate, decretDate, decretNum, decretModifieDate, decretModifieNum, dateDebut, dateFin', "codeInsee='$codeInsee'",false, MYSQL_ASSOC);
$tabRep['ZRR']=$tabRep['AFR']='NON';
foreach ($ret as $zones)
switch ($zones['typeZone']) {
case 'ZRR': $tabRep['ZRR']='OUI'; $tabRep['NZRR']=$codeInsee; break;
case 'ZAFR': $tabRep['AFR']='OUI'; $tabRep['NAFR']=$codeInsee; break;
default: break;
}
return $tabRep;
}
function searchByTelFax($tel) {
return $this->getTelFax('','','','',$tel);
}
function getTelFax($nom, $cp, $ville='', $prenom='', $tel='') {
if (trim($tel)<>'')
$query="<telep>$tel</telep><scoremini>10</scoremini><distinction>30</distinction>";
elseif (trim($prenom)=='')
$query="<rs>$nom</rs><cpville>$cp $ville</cpville><scoremini>90</scoremini><distinction>30</distinction>";
else
$query="<nom>$nom</nom><prenom>$prenom</prenom><cpville>$cp $ville</cpville><scoremini>90</scoremini><distinction>30</distinction>";
$rep=$this->client->rechtel($query);
$fp=fopen(LOG_PATH.'/amabis.log', 'a');
fwrite($fp, date('d-m-Y H:i:s')." - $query - ".implode("\n", $rep)."\n============================================================================\n");
fwrite($fp, "Requête : ".$this->client->__getLastRequest()."\n");
fwrite($fp, "Réponse : ".$this->client->__getLastResponse()."\n");
fclose($fp);
}
}
?>