2011-11-15 13:58:10 +00:00
|
|
|
#!/usr/bin/php
|
|
|
|
<?php
|
|
|
|
//error_reporting(E_ALL & ~E_NOTICE);
|
|
|
|
|
|
|
|
// Define path to application directory
|
|
|
|
defined('APPLICATION_PATH')
|
|
|
|
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
|
|
|
|
|
|
|
// Define application environment
|
|
|
|
defined('APPLICATION_ENV')
|
|
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
|
|
|
|
// Ensure library/ is on include_path
|
|
|
|
set_include_path(implode(PATH_SEPARATOR, array(
|
|
|
|
realpath(APPLICATION_PATH . '/../library'),
|
|
|
|
get_include_path(),
|
|
|
|
)));
|
|
|
|
|
|
|
|
/** Zend_Application */
|
|
|
|
require_once 'Zend/Application.php';
|
|
|
|
|
|
|
|
// Create application, bootstrap, and run
|
|
|
|
$application = new Zend_Application(
|
|
|
|
APPLICATION_ENV,
|
|
|
|
APPLICATION_PATH . '/configs/application.ini'
|
|
|
|
);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$opts = new Zend_Console_Getopt(
|
|
|
|
//Options
|
|
|
|
array(
|
|
|
|
'help|?' => "Aide.",
|
|
|
|
'ignore=i' => "Nombre de ligne à ignoré.",
|
|
|
|
'file=s' => "Définir le chemin du fichier",
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$opts->parse();
|
|
|
|
} catch (Zend_Console_Getopt_Exception $e) {
|
|
|
|
echo $e->getUsageMessage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Usage
|
|
|
|
if(isset($opts->help) || !isset($opts->file))
|
|
|
|
{
|
|
|
|
echo $opts->getUsageMessage();
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2011-11-16 13:47:10 +00:00
|
|
|
define('MYSQL_HOST', '192.168.78.230');
|
|
|
|
define('MYSQL_USER', 'wsuser');
|
|
|
|
define('MYSQL_PASS', 'scores');
|
|
|
|
define('MYSQL_DEFAULT_DB', 'jo');
|
|
|
|
|
2011-11-15 13:58:10 +00:00
|
|
|
//Définition bdd
|
|
|
|
$dbConfig = array(
|
2011-11-16 13:47:10 +00:00
|
|
|
'host' => MYSQL_HOST,
|
|
|
|
'username' => MYSQL_USER,
|
|
|
|
'password' => MYSQL_PASS,
|
|
|
|
'dbname' => MYSQL_DEFAULT_DB,
|
2011-11-15 13:58:10 +00:00
|
|
|
);
|
|
|
|
$db = Zend_Db::factory('PDO_MYSQL', $dbConfig);
|
|
|
|
|
2011-11-16 13:47:10 +00:00
|
|
|
//Chargement des classes metier
|
|
|
|
require_once realpath(dirname(__FILE__)).'/../config/config.php';
|
|
|
|
|
|
|
|
|
2011-11-15 13:58:10 +00:00
|
|
|
$tabExtract = array();
|
2011-11-16 13:47:10 +00:00
|
|
|
$tabEntete = array();
|
2011-11-15 13:58:10 +00:00
|
|
|
$tabIdentifiant = array();
|
|
|
|
$tabData = array();
|
|
|
|
|
|
|
|
$posKeySiren = $posKeySiret = $posKeyNic = false;
|
|
|
|
|
|
|
|
//Lire le fichier csv
|
|
|
|
$row = 0;
|
|
|
|
if (($handle = fopen($opts->file, 'r')) !== FALSE) {
|
|
|
|
while (($data = fgetcsv($handle, 0, ',')) !== FALSE) {
|
|
|
|
$num = count($data);
|
|
|
|
|
|
|
|
//Traitement de la première ligne
|
|
|
|
if ($row == 0) {
|
|
|
|
for ($c=0; $c < $num; $c++) {
|
|
|
|
//Détection clé importante
|
|
|
|
switch(strtolower($data[$c])) {
|
|
|
|
case 'siren':
|
|
|
|
$posKeySiren = $c;
|
|
|
|
break;
|
|
|
|
case 'nic':
|
|
|
|
$posKeyNic = $c;
|
|
|
|
break;
|
|
|
|
case 'siret':
|
|
|
|
$posKeySiret = $c;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$tabExtract[] = $data[$c];
|
|
|
|
}
|
|
|
|
if ($posKeySiren!==false && $posKeyNic!==false && $posKeySiret!==false || $posKeySiren!==false && $posKeySiret!==false ){
|
|
|
|
die("Trop de clé!");
|
|
|
|
}
|
2011-11-16 15:17:13 +00:00
|
|
|
if ($posKeySiren===false || $posKeySiret===false){
|
|
|
|
die("Aucune clé détecté!");
|
|
|
|
}
|
2011-11-15 13:58:10 +00:00
|
|
|
//Traitement des identifiants
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if ( $posKeySiret!==false ){
|
|
|
|
$tabIdentifiant[] = $data[$posKeySiret];
|
|
|
|
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
|
|
$tabIdentifiant[] = $data[$posKeySiren].$data[$posKeyNic];
|
|
|
|
} elseif ( $posKeySiren !==false ){
|
|
|
|
$tabIdentifiant[] = $data[$posKeySiren];
|
|
|
|
}
|
|
|
|
|
|
|
|
for ($c=0; $c < $num; $c++) {
|
|
|
|
$colname = $tabExtract[$c];
|
|
|
|
if (!in_array(strtolower($colname), array('siren', 'siret', 'nic'))){
|
|
|
|
$tabData[][$colname] = $data[$c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
$row++;
|
|
|
|
}
|
|
|
|
fclose($handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
$nbIdentifiant = count($tabIdentifiant);
|
|
|
|
echo "Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants.\n";
|
|
|
|
$rowTotal = $nbIdentifiant;
|
|
|
|
|
|
|
|
//Traiter la demande en créant les requetes sql nécessaires
|
|
|
|
$tabDico = array(
|
|
|
|
'etablissements' => array(
|
|
|
|
'db' => 'jo.etablissements',
|
|
|
|
'cle' => array(
|
2011-11-16 15:17:13 +00:00
|
|
|
'idSd' => "CONCAT(source,'-',source_id) AS idSd",
|
|
|
|
'source' => '',
|
|
|
|
'triCode' => '',
|
|
|
|
'autre_id' => '',
|
|
|
|
'actif' => '',
|
|
|
|
'siege' => '',
|
2011-11-16 13:47:10 +00:00
|
|
|
'raisonSociale' => '',
|
2011-11-16 15:17:13 +00:00
|
|
|
'enseigne' => '',
|
|
|
|
'sigle' => '',
|
|
|
|
'marques' => '',
|
|
|
|
'adr_num' => '',
|
|
|
|
'adr_btq' => '',
|
|
|
|
'adr_typeVoie' => '',
|
|
|
|
'adr_libVoie' => '',
|
|
|
|
'adr_comp' => '',
|
|
|
|
'adr_cp' => '',
|
|
|
|
'adr_ville' => '',
|
|
|
|
'adr_dep' => '',
|
|
|
|
'adr_codeCom' => 'CONCAT(if (adr_dep>100,round(adr_dep/10),adr_dep*1),adr_com) AS adr_codeCom',
|
|
|
|
'telEtab' => 'tel as telEtab',
|
|
|
|
'faxEtab' => 'fax as faxEtab',
|
|
|
|
'cj' => '',
|
|
|
|
'capital' => '',
|
|
|
|
'capitalDev' => '',
|
|
|
|
'ape_etab' => '',
|
2011-11-17 11:03:30 +00:00
|
|
|
'ape_entrep' => '',
|
|
|
|
'SiretEnBase' => 'nic>0 as SiretEnBase',
|
2011-11-16 13:47:10 +00:00
|
|
|
),
|
|
|
|
'where' => ' WHERE siren=$siren AND nic=$nic',
|
|
|
|
),
|
|
|
|
'identite' => array(
|
|
|
|
'db' => 'insee.identite',
|
|
|
|
'cle' => array(
|
2011-11-16 15:17:13 +00:00
|
|
|
'etActifInsee' => 'ACTIF as etActifInsee',
|
|
|
|
'nomInsee' => 'NOM as nomInsee',
|
|
|
|
'nomInsee2' => 'NOM2 as nomInsee2',
|
|
|
|
'sigleInsee' => 'SIGLE as sigleInsee',
|
|
|
|
'enseigneInsee' => 'ENSEIGNE as enseigneInsee',
|
|
|
|
'adrNumVoieInsee' => 'ADR_NUMVOIE as adrNumVoieInsee',
|
|
|
|
'adrBtqInsee' => 'ADR_BTQ as adrBtqInsee',
|
|
|
|
'adrTypeVoieInsee' => 'ADR_TYPVOIE as adrTypeVoieInsee',
|
|
|
|
'adrVoieInsee' => 'ADR_LIBVOIE as adrVoieInsee',
|
|
|
|
'adrCompInsee' => 'ADR_COMP as adrCompInsee',
|
|
|
|
'adrCPInsee' => 'ADR_CP as adrCPInsee',
|
|
|
|
'adrVilleInsee' => 'ADR_LIBCOM as adrVilleInsee',
|
|
|
|
'adrDistSPInsee' => 'ADR_DISTSP as adrDistSPInsee',
|
|
|
|
'CjInsee' => 'CJ as CjInsee',
|
|
|
|
'nafEnInsee' => 'APE_ENT as nafEnInsee',
|
|
|
|
'nafEtInsee' => 'APE_ETAB as nafEtInsee',
|
|
|
|
'APRM' => '',
|
|
|
|
'ACTIVNAT' => '',
|
|
|
|
'ORIGINE' => '',
|
|
|
|
'MODET' => '',
|
|
|
|
'EXPLET' => '',
|
|
|
|
'LIEUACT' => '',
|
|
|
|
'ACTISURF' => '',
|
|
|
|
'MODEN' => '',
|
|
|
|
'PRODPART' => '',
|
|
|
|
'EXPLEN' => '',
|
|
|
|
'MONOREG' => '',
|
|
|
|
'REGIMP' => '',
|
|
|
|
'MONOACT' => '',
|
|
|
|
'DCREN' => '',
|
|
|
|
'AUXILT' => '',
|
|
|
|
'SAISONAT' => '',
|
|
|
|
'CIVILITE' => '',
|
|
|
|
'TCA' => '',
|
|
|
|
'TCAEXP' => '',
|
|
|
|
'EFF_ENT' => '',
|
|
|
|
'DCRET' => '',
|
|
|
|
'EFF_ET' => '',
|
|
|
|
'CODEVOIE' => '',
|
|
|
|
'dateMajInsee' => 'dateUpdate as dateMajInsee',
|
2011-11-16 13:47:10 +00:00
|
|
|
),
|
2011-11-16 15:17:13 +00:00
|
|
|
'where' => ' WHERE SIREN=$siren AND NIC=$nic',
|
2011-11-16 13:47:10 +00:00
|
|
|
),
|
2011-11-17 11:03:30 +00:00
|
|
|
'notice' => array(
|
|
|
|
'db' => 'insee.insee_notices',
|
|
|
|
'cle' => array(
|
|
|
|
'insRPET' => '',
|
|
|
|
'insDEPCOMEN' => '',
|
|
|
|
'insRPEN' => '',
|
|
|
|
'insARRONET' => '',
|
|
|
|
'insCTONET' => '',
|
|
|
|
'insTCD' => '',
|
|
|
|
'insZEMET' => '',
|
|
|
|
'insDU' => '',
|
|
|
|
'insTU' => '',
|
|
|
|
'insUU' => '',
|
|
|
|
'insRECME' => '',
|
|
|
|
'insEAEANT' => '',
|
|
|
|
'insEAEAPET' => '',
|
|
|
|
'insEAESEC1T' => '',
|
|
|
|
'insEAESEC2T' => '',
|
|
|
|
'insEAEANN' => '',
|
|
|
|
'insEAEAPEN' => '',
|
|
|
|
'insEAESEC1N' => '',
|
|
|
|
'insEAESEC2N' => '',
|
|
|
|
'insEAESEC3N' => '',
|
|
|
|
'insEAESEC4N' => '',
|
|
|
|
'dateMajNotice' => 'dateNotice as dateMajNotice',
|
|
|
|
),
|
|
|
|
'where' => ' WHERE insSIREN=$siren AND insNIC=$nic',
|
|
|
|
),
|
|
|
|
'rncs_entrep' => array(
|
|
|
|
'db' => 'jo.rncs_entrep',
|
|
|
|
'cle' => array(
|
|
|
|
'entActiveRncs' => 'actif AS entActiveRncs',
|
|
|
|
'numRC2' => 'numRC2',
|
|
|
|
'raisonSocialeRncs' => 'raisonSociale AS raisonSocialeRncs',
|
|
|
|
'sigleRncs' => 'sigle AS sigleRncs',
|
|
|
|
'dateNaiss' => 'dateNaiss',
|
|
|
|
'lieuNaiss' => 'lieuNaiss',
|
|
|
|
'nationalite' => 'nationalite',
|
|
|
|
'pays' => 'pays',
|
|
|
|
'nafEnRncs' => 'naf AS nafEnRncs',
|
|
|
|
'cjRncs' => 'cj AS cjRncs',
|
|
|
|
'dateImma' => 'dateImma',
|
|
|
|
'dateRad' => 'dateRad',
|
|
|
|
'capitalType' => 'capitalType',
|
|
|
|
'dateMajEnRncs' => 'flux AS dateMajEnRncs',
|
|
|
|
),
|
|
|
|
'where' => ' WHERE siren=$siren',
|
|
|
|
),
|
|
|
|
'rncs_etab' => array(
|
|
|
|
'db' => 'jo.rncs_etab',
|
|
|
|
'cle' => array(
|
|
|
|
'etActifRncs' => 'actif AS etActifRncs',
|
|
|
|
'siegeRncs' => 'siege AS siegeRncs',
|
|
|
|
'enseigneRncs' => 'enseigne AS enseigneRncs',
|
|
|
|
'nomCommercialRncs' => 'nomCommercial AS nomCommercialRncs',
|
|
|
|
'adrNumVoieRncs' => 'adrNumVoie AS adrNumVoieRncs',
|
|
|
|
'adrIndRepRncs' => 'adrIndRep AS adrIndRepRncs',
|
|
|
|
'adrLibVoieRncs' => 'adrLibVoie AS adrLibVoieRncs',
|
|
|
|
'adrTypeVoieRncs' => 'adrTypeVoie AS adrTypeVoieRncs',
|
|
|
|
'adrVoieRncs' => 'adrVoie AS adrVoieRncs',
|
|
|
|
'cpRncs' => 'cp AS cpRncs',
|
|
|
|
'villeRncs' => 'commune AS villeRncs',
|
|
|
|
'adrCompRncs' => 'adrComp AS adrCompRncs',
|
|
|
|
'nafEtRncs' => 'naf AS nafEtRncs',
|
|
|
|
'dateMajEtRncs' => 'flux AS dateMajEtRncs',
|
|
|
|
),
|
|
|
|
'where' => ' WHERE siren=$siren AND nic=$nic',
|
|
|
|
),
|
|
|
|
'infos_entrep' => array(
|
|
|
|
'db' => 'jo.infos_entrep',
|
|
|
|
'cle' => array(
|
|
|
|
'isin' => '',
|
|
|
|
'tel' => '',
|
|
|
|
'fax' => '',
|
|
|
|
'web' => '',
|
|
|
|
'mail' => '',
|
|
|
|
),
|
|
|
|
'where' => ' WHERE siren=$siren',
|
|
|
|
),
|
2011-11-16 13:47:10 +00:00
|
|
|
'data' => array(
|
2011-11-17 11:03:30 +00:00
|
|
|
'NicSiege',
|
|
|
|
'tva',
|
|
|
|
'dateFermetureEn',
|
|
|
|
'codeFermetureEn',
|
|
|
|
'dateFermetureEt',
|
|
|
|
'codeFermetureEt',
|
|
|
|
'activite',
|
2011-11-16 13:47:10 +00:00
|
|
|
'SituationJuridique',
|
2011-11-17 11:03:30 +00:00
|
|
|
'situationParution',
|
|
|
|
'situationDernCode',
|
|
|
|
'situationDernEven',
|
|
|
|
'dirigeant1Nom',
|
|
|
|
'dirigeant1Fonction',
|
|
|
|
'dirigeant1DateNaiss',
|
|
|
|
'dirigeant1LieuNaiss',
|
|
|
|
'dirigeant2Nom',
|
|
|
|
'dirigeant2Fonction',
|
|
|
|
'dirigeant2DateNaiss',
|
|
|
|
'dirigeant2LieuNaiss',
|
|
|
|
'indiScore',
|
|
|
|
'encours',
|
|
|
|
'dateBilan',
|
|
|
|
'latLon',
|
|
|
|
'latLon2',
|
2011-11-15 13:58:10 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
//Liste des champs SQL
|
|
|
|
foreach($tabExtract as $key)
|
|
|
|
{
|
|
|
|
$strKey = false;
|
2011-11-16 13:47:10 +00:00
|
|
|
//Traitement spécial pour le champs, ajout et remplacement sur entete
|
2011-11-15 13:58:10 +00:00
|
|
|
switch($key){
|
2011-11-16 13:47:10 +00:00
|
|
|
default:
|
|
|
|
$tabEntete[] = $key;
|
|
|
|
break;
|
2011-11-15 13:58:10 +00:00
|
|
|
}
|
2011-11-16 13:47:10 +00:00
|
|
|
|
|
|
|
//Ajout à la requete SQL
|
2011-11-15 13:58:10 +00:00
|
|
|
foreach($tabDico as $element => $select)
|
|
|
|
{
|
2011-11-16 13:47:10 +00:00
|
|
|
if ( array_key_exists('db', $select) && in_array($key, $select['cle']) )
|
2011-11-15 13:58:10 +00:00
|
|
|
{
|
|
|
|
if (isset(${$element.'Fields'})){ ${$element.'Fields'}.= ', '; }
|
2011-11-16 13:47:10 +00:00
|
|
|
|
|
|
|
if ($select['cle'][$key]!=''){
|
|
|
|
$strKey = $select['cle'][$key];
|
|
|
|
}
|
|
|
|
|
2011-11-15 13:58:10 +00:00
|
|
|
if ($strKey!==false){
|
|
|
|
${$element.'Fields'}.= $strKey;
|
|
|
|
} else {
|
|
|
|
${$element.'Fields'}.= $key;
|
|
|
|
}
|
|
|
|
break;
|
2011-11-17 11:03:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Détection element(VAL1,VAL2)
|
|
|
|
$values = false;
|
|
|
|
if (preg_match('/(.*)\(.*\)/', $key, $matches))
|
|
|
|
{
|
|
|
|
$key = $matches[1];
|
|
|
|
$values = $matches[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $element == 'data' && array_key_exists($key, $select) )
|
|
|
|
{
|
|
|
|
${$element.'Data'} = $values;
|
2011-11-15 13:58:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Vérification et création des données
|
|
|
|
$row = 1;
|
|
|
|
foreach($tabIdentifiant as $item)
|
|
|
|
{
|
|
|
|
echo "Traitement de $row / $rowTotal lignes";
|
|
|
|
|
|
|
|
$siretValide = false;
|
|
|
|
$sirenValide = false;
|
|
|
|
//Vérification par algorithme
|
|
|
|
if ($posKeySiret!==false){
|
|
|
|
$siretValide = siretValide($item);
|
|
|
|
if ($siretValide===false){
|
|
|
|
$sirenValide = sirenValide(substr($siren,0,9));
|
|
|
|
} else {
|
|
|
|
$sirenValide = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($posKeySiren!==false && $posKeyNic!==false) {
|
|
|
|
$sirenValide = sirenValide($siren);
|
|
|
|
}
|
|
|
|
|
|
|
|
$siren = substr($item, 0, 9);
|
|
|
|
$nic = substr($item, 9);
|
|
|
|
|
|
|
|
//On définit le tableau de retour
|
|
|
|
if ( $posKeySiret!==false ){
|
|
|
|
$tabData[$row-1]['siret'] = $item;
|
|
|
|
} elseif ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
|
|
$tabData[$row-1]['siren'] = $siren;
|
|
|
|
$tabData[$row-1]['nic'] = $nic;
|
|
|
|
} elseif ( $posKeySiren !==false ){
|
|
|
|
$tabData[$row-1]['siren'] = $siren;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($sirenValide===false){
|
|
|
|
echo " - Siren Invalide -";
|
|
|
|
echo "\n";
|
|
|
|
$row++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Vérifier les nic, ou sélectionner le nic du siege actif
|
|
|
|
$nicTmp = 0;
|
|
|
|
$strNic = '';
|
|
|
|
$sqlNic = 'SELECT nic as nicTmp, cj as cjTmp FROM jo.etablissements WHERE siren='.$siren;
|
|
|
|
if (strlen($item)==14 && intval($nic)>0){
|
|
|
|
$stmt = $db->query($sqlNic.' AND nic='.$nic);
|
|
|
|
$result = $stmt->fetchAll();
|
|
|
|
if (count($result)==0){
|
|
|
|
$nic = 0;
|
2011-11-16 13:47:10 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-15 13:58:10 +00:00
|
|
|
|
|
|
|
if (intval($nic)==0){
|
|
|
|
$strNic = ' AND nic>-1 AND actif>-1 ORDER BY siege DESC, actif DESC, nicTmp DESC LIMIT 0,1';
|
|
|
|
$stmt = $db->query($sqlNic.$strNic);
|
|
|
|
$result = $stmt->fetchAll();
|
|
|
|
if (count($result)>0){
|
|
|
|
$nic = $result[0]['nicTmp'];
|
|
|
|
} else {
|
|
|
|
$nic = '00000';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $posKeySiren!==false && $posKeyNic!==false ){
|
|
|
|
$tabData[$row-1]['siren'] = $siren;
|
|
|
|
$tabData[$row-1]['nic'] = $nic;
|
|
|
|
}
|
|
|
|
|
2011-11-16 13:47:10 +00:00
|
|
|
//Récupération des données
|
2011-11-15 13:58:10 +00:00
|
|
|
foreach($tabDico as $element => $select)
|
|
|
|
{
|
2011-11-16 13:47:10 +00:00
|
|
|
//Traitement par requete SQL
|
2011-11-15 13:58:10 +00:00
|
|
|
if (isset(${$element.'Fields'})){
|
2011-11-16 13:47:10 +00:00
|
|
|
$where = $select['where'];
|
|
|
|
eval( "\$where = \"$where\";" );
|
2011-11-15 13:58:10 +00:00
|
|
|
${$element.'SQL'} = 'SELECT '.${$element.'Fields'}.' FROM '.$select['db'].$where;
|
|
|
|
$stmt = $db->query(${$element.'SQL'});
|
|
|
|
$result = $stmt->fetchAll();
|
|
|
|
if (count($result)>0){
|
|
|
|
$tabData[$row-1] = array_merge( $tabData[$row-1] , $result[0]);
|
|
|
|
}
|
|
|
|
}
|
2011-11-16 13:47:10 +00:00
|
|
|
//Traitement par fonction
|
2011-11-17 11:03:30 +00:00
|
|
|
elseif(isset(${$element.'Data'}))
|
2011-11-16 13:47:10 +00:00
|
|
|
{
|
2011-11-17 11:03:30 +00:00
|
|
|
if( ${$element.'Data'}!==false ){
|
|
|
|
$tabData[$row-1] = array_merge( $tabData[$row-1] , ${$element.'Data'}());
|
|
|
|
} else {
|
|
|
|
$values = explode(',', ${$element.'Data'});
|
|
|
|
$tabData[$row-1] = array_merge( $tabData[$row-1] , ${$element.'Data'}($values));
|
|
|
|
}
|
2011-11-16 13:47:10 +00:00
|
|
|
}
|
2011-11-15 13:58:10 +00:00
|
|
|
}
|
|
|
|
echo "\n";
|
|
|
|
$row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Pour chaque tabExtract (column) on crée un tableau pour la ligne CSV dans le bon ordre
|
|
|
|
|
|
|
|
//Entete
|
|
|
|
$tabEntete = array();
|
|
|
|
$tabEntete = $tabExtract;
|
|
|
|
|
|
|
|
//Mettre dans l'ordre les données
|
|
|
|
$tabSortie = array();
|
|
|
|
$row = 0;
|
|
|
|
foreach($tabData as $data){
|
|
|
|
foreach($tabExtract as $key){
|
2011-11-17 11:16:56 +00:00
|
|
|
$tabSortie[$row][] = isset($tabData[$row][$key]) ? $tabData[$row][$key] : '';
|
2011-11-15 13:58:10 +00:00
|
|
|
}
|
|
|
|
$row++;
|
|
|
|
}
|
|
|
|
|
|
|
|
writeCSV($tabSortie, $tabEntete, 'enrichissement.csv');
|
|
|
|
|
2011-11-16 13:47:10 +00:00
|
|
|
|
|
|
|
/* == FUNCTION DATA == */
|
|
|
|
|
2011-11-17 11:03:30 +00:00
|
|
|
function SituationJuridiqueData() {
|
2011-11-16 13:47:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* == FUNCTION == */
|
2011-11-15 13:58:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifie si un SIREN est valide
|
|
|
|
* @param Le code SIREN dont on veut vérifier la validité.
|
|
|
|
* @return Un booléen qui vaut 'true' si le code SIREN passé en
|
|
|
|
* paramètre est valide, false sinon.
|
|
|
|
*/
|
|
|
|
function sirenValide($siren) {
|
|
|
|
if ( (strlen($siren) != 9) || (is_nan($siren)) )
|
|
|
|
$estValide = false;
|
|
|
|
else {
|
|
|
|
// Donc le SIREN est un numérique à 9 chiffres
|
|
|
|
$somme = 0;
|
|
|
|
$tmp = 0;
|
|
|
|
for ($cpt = 0; $cpt<strlen(siren); $cpt++) {
|
|
|
|
if (($cpt % 2) == 1) { // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
|
|
|
|
$tmp = substr($siren, $cpt, 1) * 2; // On le multiplie par 2
|
|
|
|
if ($tmp > 9)
|
|
|
|
$tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$tmp = substr($siren, $cpt, 1);
|
|
|
|
$somme += intval($tmp);
|
|
|
|
}
|
|
|
|
if ((somme % 10) == 0)
|
|
|
|
$estValide = true; // Si la somme est un multiple de 10 alors le SIREN est valide
|
|
|
|
else
|
|
|
|
$estValide = false;
|
|
|
|
}
|
|
|
|
return $estValide;
|
2011-11-16 13:47:10 +00:00
|
|
|
}
|
2011-11-15 13:58:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Verifie si un SIRET est valide
|
|
|
|
* @param Le code SIRET dont on veut vérifier la validité.
|
|
|
|
* @return Un booléen qui vaut 'true' si le code SIRET passé en
|
|
|
|
* paramètre est valide, false sinon.
|
|
|
|
*/
|
|
|
|
function siretValide($siret) {
|
|
|
|
if ( (strlen($siret) != 14) || (is_nan($siret)) )
|
|
|
|
$estValide = false;
|
|
|
|
else {
|
|
|
|
// Donc le SIRET est un numérique à 14 chiffres
|
|
|
|
// Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
|
|
|
|
// correspondent au numéro d'établissement
|
|
|
|
// et enfin le dernier chiffre est une clef de LUHN.
|
|
|
|
$somme = 0;
|
|
|
|
$tmp = 0;
|
|
|
|
for ($cpt = 0; $cpt<strlen(siret); $cpt++) {
|
|
|
|
if (($cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc...
|
|
|
|
$tmp = substr($siret, $cpt, 1) * 2; // On le multiplie par 2
|
|
|
|
if ($tmp > 9)
|
|
|
|
$tmp -= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$tmp = substr($siret, $cpt, 1);
|
|
|
|
$somme += intval(tmp);
|
|
|
|
}
|
|
|
|
if (($somme % 10) == 0)
|
|
|
|
$estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide
|
|
|
|
else
|
|
|
|
$estValide = false;
|
|
|
|
}
|
|
|
|
return $estValide;
|
|
|
|
}
|
|
|
|
|
2011-11-16 13:47:10 +00:00
|
|
|
/**
|
|
|
|
* writeCSV
|
|
|
|
* @param array $list
|
|
|
|
* @param array $entete
|
|
|
|
* @param string $filename
|
|
|
|
*/
|
2011-11-15 13:58:10 +00:00
|
|
|
function writeCSV($list, $entete, $filename)
|
|
|
|
{
|
|
|
|
$fp = fopen($filename, 'w');
|
|
|
|
if (count($entete)>0){
|
|
|
|
fputcsv($fp, $entete, ',');
|
|
|
|
}
|
|
|
|
foreach ($list as $fields) {
|
|
|
|
fputcsv($fp, $fields, ',');
|
|
|
|
}
|
|
|
|
fclose($fp);
|
|
|
|
}
|
|
|
|
|