327 lines
12 KiB
PHP
327 lines
12 KiB
PHP
<?
|
|
|
|
class MTel {
|
|
|
|
public $body = '';
|
|
public $header = '';
|
|
public $codeRetour = 0;
|
|
|
|
public $cookie='';
|
|
public $urlBase='http://www.pagespro.com/recherche.php';
|
|
public $url='';
|
|
public $referer='';
|
|
public $enCache=false;
|
|
private $accesDistant=false;
|
|
|
|
public $iDb;
|
|
|
|
public function __construct($accesDistant=false) {
|
|
$this->accesDistant=$accesDistant;
|
|
$this->accesDistant=false; // Accès bloqué par "pagespro"
|
|
if ($this->accesDistant) {
|
|
$this->url=$this->urlBase;
|
|
$page=getUrl($this->url,$this->cookie,'',$this->referer, false, '', '', 3);
|
|
$this->referer=$this->url;
|
|
$this->cookie=$page['header']['Set-Cookie'];
|
|
$this->body=$page['body'];
|
|
$this->codeRetour=$page['code'];
|
|
}
|
|
$this->iDb=new WDB('jo');
|
|
}
|
|
|
|
/**
|
|
* @todo :
|
|
* 1. Faire une fonction qui récupère les Logos
|
|
* 2. Envoyer les logos par le WS
|
|
* 3. Permettre la recherche par Tel
|
|
*/
|
|
|
|
public function getTel($siret, $nic=0, $last=false, $actif=-1) {
|
|
|
|
$tabRet=$tabLast=array();
|
|
|
|
if (strlen($siret)>9) {
|
|
$nic=substr($siret,-5)*1;
|
|
$siren=round($siret/100000)*1;
|
|
} else
|
|
$siren=$siret*1;
|
|
|
|
if ($siren<1000) return $tabRet;
|
|
|
|
if (strlen($siren)<=9) {
|
|
/** Si le siren est de taille < à 9, on ajoute des 0 significatifs **/
|
|
switch (strlen($siren)) {
|
|
case 1: $siren='00000000'.$siren; break;
|
|
case 2: $siren='0000000'.$siren; break;
|
|
case 3: $siren='000000'.$siren; break;
|
|
case 4: $siren='00000'.$siren; break;
|
|
case 5: $siren='0000'.$siren; break;
|
|
case 6: $siren='000'.$siren; break;
|
|
case 7: $siren='00'.$siren; break;
|
|
case 8: $siren='0'.$siren; break;
|
|
}
|
|
}
|
|
if (strlen($nic)>0) {
|
|
switch (strlen($nic)) {
|
|
case 1: $nic='0000'.$nic; break;
|
|
case 2: $nic='000'.$nic; break;
|
|
case 3: $nic='00'.$nic; break;
|
|
case 4: $nic='0'.$nic; break;
|
|
}
|
|
}
|
|
|
|
$strNic='';
|
|
if ($nic*1>0) $strNic="AND (nic=$nic OR nic=0)";
|
|
$strActif='';
|
|
if ($actif==1) $strActif=" AND actif=1 ";
|
|
elseif($actif==0) $strActif=" AND actif=0 ";
|
|
$ret=$this->iDb->select('telephonie',
|
|
'siren,nic,dateProvPartenaire,typeTel,infoTel,telephone,actif,partenaire,idUtilisateur,dateInsert,dateInsert*1 AS dateInsertYmd,dateConfPartenaire,partenaireConf,nbConf,idUpdate,dateUpdate,dateUpdate*1 AS dateUpdateYmd',
|
|
"siren=$siren $strNic $strActif AND dateSuppr=0 ORDER BY typeTel ASC, nbConf DESC", false, MYSQL_ASSOC);
|
|
if (count($ret)>0) {
|
|
$this->enCache=true;
|
|
foreach ($ret as $tabTel) {
|
|
if ($tabTel['typeTel']=='an8' && $tabTel['infoTel']*1>0) {
|
|
$an8=$tabTel['infoTel']*1;
|
|
$retTmp=$this->iDb->select('tabAn8', 'libAn8', "codAn8='$an8'", false, MYSQL_ASSOC);
|
|
$infoTel=ucfirst(strtolower($retTmp[0]['libAn8']));
|
|
} else
|
|
$infoTel=$tabTel['infoTel'];
|
|
|
|
if ($tabTel['partenaireConf']>0) $source=$tabTel['partenaireConf'];
|
|
else $source=$tabTel['partenaire'];
|
|
if ($tabTel['dateUpdateYmd']>$tabTel['dateInsertYmd']) $dateMAJ=$tabTel['dateUpdateYmd'];
|
|
else $dateMAJ=$tabTel['dateInsertYmd'];
|
|
$tabR=array('siren'=>$siren,
|
|
'nic'=>$tabTel['nic'],
|
|
'typeTel'=>$tabTel['typeTel'],
|
|
'infoTel'=>$infoTel,
|
|
'telephone'=>$tabTel['telephone'],
|
|
'actif'=>$tabTel['actif'],
|
|
'source'=>$source,
|
|
'dateMAJ'=>$dateMAJ,
|
|
);
|
|
$tabRet[]=$tabR;
|
|
if ($last) {
|
|
if ($source==175 && !@isset($tabLast[$tabTel['typeTel']][1])) @$tabLast[$tabTel['typeTel']][1]=$tabR;
|
|
elseif(($source==118 ||
|
|
$source==250 ||
|
|
$source==253) && !@isset($tabLast[$tabTel['typeTel']][2])) @$tabLast[$tabTel['typeTel']][2]=$tabR;
|
|
elseif ($source<>2 && !@isset($tabLast[$tabTel['typeTel']][3])) @$tabLast[$tabTel['typeTel']][3]=$tabR;
|
|
elseif ($source==2 && !@isset($tabLast[$tabTel['typeTel']][4])) @$tabLast[$tabTel['typeTel']][4]=$tabR;
|
|
}
|
|
}
|
|
//sendMail('production@scores-decisions.com', 'ylenaour@scores-decisions.com', "classMTel::getTel($siret,$nic)", print_r($tabRet,true));
|
|
} elseif ($this->accesDistant) {
|
|
$this->enCache=false;
|
|
$tabPost=array( 'p_ACTION'=>'',
|
|
'p_ORDRE'=>'AfficheRes',
|
|
'a_PAGE'=>'1',
|
|
'a_TAG'=>'',
|
|
'a_OccRecherche'=>'',
|
|
'typeRecherche'=>'express',
|
|
'satellite'=>'siret',
|
|
'a_activ'=>'',
|
|
'a_rai_soc'=>'',
|
|
'a_naf'=>'',
|
|
'a_siren'=>$siret,
|
|
'a_tel'=>'',
|
|
'a_geo'=>'',
|
|
'typeTri'=>'',
|
|
'ordreTri'=>'',
|
|
'a_session'=>'',
|
|
);
|
|
//$page=getUrl($this->url,$this->cookie,'',$this->referer, false, '', '', 3);
|
|
$page=getUrl($this->url,$this->cookie,$tabPost,$this->referer,false,'','',3);
|
|
$this->referer=$this->url;
|
|
$this->body=$page['body'];
|
|
$this->codeRetour=$page['code'];
|
|
|
|
$nbResults=0;
|
|
if (preg_match('/<b class="total_responses_nr">(.*)réponses<\/b>/Uis', $this->body, $matches))
|
|
$nbResults=trim(strtr(strip_tags($matches[1]), array(' '=>'','–'=>'')));
|
|
|
|
if ($nbResults>0) {
|
|
$tabResultsHtml=explode('<div class="results_part1">', $this->body);
|
|
for ($i=1; isset($tabResultsHtml[$i]);$i++) {
|
|
$res=$tabTel=array();
|
|
$body=$tabResultsHtml[$i];
|
|
$res['nom']=trim(htm2txt(@getTextInHtml($body, '<div class="results_title">', '_title">', '</div>')));
|
|
$res['adresse']=trim(htm2txt(@getTextInHtml($body, '<div class="coordonnees">','<div>','<table id="t_coord_')));
|
|
|
|
$res['urlSite']=trim(htm2txt(@getTextInHtml($body, '<b class="siteweb">Site Web :</b> ', "javascript:SiteURL('", "','")));
|
|
$res['urlMail']=trim(htm2txt(@getTextInHtml($body, '<b>E-mail :</b>', "&mail=", "', ")));
|
|
$res['urlLogo']=trim(htm2txt(@getTextInHtml($body, '<div class="results_inset_logo">', '" src="', '" border="')));
|
|
$res['tefet']=trim(htm2txt(@getTextInHtml($body, '<b>Effectif établ : </b>','</b>','</div>')));
|
|
|
|
$res['tefet']=trim(htm2txt(@getTextInHtml($body, '<b>Effectif établ : </b>','</b>','</div>')));
|
|
$res['siret']=trim(htm2txt(@getTextInHtml($body, '<b>Siret : </b>','</b>','</div>')));
|
|
$res['nafet']=trim(htm2txt(strip_tags(@getTextInHtml($body, '<b>Code NAF : </b>','</b>','</div>'))));
|
|
|
|
$res['domaines']=trim(preg_replace('/ +/', ' ', preg_replace('/\r+|\n+|\s+/',' ',htm2txt(strip_tags(@getTextInHtml($body, '<div class="puce_domaine">','<strong>','</div>'))))));
|
|
|
|
if ($res['urlSite']<>'') {
|
|
$this->iDb->insert('telephonie', array( 'siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'dateProvPartenaire'=>date('Ymd'),
|
|
'typeTel'=>'web',
|
|
'infoTel'=>$res['urlSite'],
|
|
'telephone'=>0,
|
|
'actif'=>1,
|
|
'partenaire'=>253,
|
|
)
|
|
);
|
|
$tabRet[]=array('siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'typeTel'=>'web',
|
|
'infoTel'=>$res['urlSite'],
|
|
'telephone'=>0,
|
|
);
|
|
}
|
|
if ($res['urlLogo']<>'') {
|
|
$this->iDb->insert('telephonie', array( 'siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'dateProvPartenaire'=>date('Ymd'),
|
|
'typeTel'=>'logo',
|
|
'infoTel'=>$res['urlLogo'],
|
|
'telephone'=>0,
|
|
'actif'=>1,
|
|
'partenaire'=>253,
|
|
)
|
|
);
|
|
$tabRet[]=array('siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'typeTel'=>'logo',
|
|
'infoTel'=>$res['urlLogo'],
|
|
'telephone'=>0,
|
|
);
|
|
}
|
|
if ($res['domaines']<>'') {
|
|
$this->iDb->insert('telephonie', array( 'siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'dateProvPartenaire'=>date('Ymd'),
|
|
'typeTel'=>'domaines',
|
|
'infoTel'=>$res['domaines'],
|
|
'telephone'=>0,
|
|
'actif'=>1,
|
|
'partenaire'=>253,
|
|
)
|
|
);
|
|
$tabRet[]=array('siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'typeTel'=>'domaines',
|
|
'infoTel'=>$res['domaines'],
|
|
'telephone'=>0,
|
|
);
|
|
}
|
|
if ($res['urlMail']<>'') {
|
|
$this->iDb->insert('telephonie', array( 'siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'dateProvPartenaire'=>date('Ymd'),
|
|
'typeTel'=>'mail',
|
|
'infoTel'=>$res['urlMail'],
|
|
'telephone'=>0,
|
|
'actif'=>1,
|
|
'partenaire'=>253,
|
|
)
|
|
);
|
|
$tabRet[]=array('siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'typeTel'=>'mail',
|
|
'infoTel'=>$res['urlMail'],
|
|
'telephone'=>0,
|
|
);
|
|
}
|
|
|
|
if (preg_match_all('/<tr>(?:.*)<th>(?:.*)<span>(.*)(tél|fax)(?:.*)<\/span>(?:.*)<\/th>(?:.*)<td>(?:.*)<span>(.*)<\/span>(?:.*)<\/td>(?:.*)<\/tr>/Uis', $body, $matches)) {
|
|
foreach ($matches[2] as $j=>$tmp) {
|
|
$lib=$tmp;
|
|
$precis=trim(strtr($matches[1][$j], array('-'=>' ')));
|
|
$num=trim(strtr($matches[3][$j],array(' '=>'','<br />'=>'')));
|
|
$tabTel["$lib-$num"]=array('telFax'=>$lib,'type'=>$precis, 'telNum'=>$num);
|
|
}
|
|
$tabTel=array_values($tabTel);
|
|
|
|
|
|
foreach ($tabTel as $tabT) {
|
|
$tabRet[]=array('siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'typeTel'=>trimAccent($tabT['telFax']),
|
|
'infoTel'=>$tabT['type'],
|
|
'telephone'=>$tabT['telNum'],
|
|
'actif'=>1,
|
|
);
|
|
$this->iDb->insert('telephonie', array( 'siren'=>$siren,
|
|
'nic'=>substr($res['siret'],-5),
|
|
'dateProvPartenaire'=>date('Ymd'),
|
|
'typeTel'=>trimAccent($tabT['telFax']),
|
|
'infoTel'=>$tabT['type'],
|
|
'telephone'=>$tabT['telNum'],
|
|
'actif'=>1,
|
|
'partenaire'=>253,
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|
|
} /*else {
|
|
//http://www.annuaire.com/uploads/504/284/504284159/logo.jpg
|
|
//http://www.annuaire.com/email/491314266/
|
|
$url="http://www.annuaire.com/societe/-$siren/";
|
|
//$page=getUrl($this->url,$this->cookie,'',$this->referer, false, '', '', 3);
|
|
$page=getUrl($url,'','','',false,'','',3);
|
|
|
|
if ($page['code']<>301) return false;
|
|
$url2=$page['header']['Location'];
|
|
$page=getUrl($url2,'','',$url,false,'','',3);
|
|
|
|
if (!preg_match('/<a href="http:\/\/www\.annuaire\.com\/inscription\/1\/\?companyid=(.*)&go=next"/Uis', $page['body'], $matches)) {
|
|
print_r($page);
|
|
die($siren);
|
|
}
|
|
}*/
|
|
}
|
|
|
|
|
|
if ($last) {
|
|
$tabRet=array();
|
|
//print_r($tabLast);
|
|
//die();
|
|
foreach($tabLast as $typeTel=>$tabPriorite) {
|
|
ksort($tabPriorite);
|
|
$tabRet[]=current($tabPriorite);
|
|
/*
|
|
$key ( array &$array )()
|
|
echo $typeTel.EOL;
|
|
print_r($tabPriorite);
|
|
if ($typeTel=='tel') die();
|
|
//if ($tabPriorite['typeTel']=='tel') die();*/
|
|
}
|
|
//print_r($tabRet);
|
|
//die();
|
|
/*
|
|
$tabLast[$tabTel['typeTel'][1]]=$tabR;
|
|
elseif(($source==118 ||
|
|
$source==250 ||
|
|
$source==253) && !isset($tabLast[$tabTel['typeTel'][2]])) $tabLast[$tabTel['typeTel'][2]]=$tabR;
|
|
elseif ($source<>2 && !isset($tabLast[$tabTel['typeTel'][3]])) $tabLast[$tabTel['typeTel'][3]]=$tabR;
|
|
elseif ($source==2 && !isset($tabLast[$tabTel['typeTel'][4]])) $tabLast[$tabTel['typeTel'][4]]=$tabR;*/
|
|
}
|
|
return $tabRet;
|
|
}
|
|
|
|
function getOperateur($tel) {
|
|
/*http://www.arcep.fr/index.php?id=interactivenumeros
|
|
Données POST:
|
|
ctrl_flag[do_ctrl]
|
|
bloc[017543]
|
|
CMD[RESULTS_NUMEROTATION]
|
|
http://www.arcep.fr/index.php?id=interactivenumeros&CMD=DETAILS_SOC&uid=158757&bloc=017543&cHash=0c29e39859
|
|
http://www.arcep.fr/uploads/tx_gsavis/05-0233.pdf
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|