batch/bin/getTelSources.php

472 lines
21 KiB
PHP
Raw Permalink Normal View History

2015-09-04 14:56:16 +02:00
#!/usr/bin/php
<?php
error_reporting(E_ALL ^ E_DEPRECATED ^ E_NOTICE ^ E_STRICT);
include_once(__DIR__.'/../includes/auto_prepend.php');
include_once(INCLUDE_PATH.'insee/classMInsee.php');
include_once(FWK_PATH.'mail/sendMail.php');
$strInfoScript='Usage : '.basename($argv[0]). " [OPTION]
R<EFBFBD>cup<EFBFBD>ration des informations de contact issues des march<EFBFBD>s publics
Options :
-a Ne pas traiter les administrations des March<EFBFBD>s Publics
-e Ne pas traiter les entreprises des March<EFBFBD>s Publics
-v Mode verbose
-m Ne pas envoyer le mail d'informations
";
$mInsee=new MInsee();
$tabSrc=array( 'pjms'=>array('lib'=>'PagesJaunesMS',
'db'=>'tmp',
'table'=>'pjms201505',
'zones'=>"seq AS id, SUBSTRING(siret,1,9) AS siren, SUBSTRING(siret,10,5) AS nic, '' AS poste, '' AS mail, '' AS web,
20150630 AS dateInsert,
0 AS dateUpdate,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax,
rubrique_pro AS an8",
'where'=>"siret>100000000 AND (tel<>'' OR fax<>'' OR rubrique_pro<>'')",
'go'=>0,
'idSrc'=>118),
/** @todo : Ne charger les donn<EFBFBD>es PJMS qu'apr<EFBFBD>s avoir mis le fichier sur le serveur,
* ./loadCSV.php -s=/t -d=tmp -t=pjms -e 2014101000948_Scores_et_Decisions.csv
**/
'adm'=>array('lib'=>'Administrations',
'db'=>'jo',
'table'=>'boamp_detail',
'zones'=>"id, siren, nic, poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert, dateUpdate,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND nic>9 AND recupTel=0 AND (poste<>'' OR tel<>'' OR fax<>'' OR email<>'' OR web<>'')",
'go'=>1,
'idSrc'=>131),
'ent'=>array('lib'=>'Entreprises',
'db'=>'jo',
'table'=>'boamp_lots',
'zones'=>"id, siren, nic, poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert, dateUpdate,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND nic>9 AND recupTel=0 AND (poste<>'' OR tel<>'' OR fax<>'' OR email<>'' OR web<>'')",
'go'=>1,
'idSrc'=>131),
'asso'=>array('lib'=>'Associations',
'db'=>'jo',
'table'=>'asso',
'zones'=>"id, siren, nic, '' AS poste, Assoc_Mail AS mail, Assoc_Web AS web, DATE(dateInsert)*1 AS dateInsert, dateUpdate",
'where'=>"siren>1000 AND nic>9 AND recupTel=0 AND (Assoc_Mail<>'' OR Assoc_Web<>'')",
'go'=>1,
'idSrc'=>3),
'assocpt'=>array('lib'=>'Comptes Associations',
'db'=>'jo',
'table'=>'asso_bilans',
'zones'=>"id, siren, NULL AS nic, '' AS poste, siteWeb AS web, DATE(dateInsert)*1 AS dateInsert, dateUpdate",
'where'=>"siren>1000 AND recupTel=0 AND (siteWeb LIKE '%@%' OR siteWeb LIKE '%http%' OR siteWeb LIKE '%www%' OR siteWeb LIKE '%.fr' OR siteWeb LIKE '%.org' OR siteWeb LIKE '%.com')",
'go'=>1,
'idSrc'=>3),
'mand'=>array('lib'=>'Mandataires',
'db'=>'jo',
'table'=>'tabMandataires',
'zones'=>"id, sirenMand AS siren, nicMand AS nic, '' AS poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"sirenMand>1000 AND nicMand>9 AND recupTel=0 AND (tel<>'' OR fax<>'' OR email<>'' OR web<>'')",
'go'=>1,
'idSrc'=>176),
'mandGrp'=>array('lib'=>'MandatairesGrp',
'db'=>'jo',
'table'=>'tabMandataires',
'zones'=>"id, sirenGrp AS siren, nicGrp AS nic, '' AS poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"sirenGrp>1000 AND nicGrp>9 AND recupTel=0 AND (tel<>'' OR fax<>'' OR email<>'' OR web<>'')",
'go'=>1,
'idSrc'=>176),
'annuWeb'=>array('lib'=>'Annuaire.com Web',
'db'=>'telephonie',
'table'=>'societe_ent',
'zones'=>"id, siren, 0 AS nic, '' AS poste, web, DATE(dateInsert)*1 AS dateInsert",
'where'=>"siren>1000 AND recupTel=0 AND web<>''",
'go'=>1,
'idSrc'=>251),
'annuTel'=>array('lib'=>'Annuaire.com Tel',
'db'=>'telephonie',
'table'=>'societe_tel',
'zones'=>"id, siren, NULL AS nic, infoTel AS poste, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(numTel,'-',''),' ',''),',',''),'.','') AS tel",
'where'=>"siren>1000 AND recupTel=0 AND libTel='T<>l<EFBFBD>phone'",
'go'=>1,
'idSrc'=>251),
'insee'=>array('lib'=>'Insee Even',
'db'=>'insee',
'table'=>'insee_even',
'zones'=>"id, insSIREN as siren, insNIC as nic, '' AS poste, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(insTEL,'-',''),' ',''),',',''),'.','') AS tel",
'where'=>"insTEL<>'' AND recupTel=0",
'go'=>1,
'idSrc'=>2),
'annuFax'=>array('lib'=>'Annuaire.com Fax',
'db'=>'telephonie',
'table'=>'societe_tel',
'zones'=>"id, siren, NULL AS nic, infoTel AS poste, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(numTel,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND recupTel=0 AND libTel='Fax'",
'go'=>1,
'idSrc'=>251),
'tourisme'=>array('lib'=>'Hotels/Campings',
'db'=>'jo',
'table'=>'tourisme',
'zones'=>"id, siren, nic, '' AS poste, mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND nic>9 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>200),
'qualifelec'=>array('lib'=>'Qualifelec',
'db'=>'sdv1',
'table'=>'qualifelec',
'zones'=>"id, SUBSTRING(siret,1,9) AS siren, SUBSTRING(siret,10,5) AS nic, '' AS poste, mail, web, DATE(dateInsert)*1 AS dateInsert, tel, fax",
'where'=>"siret>100000000 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>211),
'qualipaysage'=>array('lib'=>'Qualipaysage',
'db'=>'sdv1',
'table'=>'qualipaysage',
'zones'=>"id, SUBSTRING(siret,1,9) AS siren, SUBSTRING(siret,10,5) AS nic, '' AS poste, mail, web, DATE(dateInsert)*1 AS dateInsert, tel, fax",
'where'=>"siret>100000000 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>212),
'qualibat'=>array('lib'=>'Qualibat',
'db'=>'sdv1',
'table'=>'qualibat',
'zones'=>"id, siren, NULL AS nic, '' AS poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(tel,')',''),'(',''),'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(fax,')',''),'(',''),'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND recupTel=0 AND (tel<>'' OR fax<>'' OR email<>'' OR web<>'')",
'go'=>1,
'idSrc'=>213),
'ecoartisan'=>array('lib'=>'EcoArtisan',
'db'=>'sdv1',
'table'=>'ecoartisan',
'zones'=>"id, SUBSTRING(siret,1,9) AS siren, SUBSTRING(siret,10,5) AS nic, '' AS poste, mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(tel,')',''),'(',''),'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(fax,')',''),'(',''),'-',''),' ',''),',',''),'.','') AS fax,
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(mob,')',''),'(',''),'-',''),' ',''),',',''),'.','') AS mob",
'where'=>"siret>100000000 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mob<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>214),
'finess'=>array('lib'=>'Finess',
'db'=>'sante',
'table'=>'finess',
'zones'=>"id, SUBSTRING(SIRET,1,9) AS siren, SUBSTRING(SIRET,10,5) AS nic, '' AS poste, '' AS mail, '' AS web, DATE(NOW())*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(Tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(Fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"SIRET>1000 AND recupTel=0 AND (Tel<>'' OR Fax<>'')",
'go'=>0,
'idSrc'=>210),
'cncc'=>array('lib'=>'CNCC',
'db'=>'sdv1',
'table'=>'tabCNCC',
'zones'=>"id, siren, nic, '' AS poste, mail, web, dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(Tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(Fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>100 AND nic>9 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>300),
'amf_mairies'=>array('lib'=>'AMFM',
'db'=>'jo',
'table'=>'villes',
'zones'=>"id, siren, nic, '' AS poste, '' AS mail, web, dateMajAMF AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>100 AND nic>9 AND recupTel=0 AND (tel<>'' OR fax<>'' OR web<>'')",
'go'=>1,
'idSrc'=>400),
'banatic'=>array('lib'=>'Banatic',
'db'=>'insee',
'table'=>'banatic_coor',
'zones'=>"id, sirenGrp AS siren, NULL AS nic, '' AS poste, mail, web, dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"sirenGrp>100 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>52),
'infos_entrep'=>array('lib'=>'InfosEntrep',
'db'=>'jo',
'table'=>'infos_entrep',
'zones'=>"id, siren, nic, '' AS poste, mail, web, dateUpdate AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND recupTel=0 AND (tel<>'' OR fax<>'' OR mail<>'' OR web<>'')",
'go'=>1,
'idSrc'=>175),
'crmScores'=>array('lib'=>'CRM Scores',
'db'=>'sugarcrm',
'table'=>'accounts',
'zones'=>"id, ticker_symbol AS siren, NULL AS nic, '' AS poste, email1 AS mail, website AS web, IF(date_modified>date_entered, date_modified, date_entered) AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(phone_office,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(phone_alternate,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"ticker_symbol>1000 AND recupTel=0 AND (phone_office<>'' OR phone_alternate<>'' OR email1<>'' OR website<>'')",
'go'=>1,
'idSrc'=>252),
/*
`id` , `billing_address_street` , `billing_address_city` , `billing_address_state` , `billing_address_postalcode` ,
`phone_office` , `phone_alternate` , `email1` , `email2` , `website` , `ticker_symbol` , `shipping_address_street` ,
`shipping_address_city` , `shipping_address_state` , `shipping_address_postalcode` , `date_entered` , `date_modified` , `modified_user_id` , `deleted`
FROM `accounts`
ORDER BY `accounts`.`date_modified` ASC
*/
);
$tabZones=array('tel', 'fax', 'mob', 'mail', 'web', 'an8');
$verbose=$noMail=false;
$argv=$_SERVER['argv'];
if ($_SERVER['argc']>1) {
for ($i=1; isset($argv[$i]); $i++) {
if (substr($argv[$i],0,1)=='-') {
switch (substr($argv[$i],1,1)) {
case 'a':
$tabSrc['adm']['go']=0;
break;
case 'e':
$tabSrc['ent']['go']=0;
break;
case 'v':
$verbose=true;
break;
case 'm':
$noMail=true;
break;
/* case 'i':
$index=trim(substr($argv[$i],3));
break;*/
case '-':
case '?':
die($strInfoScript);
break;
default:
die('Option '. $argv[$i] . " inconnue !\n");
break;
}
}
}
}
echo date('Y/m/d - H:i:s') ." - DEBUT du programme de r<>cup<75>ration des Tel, Fax, Mel et Web issus des diff<66>rentes sources...".EOL;
$iDb=new WDB('jo');
$iDb2=new WDB('jo');
foreach ($tabSrc as $src=>$tabSrcDet) {
if ($tabSrcDet['go']==0) {
echo date('Y/m/d - H:i:s') ." - On ne traite pas les contacts '".$tabSrcDet['lib']."'".EOL;
continue;
}
echo date('Y/m/d - H:i:s') ." - Traitement des contacts '".$tabSrcDet['lib']."' (Source ".$tabSrcDet['idSrc'].")".EOL;
unset($iDb);
$iDb=new WDB($tabSrcDet['db']);
//enum('an8', 'domaines', 'fax', 'logo', '', 'mob', 'tel', 'web')
$nb=$iDb->select($tabSrcDet['table'], $tabSrcDet['zones'],$tabSrcDet['where'], false,MYSQL_ASSOC,true);
if (mysql_errno()<>0) die(mysql_error().EOL);
echo date ('Y/m/d - H:i:s')." - Il y a $nb ligne(s) de contacts '".$tabSrcDet['lib']."' <20> mettre <20> jour...".mysql_error().EOL;
$j=0;
while ($tabTel=$iDb->fetch(MYSQL_ASSOC)) {
$j++;
$siren=$tabTel['siren'];
$nic =$tabTel['nic'];
foreach ($tabZones as $zone) {
// Si la zone n'existe pas dans la table o<> on lit les infos de contacts
if (!isset($tabTel[$zone])) continue;
// Le t<>l<EFBFBD>phone doit faire 10 chiffres
if (($zone=='tel' || $zone=='fax' || $zone=='mob') && strlen($tabTel[$zone])<10 && $tabTel[$zone]*1<100000000) continue;
if ($zone<>'tel' && $zone<>'fax' && $zone<>'mob') {
if (strlen($tabTel[$zone])<4) continue;
$tel=0;
$infoTel=preg_replace('/(\s|,|\.|;)+$/','',trim($tabTel[$zone]));
$infoTel=preg_replace('/ ou .*| et .*| \(ou\) .*| \(et\) .*| ; .*| \/ .*/','',trim($infoTel));
if ($verbose) echo $tabSrcDet['lib']." $j/$nb - ".$tabTel['id']. ", $siren $nic - $zone : ".$tabTel[$zone].' ==> '.$infoTel.EOL;
} else {
$tel=$tabTel[$zone];
$infoTel='';
if ($verbose) echo $tabSrcDet['lib']." $j/$nb - ".$tabTel['id']. ", $siren $nic - $zone : ".$tabTel[$zone].' ==> '.$tel.EOL;
}
//continue;
if ($iDb2->insert('telephonie', array( 'siren'=>$siren,
'nic'=>$nic,
'dateProvPartenaire'=>str_replace('-','',$tabTel['dateInsert']),
'typeTel'=>$zone,
'actif'=>1,
'infoTel'=>$infoTel,
'telephone'=>$tel,
'partenaire'=>$tabSrcDet['idSrc'])) || $iDb2->getLastErrorNum()==1062) {
if ($iDb2->getLastErrorNum()<>1062) {
@$nbInsert[$zone]++;
@$nbInsertSrc[$zone][$src]++;
}
elseif ($iDb2->getLastErrorNum()==1062) {
$ret2=$iDb2->select('telephonie', 'nbConf', "siren=$siren AND nic=$nic AND typeTel='$zone' AND infoTel='$infoTel' AND telephone=$tel", false, MYSQL_ASSOC);
$nbConf=($ret2[0]['nbConf']*1)+1;
$iDb2->update('telephonie', array( 'dateConfPartenaire'=>str_replace('-','',$tabTel['dateInsert']),
'partenaireConf'=>$tabSrcDet['idSrc'],
'nbConf'=>$nbConf), "siren=$siren AND nic=$nic AND typeTel='$zone' AND infoTel='$infoTel' AND telephone=$tel", false);
@$nbUpdateSrc[$zone][$src]++;
@$nbUpdate[$zone]++;
}
@$nbTot[$zone]++;
$tabUpdate=array('recupTel'=>1);
if (isset($tabTel['dateUpdate'])) $tabUpdate['dateUpdate']=$tabTel['dateUpdate'];
$iDb->update($tabSrcDet['table'], $tabUpdate, "id='".$tabTel['id']."'");
} else die($iDb2->getLastError());
}
}
}
print_r($nbInsert);
print_r($nbUpdate);
print_r($nbTot);
if (!$noMail) {
$message=date('Y/m/d - H:i:s') ." - Fin de la r<>cup<75>ration des Tel, Fax, Mel et Web issus des diff<66>rentes sources :".EOL;
foreach ($tabZones as $zone)
$message.=" Nombre de nouveaux '$zone' = ".@$nbInsert[$zone].' ajouts et '.@$nbUpdate[$zone].' MAJ / '.@$nbTot[$zone].' lignes'.EOL;
$message.=EOL;
foreach ($tabZones as $zone) {
foreach ($tabSrc as $src=>$tabSrcDet) {
$nbTotTmp=@$nbInsertSrc[$zone][$src]+@$nbUpdateSrc[$zone][$src];
if ($nbTotTmp>0) $message.=" Source '".sprintf("%-20s", $tabSrcDet['lib']."'")." nb. nouveaux '$zone' = ".@$nbInsertSrc[$zone][$src].' ajouts et '.@$nbUpdateSrc[$zone][$src].' MAJ / '.@$nbTotTmp.' lignes'.EOL;
}
}
sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com,support@scores-decisions.com', "R<EFBFBD>cup<EFBFBD>ration des Tel, Fax, Mel et Web", $message);
}
echo date('Y/m/d - H:i:s') ." - FIN du programme de r<>cup<75>ration des Tel, Fax, Mel et Web issus des diff<66>rentes sources.".EOL;
die();
/** Mise <20> jour des fonctions de direction **/
$tabFonctions=array('maire',
'directeur',
'pr<70>sident',
'd<>put<75>',
'directrice',
's<>nateur',
'proviseur',
'secr<63>taire',
'pr<70>fet',
'adjoint',
'chef',
'conseiller',
'ing<6E>nieur',
);
$strFct='';
foreach ($tabFonctions as $iFct=>$fct) {
if ($iFct>0) $strFct.=' OR ';
$strFct.="destinataire LIKE '%$fct%'";
}
$tabSrc=array( 'adm'=>array('lib'=>'Administrations',
'db'=>'jo',
'table'=>'boamp_detail',
'zones'=>"id, siren, nic, destinataire, poste, email AS mail, web, DATE(dateInsert)*1 AS dateInsert,
REPLACE(REPLACE(REPLACE(REPLACE(tel,'-',''),' ',''),',',''),'.','') AS tel,
REPLACE(REPLACE(REPLACE(REPLACE(fax,'-',''),' ',''),',',''),'.','') AS fax",
'where'=>"siren>1000 AND nic>9 AND recupDir=0 AND LENGTH(destinataire)>18 AND ($strFct)",
'go'=>1,
'idSrc'=>131),
);
echo date('Y/m/d - H:i:s') ." - DEBUT du programme de r<>cup<75>ration des Dirigeants issus de March<63>s Publics...".EOL;
$iDb=new WDB('jo');
$iDb2=new WDB('jo');
foreach ($tabSrc as $src=>$tabSrcDet) {
if ($tabSrcDet['go']==0) {
echo date('Y/m/d - H:i:s') ." - On ne traite pas les contacts '".$tabSrcDet['lib']."'".EOL;
continue;
}
echo date('Y/m/d - H:i:s') ." - Traitement des contacts '".$tabSrcDet['lib']."'".EOL;
unset($iDb);
$iDb=new WDB($tabSrcDet['db']);
//enum('an8', 'domaines', 'fax', 'logo', '', 'mob', 'tel', 'web')
$nb=$iDb->select($tabSrcDet['table'], $tabSrcDet['zones'],$tabSrcDet['where'], false,MYSQL_ASSOC,true);
echo date ('Y/m/d - H:i:s')." - Il y a $nb ligne(s) de contacts '".$tabSrcDet['lib']."' <20> mettre <20> jour...".mysql_error().EOL;
while ($tabTel=$iDb->fetch(MYSQL_ASSOC)) {
$siren=$tabTel['siren'];
$nic =$tabTel['nic'];
print_r($tabTel);
continue;
foreach ($tabZones as $zone) {
// Si la zone n'existe pas dans la table o<> on lit les infos de contacts
if (!isset($tabTel[$zone])) continue;
// Le t<>l<EFBFBD>phone doit faire 10 chiffres
if (($zone=='tel' || $zone=='fax') && strlen($tabTel[$zone])<10) continue;
if ($zone<>'tel' && $zone<>'fax') {
$tel=0;
$infoTel=preg_replace('/(\s|,|\.|;)+$/','',trim($tabTel[$zone]));
echo $tabTel['id']. ", $siren : ".$tabTel[$zone].' ==> '.$infoTel.EOL;
} else {
$tel=$tabTel[$zone];
$infoTel='';
}
//continue;
if ($iDb2->insert('telephonie', array( 'siren'=>$siren,
'nic'=>$nic,
'dateProvPartenaire'=>$tabTel['dateInsert'],
'typeTel'=>$zone,
'actif'=>1,
'infoTel'=>$infoTel,
'telephone'=>$tel,
'partenaire'=>$tabSrcDet['idSrc'])) || $iDb2->getLastErrorNum()==1062) {
@$nbInsert[$zone]++;
$iDb->update($tabSrcDet['table'], array('recupTel'=>1), "id='".$tabTel['id']."'");
} else die($iDb2->getLastError());
}
}
}
die();
$nbAvecMaj=$nbSansMaj=$nbErr=0;
while ($tabTel=$iDbSel->fetch(MYSQL_ASSOC)) {
$siren=$tabTel['siren'];
$tel=trim(strtr($tabTel['tel'], array('.'=>'', ' '=>'', '-'=>'')));
$fax=trim(strtr($tabTel['fax'], array('.'=>'', ' '=>'', '-'=>'')));
$tabTmp=$iDbMaj->select('identite', 'id, SIREN, NIC, ACTIF, SIEGE, TEL, FAX',"SIREN=$siren ORDER BY SIEGE DESC, ACTIF DESC LIMIT 0,1", false, MYSQL_ASSOC);
if (count($tabTmp)>0) {
$tabUpdate=array();
$etab=$tabTmp[0];
$id=$etab['id'];
$telPrev=$etab['TEL'];
$faxPrev=$etab['FAX'];
if ($telPrev=='' && $tel<>'') $tabUpdate['TEL']=$tel;
if ($faxPrev=='' && $fax<>'') $tabUpdate['FAX']=$fax;
if (count($tabUpdate)>0) {
$iDbMaj->update('identite',$tabUpdate, "id='$id'");
echo date ('Y/m/d - H:i:s')." - Siren $siren, Tel $tel, Fax $fax : Mise <20> jour OK".EOL;
$nbAvecMaj++;
}
else {
$nbSansMaj++;
// echo date ('Y/m/d - H:i:s')." - Siren $siren, Tel $tel, Fax $fax : PAS de mise <20> jour".EOL;
}
} else {
echo date ('Y/m/d - H:i:s')." - Siren $siren, Tel $tel, Fax $fax : Pas de fiche identite !".EOL;
$nbErr++;
// die();
}
/*print_r($tabTel);
print_r($tabTmp);
die();*/
}
echo date ('Y/m/d - H:i:s')." - FIN de la mise <20> jour des TEL/FAX des entreprises ($nbAvecMaj MAJ/$nbTel avec $nbErr erreurs).".EOL;
die();
?>