2012-10-16 07:44:31 +00:00
#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
< ? php
include_once ( FWK_PATH . 'common/chiffres.php' );
include_once ( FWK_PATH . 'common/dates.php' );
include_once ( INCLUDE_PATH . 'insee/classMInsee.php' );
include_once ( INCLUDE_PATH . 'partenaires/classMLiens.php' );
include_once ( FWK_PATH . 'mail/sendMail.php' );
$strInfoScript = 'Usage : ' . basename ( $argv [ 0 ]) . " <option> [SIREN]
2013-06-19 08:24:49 +00:00
Mise <EFBFBD> jour des adresses de domiciliation .
2012-10-16 07:44:31 +00:00
Options :
2013-06-19 08:24:49 +00:00
- d Mode debug ( Verbosit<EFBFBD> au maximum )
2012-10-16 07:44:31 +00:00
- l Source 'Base Liens'
- o Ordre inverse
2013-06-19 08:24:49 +00:00
- 2 2 <EFBFBD> me passe
" ;// -s:SSAAMMJJ Reprendre la mise <20> jour depuis le flux Insee du SSAAMMJJ
2012-10-16 07:44:31 +00:00
$passe = 1 ;
$modeDebug = false ;
$base = 'Dir' ;
$orderBy = 'ORDER BY UID ASC' ;
$argv = $_SERVER [ 'argv' ];
for ( $i = 1 , $j = 0 ; isset ( $argv [ $i ]); $i ++ ) {
if ( substr ( $argv [ $i ], 0 , 1 ) == '-' ) {
switch ( substr ( $argv [ $i ], 1 , 1 )) {
case 'd' : $modeDebug = true ; break ;
case 'l' : $base = 'Act' ; $iLien = new MLiens ( 0 ); break ;
case 'o' : $orderBy = 'ORDER BY UID DESC' ; break ;
case '2' : $passe = 2 ; break ;
// case 's': $jourFlux=substr($argv[$i],3,8); break;
// case 'h': $histo=true; break;
/*
case 'j' : $loadInpiLocal = false ; break ;
case 'q' : $loadActesDuJour = false ; break ;
case 'b' : $loadBilans = false ; break ;
case 'i' : $iReprise = substr ( $argv [ $i ], 3 ); break ; */
case '-' :
case '?' : die ( $strInfoScript ); break ;
default : die ( 'Option ' . $argv [ $i ] . ' inconnue !' . EOL ); break ;
}
} //else $tabSiren[]=$argv[$i];
}
$iDb = new WDB ( 'tmp' );
$iDb2 = new WDB ( 'tmp' );
$iInsee = new MInsee ();
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - D<> but du traitement WorldCheck ' $base ' en passe $passe ... " . EOL ;
2012-10-16 07:44:31 +00:00
if ( $passe == 1 ) {
$nb = $iDb -> select ( 'worldcheck' , 'UID, `LAST NAME` AS nom, `FIRST NAME` AS prenom, ALIASES, `ALTERNATIVE SPELLING` AS alterspel, CATEGORY, TITLE, `SUB-CATEGORY` AS subCat, POSITION, DOB, `PLACE OF BIRTH` AS ville' , " 1 AND CATEGORY IN('CRIME - FINANCIAL','CRIME - NARCOTICS','CRIME - ORGANIZED','CRIME - OTHER','CRIME - WAR','INDIVIDUAL','TERRORISM','BLACKLISTED','CORPORATE','EMBARGO','EMBARGO VESSEL','VESSEL','ORGANISATION') AND nb $base IS NULL AND checked $base =0 /* LIMIT 0,10*/ $orderBy " , false , MYSQL_ASSOC , true );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nb UID WorldCheck <20> mettre <20> v<> rifier... " . EOL ;
2012-10-16 07:44:31 +00:00
echo mysql_error () . EOL ;
$i = 0 ;
//foreach ($AnnDb as $i=>$tabWorldC) {
while ( $tabWorldC = $iDb -> fetch ( MYSQL_ASSOC )) {
$i ++ ;
$uid = $tabWorldC [ 'UID' ];
$nom = $tabWorldC [ 'nom' ];
$prenom = $tabWorldC [ 'prenom' ];
$alias = $tabWorldC [ 'ALIASES' ];
$alter = $tabWorldC [ 'alterspel' ];
$dnais = WDate :: DateT ( 'Y-m-d' , 'd/m/Y' , $tabWorldC [ 'DOB' ]);
$vnais = '' ; //$tabWorldC['ville'];
$strCat = $tabWorldC [ 'CATEGORY' ] . ' ' . $tabWorldC [ 'TITLE' ] . ' ' . $tabWorldC [ 'subCat' ] . ' ' . $tabWorldC [ 'POSITION' ];
2013-06-19 08:24:49 +00:00
echo " $i / $nb - Recherche de $nom , $prenom n<> le $dnais <20> $vnais ( $strCat ) : " ;
2012-10-16 07:44:31 +00:00
if ( $base == 'Dir' ) $tabDir =@ $iInsee -> rechercheDir ( $nom . ' ' . $alias . ' ' . $alter , $prenom , '' , $dnais , $vnais , 0 , 20 , 200 , false );
elseif ( $base == 'Act' ) $tabDir =@ $iLien -> rechercheActionnaire ( $nom . ' ' . $prenom . ' ' . $alias . ' ' . $alter , '' , 0 , '' , 0 , 100 , 0 , 20 , 200 , false );
else die ( 'Source inconnue' . EOL );
$nbRep = $tabDir [ 'nbReponsesTotal' ];
$nbCrit = count ( $tabDir [ 'criteres' ]);
2013-06-19 08:24:49 +00:00
if ( $nbRep == 0 ) { echo " Pas de r<> ponse " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 0 , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
if ( $nbCrit < 2 ) { echo " Pas assez pr<70> cis " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 'NULL' , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
if ( $nbRep >= 200 ) { echo " Trop de r<> sultat " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 'NULL' , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
2012-10-16 07:44:31 +00:00
$tabTrouve = $tabDir [ 'reponses' ];
print_r ( $tabDir );
$iDb2 -> update ( 'worldcheck' , array ( " nb $base " => $nbRep , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false );
// BOUCLER SUR CHAQUE SIREN
// EXTRAIRE LE NOM, LE CP/VILLE ET LA FJ/NAF DE LA SOCIETE
// EXTRAIRE LES DIRIGEANTS
// STOCKER EN BASE
echo mysql_error () . EOL ;
// die();
}
} else {
$nb = $iDb -> select ( 'worldcheck' , 'UID, `LAST NAME` AS nom, `FIRST NAME` AS prenom, ALIASES, `ALTERNATIVE SPELLING` AS alterspel, CATEGORY, TITLE, `SUB-CATEGORY` AS subCat, POSITION, DOB, `PLACE OF BIRTH` AS ville' , " 1 AND CATEGORY IN('CRIME - FINANCIAL','CRIME - NARCOTICS','CRIME - ORGANIZED','CRIME - OTHER','CRIME - WAR','INDIVIDUAL','TERRORISM','BLACKLISTED','CORPORATE','EMBARGO','EMBARGO VESSEL','VESSEL','ORGANISATION') AND nbCrit $base >1 AND checked $base <2 $orderBy " , false , MYSQL_ASSOC , true );
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Il y a $nb UID WorldCheck <20> mettre <20> v<> rifier... " . EOL ;
2012-10-16 07:44:31 +00:00
echo mysql_error () . EOL ;
$i = 0 ;
//foreach ($AnnDb as $i=>$tabWorldC) {
while ( $tabWorldC = $iDb -> fetch ( MYSQL_ASSOC )) {
$i ++ ;
$uid = $tabWorldC [ 'UID' ];
$nom = $tabWorldC [ 'nom' ];
$prenom = $tabWorldC [ 'prenom' ];
$alias = $tabWorldC [ 'ALIASES' ];
$alter = $tabWorldC [ 'alterspel' ];
$dnais = WDate :: DateT ( 'Y-m-d' , 'd/m/Y' , $tabWorldC [ 'DOB' ]);
$vnais = '' ; //$tabWorldC['ville'];
$strCat = $tabWorldC [ 'CATEGORY' ] . ' ' . $tabWorldC [ 'TITLE' ] . ' ' . $tabWorldC [ 'subCat' ] . ' ' . $tabWorldC [ 'POSITION' ];
2013-06-19 08:24:49 +00:00
echo " $i / $nb - Recherche de $nom , $prenom n<> le $dnais <20> $vnais ( $strCat ) : " ;
2012-10-16 07:44:31 +00:00
if ( $base == 'Dir' ) $tabDir =@ $iInsee -> rechercheDir ( $nom . ' ' . $alias . ' ' . $alter , $prenom , '' , $dnais , $vnais , 0 , 20 , 200 , false );
elseif ( $base == 'Act' ) $tabDir =@ $iLien -> rechercheActionnaire ( $nom . ' ' . $prenom . ' ' . $alias . ' ' . $alter , '' , 0 , '' , 0 , 100 , 0 , 20 , 200 , false );
else die ( 'Source inconnue' . EOL );
$nbRep = $tabDir [ 'nbReponsesTotal' ];
$nbCrit = count ( $tabDir [ 'criteres' ]);
/* if ( $nbRep > 0 ) {
print_r ( $tabDir );
die ();
}
/* $tabTrouve = $tabDir [ 'reponses' ];
print_r ( $tabDir );
$iDb2 -> update ( 'worldcheck' , array ( " nb $base " => $nbRep , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false );
*/
2013-06-19 08:24:49 +00:00
if ( $nbRep == 0 ) { echo " Pas de r<> ponse " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 0 , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
if ( $nbCrit < 2 ) { echo " Pas assez pr<70> cis " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 'NULL' , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
if ( $nbRep >= 200 ) { echo " Trop de r<> sultat " . EOL ; $iDb2 -> update ( 'worldcheck' , array ( " nb $base " => 'NULL' , " nbCrit $base " => $nbCrit , " checked $base " => 1 ), " UID= $uid " , false ); continue ; }
2012-10-16 07:44:31 +00:00
$tabTrouve = $tabDir [ 'reponses' ];
foreach ( $tabTrouve as $j => $dir ) {
if ( $base == 'Dir' ) {
$nomT = trim ( $dir [ 'DirNom' ] . ' ' . $dir [ 'DirNomUsage' ]);
$prenomT = $dir [ 'DirPrenom' ];
$dnaisT = $dir [ 'DirDateNaiss' ];
$vnaisT = $dir [ 'DirLieuNaiss' ];
$fonction = $dir [ 'DirFonction' ];
$sirenT =@ $dir [ 'Siren' ];
$levNom = levenshtein ( $nom , $nomT );
$levPrenom = levenshtein ( $prenom , $prenomT );
$levNais = levenshtein ( $tabWorldC [ 'DOB' ], $dnaisT );
$len = strlen ( $nom . $prenom . $dnais );
$lenT = strlen ( $nomT . $prenomT . $dnaisT );
$levTotal = $levNom + $levPrenom + $levNais ;
$nomT =@ $dir [ 'DirNom' ];
} else {
$nomT = $dir [ 'ActNomRs' ];
$sirenT =@ $dir [ 'Siren' ];
$levNom = levenshtein ( $nom . ' ' . $prenom , $nomT );
$len = strlen ( $nom . $prenom );
$lenT = strlen ( $nomT );
$levTotal = $levNom ;
$len1 = ( $lenT + $len ) / 2 ;
$ratio1 = $levTotal / $len1 * 1.0 ;
$prenomT = $vnaisT = $fonction = '' ;
$dnaisT = 0 ;
}
$len1 = ( $lenT + $len ) / 2 ;
$ratio1 = $levTotal / $len1 * 1.0 ;
if ( $ratio1 < 0.3 && $sirenT > 1000 ) {
2013-06-19 08:24:49 +00:00
echo " $i / $nb - TROUVE ..... $nomT , $prenomT n<> le $dnaisT <20> $vnaisT ( $fonction ) : $levTotal , $len1 => $ratio1 " . EOL ;
2012-10-16 07:44:31 +00:00
$tabId = $iInsee -> getIdentiteLight ( $sirenT );
$tabInsert = array ( 'wUID' => $uid ,
'wNOM' => $nom ,
'wPRENOM' => $prenom ,
'wALIASES' => $alias ,
'wALTER' => $alter ,
'wDOB' => $tabWorldC [ 'DOB' ],
'wCATEGORY' => $tabWorldC [ 'CATEGORY' ],
'wTITLE' => $tabWorldC [ 'TITLE' ],
'wSUBCATEGORY' => $tabWorldC [ 'subCat' ],
'wPOSITION' => $tabWorldC [ 'POSITION' ],
'scoring' => $ratio1 ,
'source' => $base ,
'DirRs' =>@ $dir [ 'DirRs' ],
'DirNom' => $nomT ,
'DirPrenom' =>@ $dir [ 'DirPrenom' ],
'DirNomUsage' =>@ $dir [ 'DirNomUsage' ],
'DirDateNaiss' =>@ $dir [ 'DirDateNaiss' ],
'DirLieuNaiss' =>@ $dir [ 'DirLieuNaiss' ],
'DirFonction' =>@ $dir [ 'DirFonction' ],
'siren' => $sirenT ,
'Nom' => $tabId [ 'Nom' ],
'Adresse' => $tabId [ 'Adresse' ],
'Adresse2' => $tabId [ 'Adresse2' ],
'CP' => $tabId [ 'CP' ],
'Ville' => $tabId [ 'Ville' ],
'FJ' => $tabId [ 'FJ' ],
'FJ_lib' => $tabId [ 'FJ_lib' ],
'Actif' => $tabId [ 'Actif' ],
'NafEnt' => $tabId [ 'NafEnt' ],
'NafEntLib' => $tabId [ 'NafEntLib' ],
'Capital' => $tabId [ 'Capital' ],
'CapitalDev' => $tabId [ 'CapitalDev' ],
'TrancheCA' => $tabId [ 'TrancheCA' ],
'TrancheCALib' => $tabId [ 'TrancheCALib' ],
'EffEnTr' => $tabId [ 'EffEnTr' ],
'EffEnTrLib' => $tabId [ 'EffEnTrLib' ],
);
$iDb2 -> insert ( 'worldcheckResults' , $tabInsert , false );
//echo mysql_error().EOL;
//die();
}
$iDb2 -> update ( 'worldcheck' , array ( " nb $base " => $nbRep , " nbCrit $base " => $nbCrit , " checked $base " => 2 ), " UID= $uid " , false );
}
echo mysql_error () . EOL ;
}
}
2013-06-19 08:24:49 +00:00
echo date ( 'Y/m/d - H:i:s' ) . " - Fin du traitement de mise <20> jour des adresses de domiciliation. " . EOL ;
2012-10-16 07:44:31 +00:00
?>