2012-10-16 07:44:31 +00:00
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
< ? php
/**
2013-06-19 08:24:49 +00:00
** Ce script r<EFBFBD> cup<EFBFBD> re les tribunaux comp<EFBFBD> tents pour les codes insee des communes ( site du minist<EFBFBD> re de la justice )
2012-10-16 07:44:31 +00:00
** URL = http :// www . justice . gouv . fr / recherche - juridictions / popup . php ? insee = 01053 & type = all
** referer = http :// www . justice . gouv . fr / recherche - juridictions / consult . php
**
2013-06-19 08:24:49 +00:00
** Il faudrait penser <EFBFBD> mettre <EFBFBD> jour en automatique la liste des communes depuis le site de l ' insee !!!
2012-10-16 07:44:31 +00:00
** URL = http :// www . insee . fr / fr / nom_def_met / nomenclatures / cog / cog . telechargement . annee . asp ? annee = 2007
**/
include_once ( INCLUDE_PATH . 'insee/classMInsee.php' );
include_once ( FWK_PATH . 'common/curl.php' );
$referer = 'http://annuaire-cfe.insee.fr/AnnuaireCFE/jsp/lcfeaf.jsp' ;
$iDb = new WDB ();
$iInsee = new MInsee ();
/*
$url = 'http://www.justice.gouv.fr/recherche-juridictions/popup.php?insee=01000&type=all' ;
$page = getUrl ( $url , '' , '' , $referer , false , 'www.justice.gouv.fr' );
die ( $page [ 'body' ]);
*/
$lstCom = $iDb -> select ( 'villes' , 'codeInsee, TRIM(CONCAT(ARTMAJ,NCC)) as LibCom' , 'codeInsee BETWEEN 85068 AND 91000 GROUP BY codeInsee' ); // "`Code Insee`<'10000'");
foreach ( $lstCom as $i => $tabCom ) {
$numInsee = $tabCom [ 'codeInsee' ];
$dep = substr ( $numInsee , 0 , 2 );
if ( $dep == 97 ) {
$dep = substr ( $numInsee , 0 , 3 );
$com = substr ( $numInsee , 3 , 2 );
} else
$com = substr ( $numInsee , 2 , 3 );
$url = " http://annuaire-cfe.insee.fr/AnnuaireCFE/jsp/Controleur.jsp?ddd= $dep &ccc= $com &service=lcfer&type=NULL&Valider=Valider " ;
$page = getUrl ( $url , '' , '' , $referer , false , 'annuaire-cfe.insee.fr' );
$body = $page [ 'body' ];
2013-06-19 08:24:49 +00:00
if ( strpos ( $body , " <P>Erreur rencontr<74> e : java.lang.NullPointerException</P> " ) == 0 )
2012-10-16 07:44:31 +00:00
{
//print_r($page);
$cookie = $page [ 'header' ][ 'Set-Cookie' ];
$page = getUrl ( 'http://annuaire-cfe.insee.fr/AnnuaireCFE/jsp/lcferf.jsp' , $cookie , '' , $url , false , 'annuaire-cfe.insee.fr' );
$body = $page [ 'body' ];
if ( preg_match ( '/<font size="2" face="Arial, Helvetica, sans-serif" color="#D01010">(?:.*)([\d]{2,3})(?:.*)- (.*) \/ (.*)<\/b><\/font><\/td>/Uis' , $body , $matches )) {
$depLu = $matches [ 1 ];
$depLib = $matches [ 2 ];
$comLib = $matches [ 3 ];
}
/*< b > 01
- AIN / L ' ABERGEMENT CLEMENCIAT </ b ></ font ></ td >*/
$tabTmp = explode ( '<tr bgcolor="#FFFFFF">' , $body );
//print_r($tabTmp);die();
$sleep = false ;
foreach ( $tabTmp as $j => $tabTrib ) {
if ( $j < 2 ) continue ;
if ( preg_match ( '/<td valign="top" width="48%"> <font face="Arial, Helvetica, sans-serif" size="2">(?:.*)<b>(.*)<\/b><br>(.*)<\/font>/Uis' , $tabTrib , $results )) {
$libTri = strip_tags ( $results [ 1 ]);
if ( preg_match ( " /^Chambre de commerce et d'industrie $ /i " , $libTri )) $typeTri = 'O' ; // CCI
2013-06-19 08:24:49 +00:00
elseif ( preg_match ( " /^Chambre de m<> tiers et de l'artisanat/i " , $libTri )) $typeTri = 'T' ; // CM
elseif ( preg_match ( " /^Chambre de m<> tiers/i " , $libTri )) $typeTri = 'T' ; // CM
2012-10-16 07:44:31 +00:00
elseif ( preg_match ( " /^Greffe du tribunal de commerce/i " , $libTri )) continue ; //$typeTri='C';// TC
elseif ( preg_match ( " /^Chambre d'agriculture/i " , $libTri )) $typeTri = 'R' ; // AGR
elseif ( preg_match ( " /^Chambre nationale de la batellerie artisanale/i " , $libTri )) $typeTri = 'N' ; // BAR
elseif ( preg_match ( " /^URSSAF/i " , $libTri )) $typeTri = 'U' ; // URS
2013-06-19 08:24:49 +00:00
elseif ( preg_match ( " /^Centre des imp<6D> ts/i " , $libTri )) $typeTri = 'Z' ; // CDI
else die ( " Libell<EFBFBD> CFE ' $libTri ' inconnu ! " );
2012-10-16 07:44:31 +00:00
} else die ( 'Erreur fatale' ); /*</ b >< br >
1 RUE JOSEPH BERNIER < br >
01000 BOURG EN BRESSE < br >
2013-06-19 08:24:49 +00:00
T<EFBFBD> l : 04 74 32 13 00 < br >
2012-10-16 07:44:31 +00:00
Fax : 04 74 21 42 63 < br >
< a href = " http://WWW.AIN.CCI.FR " target = " _new " > WWW . AIN . CCI . FR </ a >
</ font >*/
if ( preg_match_all ( '/(.*)(?:<br>|<\/a>)/Uis' , $results [ 2 ], $results )) {
//print_r($results);die();
$results2 = $results [ 1 ];
$adresse1 = trim ( $results2 [ 0 ]);
$adresse2 = trim ( $results2 [ 1 ]);
if ( substr ( $adresse2 , 0 , 5 ) * 1 > 0 ) {
$adresse2 = '' ;
$i = 1 ;
} else $i = 2 ;
$cpVille = trim ( @ $results2 [ $i ]);
$cp = substr ( $cpVille , 0 , 5 ) * 1 ;
$ville = trim ( substr ( $cpVille , 5 ));
2013-06-19 08:24:49 +00:00
$tel = str_replace ( ' ' , '' , strtr ( @ $results2 [ $i + 1 ], 'T<> lFax :.' , ' ' )) * 1 ;
$fax = str_replace ( ' ' , '' , strtr ( @ $results2 [ $i + 2 ], 'T<> lFax :.' , ' ' )) * 1 ;
2012-10-16 07:44:31 +00:00
if ( preg_match ( '/<a href="(.*)"/Ui' , trim ( @ $results2 [ $i + 3 ]), $results2 )) $web = strtolower ( $results2 [ 1 ]);
if ( $web == 'http://' ) $web = '' ;
$id = md5 ( $typeTri . $adresse1 . $cp . $ville );
$str = $tabCom [ 'codeInsee' ] . " ;1; $depLu ; $depLib ; $comLib ; $id ; $typeTri ; $adresse1 ; $adresse2 ; $cp ; $ville ; $cpVille ; $tel ; $fax ; $web " ;
$trib = $iDb -> select ( 'tribunaux' , 'triId, triCode, triType, triNom, triCP, triTel, triFax' , " triType=' $typeTri ' AND triCommentaire=' $id ' " );
if ( isset ( $trib [ 0 ][ 'triId' ])) {
$id = $trib [ 0 ][ 'triId' ];
$code = $trib [ 0 ][ 'triCode' ];
$nom = $trib [ 0 ][ 'triNom' ];
} else {
2013-06-19 08:24:49 +00:00
// Il faut ins<6E> rer la fiche ID de la comp<6D> tence
2012-10-16 07:44:31 +00:00
$tabAdr = $iInsee -> structureVoie ( $adresse1 );
$tabInsert = array ( 'triType' => $typeTri ,
'triNom' => $libTri ,
'triCP' => $cp ,
'triWeb' => $web ,
'triAdrNum' => $tabAdr [ 'num' ],
'triAdrIndRep' =>@ $tabAdr [ 'indRep' ],
'triAdrTypeVoie' => $tabAdr [ 'typeVoie' ],
'triAdrVoie' => $tabAdr [ 'libVoie' ],
'triAdrComp' => $adresse2 ,
'triVille' => $ville ,
'triTel' => $tel ,
'triFax' => $fax ,
'triCommentaire' => $id ,
);
$id = $iDb -> insert ( 'tribunaux' , $tabInsert );
$code = '' ;
$nom = $libTri ;
print_r ( $tabInsert );
$sleep = true ;
}
echo $str ;
if ( $id > 0 ) {
$ret = $iDb -> insert ( 'tribunauxInsee' , array ( 'CodeInsee' => $tabCom [ 'codeInsee' ], 'triId' => $id ));
if ( ! $ret ) {
2013-06-19 08:24:49 +00:00
echo ' D<> j<EFBFBD> en base.' ;
2012-10-16 07:44:31 +00:00
}
else {
echo ' ===> INSERE !!!' ;
$sleep = true ;
}
echo " \n " ;
}
}
}
} else {
$str = $tabCom [ 'codeInsee' ] . " ;0;;; " . $tabCom [ 'LibCom' ] . " \n " ;
echo $str ;
}
/* if ( $sleep ) randsleep ( 5 , 15 ); //7,21);
else randsleep ( 2 , 7 ); */
// sleep(2);
}
die ();
?>