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 );
}
2014-10-31 15:15:08 +00:00
/**
* @ todo Corriger les adresses présentes dans CEDEXA ( toutes les lignes )
* @ todo Ligne 3 , acheter HEXALIGNE3
*/
function normaliseAdresse ( $adrL1 , $adrL2 , $adrL3 , $adrL4 , $adrL5 , $adrL6 , $adrL7 = '' , $norme = 38 ) {
if ( $norme <> 32 && $norme <> 38 ) {
return 'La norme doit être 32 ou 38 caractères (38 par défaut)' . EOL ;
}
$iInsee = new MInsee ();
$iDb = new WDB ( 'villes' );
$adrL = array ();
$adrL [ 1 ] = $adrL1 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL1 )))));
$adrL [ 2 ] = $adrL2 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL2 )))));
$adrL [ 3 ] = $adrL3 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL3 )))));
$adrL [ 4 ] = $adrL4 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL4 )))));
$adrL [ 5 ] = $adrL5 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL5 )))));
$adrL [ 6 ] = $adrL6 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL6 )))));
$adrL [ 7 ] = $adrL7 = trim ( preg_replace ( '/\s+/' , ' ' , preg_replace ( '/[^a-z\d ]/i' , ' ' , strtoupper ( trimAccent ( $adrL7 )))));
if ( $adrL7 <> '' || $adrL7 <> 'FRANCE' || $adrL7 <> 'MONACO' )
$tabLen = $tabMaxLen = array ();
$tabLen [ 1 ] = strlen ( $adrL1 ); if ( $tabLen [ 1 ] > $norme ) $tabMaxLen [] = 1 ;
$tabLen [ 2 ] = strlen ( $adrL2 ); if ( $tabLen [ 2 ] > $norme ) $tabMaxLen [] = 2 ;
$tabLen [ 3 ] = strlen ( $adrL3 ); if ( $tabLen [ 3 ] > $norme ) $tabMaxLen [] = 3 ;
$tabLen [ 4 ] = strlen ( $adrL4 ); if ( $tabLen [ 4 ] > $norme ) $tabMaxLen [] = 4 ;
$tabLen [ 5 ] = strlen ( $adrL5 ); if ( $tabLen [ 5 ] > $norme ) $tabMaxLen [] = 5 ;
$tabLen [ 6 ] = strlen ( $adrL6 ); if ( $tabLen [ 6 ] > $norme ) $tabMaxLen [] = 6 ;
$tabLen [ 7 ] = strlen ( $adrL7 ); if ( $tabLen [ 7 ] > $norme ) $tabMaxLen [] = 7 ;
if ( count ( $tabMaxLen ) > 0 ) {
//print_r($tabLen);
foreach ( $tabMaxLen as $j ) {
echo " La ligne n° $j fait " . $tabLen [ $j ] . " caractères : ' " . $adrL [ $j ] . " ' " . EOL ;
}
if ( $j > 1 ) die ( " Une des lignes fait plus de $norme caractères ! " . EOL );
return " Une des lignes fait plus de $norme caractères ! " . EOL ;
}
$L1 = $adrL1 ;
$L2 = $adrL2 ;
// Ligne 3, acheter HEXALIGNE3
$L3 = $adrL3 ;
// Ligne 5 et 7 par défaut
$L7 = $adrL7 ;
$L5 = $adrL5 ;
// Ligne 6 : CP + Localité
$idAdr56 = false ;
$tabAdr56k = $tabAdr56L = array ();
$cp = substr ( trim ( $adrL6 ), 0 , 5 );
$cp2 = substr ( $cp , 0 , 2 );
$ville = trim ( strtr ( substr ( $adrL6 , 5 ), array ( ' SAINT ' => ' ST ' , ' SAINTE ' => ' STE ' )));
$ret = $iDb -> select ( 'hexaviaVilles' ,
" idAdr56, codeInseeCom, libCom $norme , codeInseeGlobal, indPluridis, libLigne5n $norme , indRoudis, codePostal, libLigne6n $norme , codeInseePre, codeMaj $norme , dateMaj $norme , MATCH (codePostal, libCom38) AGAINST (' $cp $ville ' IN NATURAL LANGUAGE MODE) AS score " ,
" (MATCH (codePostal, libCom38) AGAINST (' $cp $ville ' IN NATURAL LANGUAGE MODE) OR MATCH (codePostal, libCom38) AGAINST (' $cp2 $ville ' IN NATURAL LANGUAGE MODE)) /*OR codePostal=' $cp ' AND libCom $norme =' $ville '*/ " , false , MYSQL_ASSOC );
$nbRet = count ( $ret );
if ( $nbRet == 0 ) return 'Aucune correspondance CP VILLE' . EOL ;
else {
foreach ( $ret as $i => $iRet ) {
//echo "je compare '$cp' avec '".$iRet['codePostal']."' et '$ville' avec '".$iRet["libCom$norme"]."' (".$iRet['idAdr56'].")".EOL;
if (( $iRet [ 'codePostal' ] == $cp || substr ( $iRet [ 'codePostal' ], 0 , 2 ) == $cp2 ) && ( $iRet [ " libCom $norme " ] == $ville || preg_replace ( '/ 0/' , ' ' , $iRet [ " libCom $norme " ]) == $ville ) || ( strpos ( $iRet [ " libCom $norme " ], $ville ) > 0 && $nbRet == 1 )) {
$idAdr56 = $iRet [ 'idAdr56' ];
$dateMajHexavia = $iRet [ " dateMaj $norme " ];
$hexaViaComCod = $iRet [ 'codeInseeCom' ];
$hexaViaComLib = $iRet [ " libCom $norme " ];
$hexaViaCP = $iRet [ 'codePostal' ];
$L5 = $iRet [ " libLigne5n $norme " ];
$L6 = $iRet [ 'codePostal' ] . ' ' . $iRet [ " libLigne6n $norme " ];
$L7 = '' ;
$tabAdr56k [] = $idAdr56 ;
$tabAdr56L [ '_' . $idAdr56 ] = array ( 'L5' => $L5 , 'L6' => $L6 , 'L7' => $L7 ,);
//break;
}
}
if ( ! $idAdr56 ) {
//print_r($ret);
//die('Plusieurs correspondances CP VILLE'.EOL);
return 'Plusieurs correspondances CP VILLE' . EOL ;
}
}
/* if ( count ( $ret ) > 1 ) {
print_r ( $ret );
die ( 'Plusieurs correspondances CP VILLE' . EOL );
return 'Plusieurs correspondances CP VILLE' . EOL ;
}
elseif ( count ( $ret ) == 1 ) {
$ret = $ret [ 0 ];
$idAdr56 = $ret [ 'idAdr56' ];
$L5 = $ret [ " libLigne5n $norme " ];
$L6 = $ret [ 'codePostal' ] . ' ' . $ret [ " libLigne6n $norme " ];
$L7 = '' ;
} */
// Ligne 4 :
$matriculeHexavia = false ;
if ( preg_match ( '/(^(\d{0,4})\s?([a-z]{0,1}))\s(.*)$/i' , $adrL4 , $matches )) {
$numVoieRep = $matches [ 1 ];
$numVoie = $matches [ 2 ];
$indRep = $matches [ 3 ];
$libVoie = $matches [ 4 ];
$libVoie5 = substr ( $libVoie , 0 , 5 );
$tabAdr = $iInsee -> structureVoie ( $libVoie );
$typeVoie =@ $tabAdr [ 'typeVoie' ];
preg_match ( '/([a-z\d]{1,20})$/i' , $libVoie , $matches2 );
$derMot = $matches2 [ 1 ];
$derMot5 = substr ( $derMot , 0 , 5 );
//print_r($matches);
//die($derMot);
//foreach($tabAdr56 as $k=>$tabAdr56) //=array('idAdr56'=>$idAdr56,'L5'=>$L5,'L6'=>$L6,'L7'=>$L7,);
$strAdr56 = implode ( " ',' " , $tabAdr56k );
$ret = $iDb -> select ( 'hexaviaVoies' ,
" idAdr56, codeVoie, derElemVoie, libVoie $norme , typeVoie, descLibVoie, indStand $norme , indScind, indHomo, codePostal, codeRoudis, codeMaj $norme , dateMaj $norme
numImpMin , numImpMinExt , numImpMax , numImpMaxExt , numPairMin , numPairMinExt , numPairMax , numPairMaxExt , MATCH ( libVoie38 ) AGAINST ( '$libVoie' IN NATURAL LANGUAGE MODE ) AS score " ,
// "idAdr56='$idAdr56' AND (MATCH (libVoie38) AGAINST ('$libVoie' IN NATURAL LANGUAGE MODE) OR libVoie38 LIKE '$libVoie5%' OR derElemVoie LIKE '$libVoie5%')/*AND typeVoie='$typeVoie' AND derElemVoie='$derMot'*/",false, MYSQL_ASSOC);
" idAdr56 IN (' $strAdr56 ') AND (MATCH (libVoie38) AGAINST (' $libVoie ' IN NATURAL LANGUAGE MODE) OR libVoie38 LIKE ' $libVoie5 %' OR derElemVoie LIKE ' $libVoie5 %')/*AND typeVoie=' $typeVoie ' AND derElemVoie=' $derMot '*/ " , false , MYSQL_ASSOC );
$nbRet = count ( $ret );
if ( $nbRet == 0 ) {
// Vérifier si la commune à des voies normées 98816
$ret = $iDb -> select ( 'hexaviaVoies' , " codeVoie " , " idAdr56 IN(' $strAdr56 ') " , false , MYSQL_ASSOC );
$nbVoiesCom = count ( $ret );
if ( count ( $ret ) == 0 ) {
return " Aucune Voie recensée dans cette commune (' $strAdr56 ') ! " . EOL ;
}
return " Aucune correspondance Voie pour ' $adrL4 ', ' $libVoie ' ( $nbVoiesCom voies dans la commune # $idAdr56 ) " . EOL ;
}
else {
foreach ( $ret as $i => $iRet ) {
//echo "je compare '$libVoie' avec '".$iRet["libVoie$norme"]."'".EOL;
if ( $iRet [ " libVoie $norme " ] == $libVoie || $iRet [ 'derElemVoie' ] == $derMot || /*substr($iRet["libVoie$norme"],0,5)==$libVoie5 || */ substr ( $iRet [ 'derElemVoie' ], 0 , 5 ) == $derMot5 ) {
$tabAdr = $iInsee -> structureVoie ( $libVoie );
if ( $tabAdr [ 'typeVoie' ] <> $iRet [ 'typeVoie' ] && $nbRet > 1 ) continue ;
$idAdr56 = $iRet [ 'idAdr56' ];
$L4 = preg_replace ( '/\s+/' , ' ' , trim ( $numVoie . ' ' . $indRep . ' ' . $iRet [ " libVoie $norme " ]));
$L4 = preg_replace ( '/^0+/' , '' , $L4 );
$hexaViaVoie = $iRet [ " libVoie $norme " ];
if ( strlen ( $L4 ) > $norme ) return " Taille de la ligne 4 générée en sortie plus longue que $norme ! " . EOL ;
$matriculeHexavia = $iRet [ 'codeVoie' ];
$codeRoudis = $iRet [ 'codeRoudis' ];
$L5 = $tabAdr56L [ '_' . $idAdr56 ][ 'L5' ];
$L6 = $tabAdr56L [ '_' . $idAdr56 ][ 'L6' ];
$L7 = $tabAdr56L [ '_' . $idAdr56 ][ 'L7' ];
break ;
}
}
if ( ! $matriculeHexavia ) {
//print_r($ret);
// die("Plusieurs correspondances Voies pour $adrL4 $adrL6 dans cette commune ('$strAdr56') !".EOL);
return 'Plusieurs correspondances Voies' . EOL ;
}
}
}
/*
if ( count ( $ret ) == 0 ) {
// Vérifier si la commune à des voies normées 98816
$ret = $iDb -> select ( 'hexaviaVoies' , " codeVoie " , " idAdr56=' $idAdr56 ' " , false , MYSQL_ASSOC );
if ( count ( $ret ) == 0 ) {
return 'Aucune Voie recensée dans cette commune !' . EOL ;
}
return 'Aucune correspondance Voie' . EOL ;
}
elseif ( count ( $ret ) > 1 ) {
print_r ( $ret );
$tabAdr = $iInsee -> structureVoie ( $libVoie );
print_r ( $tabAdr );
return 'Plusieurs correspondances Voies' . EOL ;
}
elseif ( count ( $ret ) == 1 ) {
$ret = $ret [ 0 ];
$L4 = preg_replace ( '/\s+/' , ' ' , trim ( $numVoie . ' ' . $indRep . ' ' . $ret [ " libVoie $norme " ]));
if ( strlen ( $L4 ) > $norme ) return " Taille de la ligne 4 générée en sortie plus longue que $norme ! " . EOL ;
$matriculeHexavia = $ret [ 'codeVoie' ];
$codeRoudis = $ret [ 'codeRoudis' ];
}
}
*/
$tabAdr = array (
'L1' => $L1 ,
'L2' => $L2 ,
'L3' => $L3 ,
'L4' => $L4 ,
'L5' => $L5 ,
'L6' => $L6 ,
'L7' => $L7 ,
'HexaviaDateRef' => $dateMajHexavia ,
'HexaviaComCod' => $hexaViaComCod ,
'HexaviaComLib' => $hexaViaComLib ,
'HexaviaCP' => $hexaViaCP ,
'HexaVia56' => $idAdr56 ,
'HexaViaVoie' => $hexaViaVoie ,
'HexaViaMat' => $matriculeHexavia ,
'RoudisId' => $codeRoudis );
return $tabAdr ;
/*
if ( $adresseNum == '' && $adresseBtq == '' && $adresseVoie == '' && $adresseRue == '' && $cp == '' && $ville == '' )
return false ;
$tabAdr = $this -> structureVoie ( $adresseNum . ' ' . $adresseBtq . ' ' . $adresseVoie . ' ' . $adresseRue );
$num = $tabAdr [ 'num' ] * 1 ;
if ( $num == 0 ) return false ;
$indRep = trim ( $tabAdr [ 'indRep' ]);
$typeVoie = trim ( $tabAdr [ 'typeVoie' ]);
$libVoie = trim ( substr ( $tabAdr [ 'libVoie' ], - 5 ));
$strAdrActive = '' ;
if ( $active ) {
$strAdrActive .= " AND (enActif=1 OR etActif=1) AND nbEntrep>30 AND pasEntrepDom=0 AND siren>1000 " ;
}
$tabTmp = $this -> iDb -> select ( 'tabAdrDom' ,
'id, siren, nic, enActif, etActif, procol, nom, nom2, sigle, enseigne, adrNum, adrBtq, adrTypVoie, adrLibVoie, ville, cp, adrComp, adrDistSp, cj, apen, apet, nbEntrep, dateInsert, dateUpdate' ,
" adrNum= $num AND adrBtq=' $indRep ' AND adrTypVoie LIKE '% $typeVoie %' AND adrLibVoie LIKE '% $libVoie %' AND cp= $cp $strAdrActive GROUP BY siren ORDER BY enActif DESC, nbEntrep DESC " , false , MYSQL_ASSOC );
if ( count ( $tabTmp ) > 0 ) {
return $tabTmp ;
}
*/
return false ;
}
2013-11-05 11:18:30 +00:00
}
?>