2009-03-04 16:38:47 +00:00
|
|
|
<?php
|
2011-01-07 13:23:05 +00:00
|
|
|
function valideSiren($siren, $nic = '', $erreur = false)
|
|
|
|
{
|
|
|
|
$lenSIREN = strlen($siren);
|
|
|
|
if (!valideData($siren, 9, 9, 'N')) { //Siren non précisé ou incorrect.
|
|
|
|
return $erreur;
|
|
|
|
} else {
|
|
|
|
if (!isset($nic) || trim($nic)=='') {
|
|
|
|
$somme = 0;
|
|
|
|
for ($i = 0; $i <= 8; $i += 2) { // Traitement IMPAIR
|
|
|
|
$somme += (integer) substr($siren, $i, 1);
|
|
|
|
}
|
2009-03-04 16:38:47 +00:00
|
|
|
|
2011-01-07 13:23:05 +00:00
|
|
|
for ($i = 1; $i <= 7; $i += 2) { // Traitement PAIR
|
|
|
|
$var_tmp = (string) (2 * ((integer) substr($siren, $i, 1)));
|
|
|
|
$som_tmp = 0;
|
|
|
|
for ($j = 0; $j < strlen($var_tmp); $j++) {
|
|
|
|
$som_tmp += (integer) substr($var_tmp, $j, 1);
|
|
|
|
}
|
|
|
|
$somme += $som_tmp;
|
|
|
|
}
|
2009-03-04 16:38:47 +00:00
|
|
|
|
2011-01-07 13:23:05 +00:00
|
|
|
if ((integer) ($somme / 10) != ($somme / 10)) {
|
|
|
|
// Le Siren est faux
|
|
|
|
if (substr($siren, 0, 3) != '200')
|
|
|
|
// Les siren débutant par 200 sont toujours valides
|
|
|
|
// (sirens provisoires de la BDF?!)
|
|
|
|
return $erreur;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!valideData($nic, 1, 5, 'N')) { // Nic de format incorrect.
|
|
|
|
return $erreur;
|
|
|
|
}
|
2009-03-04 16:38:47 +00:00
|
|
|
|
2011-01-07 13:23:05 +00:00
|
|
|
$SIRET = $siren.$nic;
|
|
|
|
$somme = 0;
|
|
|
|
for ($i = 0; $i <= 12; $i += 2) { // Traitement PAIR
|
|
|
|
$var_tmp = (string) (2 * ((integer) substr($SIRET, $i, 1)));
|
|
|
|
$som_tmp = 0;
|
|
|
|
for ($j = 0; $j < strlen($var_tmp); $j++) {
|
|
|
|
$som_tmp += (integer) substr($var_tmp, $j, 1);
|
|
|
|
}
|
|
|
|
$somme += $som_tmp;
|
|
|
|
}
|
|
|
|
for ($i = 1; $i <= 13; $i += 2) { // Traitement IMPAIR
|
|
|
|
$somme += (integer) substr($SIRET, $i, 1);
|
|
|
|
}
|
2009-03-04 16:38:47 +00:00
|
|
|
|
2011-01-07 13:23:05 +00:00
|
|
|
if ((integer) ($somme / 10) != ($somme / 10)) { // Le Siret est faux
|
|
|
|
return $erreur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2009-03-04 16:38:47 +00:00
|
|
|
}
|
2011-01-07 13:23:05 +00:00
|
|
|
|
|
|
|
function replace_siren($matches)
|
|
|
|
{
|
|
|
|
$client =
|
|
|
|
new SoapClient(null,
|
|
|
|
array('trace' => 1,
|
|
|
|
'soap_version' => SOAP_1_1,
|
|
|
|
'location' => WEBSERVICE_URL,
|
|
|
|
'uri' => WEBSERVICE_URI,
|
|
|
|
'login' => $_SESSION['tabInfo']['login'],
|
|
|
|
'password' =>
|
|
|
|
$_SESSION['tabInfo']['password']));
|
|
|
|
|
|
|
|
foreach ($matches as $sirenBrut) {
|
|
|
|
$siren = strtr($sirenBrut, array(' ' => '', '.' => '', '-' => ''));
|
|
|
|
if (strlen($sirenBrut) == 9) {
|
|
|
|
$sirenBrut = implode(' ', str_split($sirenBrut, 3));
|
|
|
|
}
|
|
|
|
if (valideSiren($siren)) {
|
|
|
|
require_once 'scoresws/scoresws.php';
|
|
|
|
try {
|
|
|
|
$o = new StdClass;
|
|
|
|
$o->siren = $siren;
|
|
|
|
$O = $ws_soap_client_int->__call('isSirenExistant', array($o));
|
|
|
|
} catch (SoapFault $fault) {
|
|
|
|
return $sirenBrut;
|
|
|
|
}
|
|
|
|
if ($O->result) {
|
|
|
|
return '<a href="/?page=identite&siret='.$siren.
|
|
|
|
'" title="Voir la fiche d\'identité'.
|
|
|
|
' de cette entreprise">'.$sirenBrut.'</a>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $sirenBrut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|