iDb=new WDB(); } function getIdentite($siren, $refresh=false) { $siren=$siren*1; $res=$this->iDb->select('artisanat', 'id, siren, actif, numRM, denomination, sigle, nomCommercial, enseigne, fj, effectif, aprm, debutActivite, activite, adresse, cp, ville, cessation, radiation, nbInscriptions, nom, prenom, nomUsage, dateNaiss, lieuNaiss, natio, qualite, qualif, dateQualif, dateFctDeb, dateFctFin, IF(dateInsert>dateUpdate,dateInsert,dateUpdate) AS dateUpdate', "siren=$siren", false, MYSQL_ASSOC); if (count($res)>0 && !$refresh) { $this->enCache=true; $tabInsert=$res[0]; } elseif (ARTISANAT_DISPO_WEB) { $this->enCache=false; $url='http://www.cma-paris.fr/CMP/rm_recherche.php?dom=Gerer&fonction=recherche'; $page=getUrl($url, '', '', $this->referer, false, 'www.cma-paris.fr', false, '', '', 21); $this->body=$page['body']; $this->codeRetour=$page['code']; if ($this->codeRetour<>'200') { $this->libErreur='Erreur Artisanat 200a !'; return false; } $this->cookie=$page['header']['Set-Cookie']; $this->referer=$url; $url='http://www.cma-paris.fr/CMP/rm_recherche.php?dom=Gerer&fonction=cherche'; $postData=array( 'siren_op'=>'%3D', 'siren'=>$siren, 'den_rent_op'=>'%25', 'den_rent'=>'', 'adresse_op'=>'contient', 'adresse'=>'', 'bde_rent_op'=>'%25', 'bde_rent'=>'', 'nom_rdir_op'=>'%25', 'nom_rdir'=>'', 'pren_rdir_op'=>'%25', 'pren_rdir'=>'', 'table'=>'rentreprise',//'rentrad', 'x'=>56, 'y'=>14, ); randsleep(1,2); $page=getUrl($url, $this->cookie, $postData, $this->referer, false, 'www.cma-paris.fr', false, '', '', 21); $this->body=$page['body']; $this->codeRetour=$page['code']; if ($this->codeRetour<>'200') { $this->libErreur='Erreur Artisanat 200b !'; return false; } $this->referer=$url; if (preg_match('/aucune.entreprise.ne.correspond(?:.*)vos.crit(?:.*)de.recherche<\/span>/Uis', $this->body, $matches)) { $url='http://www.cma-paris.fr/CMP/rm_recherche.php?dom=Gerer&fonction=cherche'; $postData=array( 'siren_op'=>'%3D', 'siren'=>$siren, 'den_rent_op'=>'%25', 'den_rent'=>'', 'adresse_op'=>'contient', 'adresse'=>'', 'bde_rent_op'=>'%25', 'bde_rent'=>'', 'nom_rdir_op'=>'%25', 'nom_rdir'=>'', 'pren_rdir_op'=>'%25', 'pren_rdir'=>'', 'table'=>'rentrad', 'x'=>56, 'y'=>14, ); randsleep(1,2); $page=getUrl($url, $this->cookie, $postData, $this->referer, false, 'www.cma-paris.fr', false, '', '', 21); $this->body=$page['body']; $this->codeRetour=$page['code']; if ($this->codeRetour<>'200') { $this->libErreur='Erreur Artisanat 200c !'; return false; } $this->referer=$url; } /** Gestion des multi-inscriptions au RM **/ if (preg_match('/(.*)entreprises.correspondent(?:.*)vos.crit(?:.*)de.recherche<\/span>/Uis', $this->body, $matches)) { $nbRep=trim($matches[1])*1; $iRadMax=-1; if (preg_match_all('//Uis', $this->body, $matches)) { $tabUrls=array_unique($matches[1]); $anRadMax=0; // Recherche de la dernière inscription foreach ($tabUrls as $iUrl=>$url) { // On prend la dernière inscription $tabTmp=explode('&',$url); if (substr($tabTmp[3],0,8)=='an_rera=') { $anRad=substr($tabTmp[3],8); if ($anRad>$anRadMax) { $anRadMax=$anRad; $iRadMax=$iUrl; } } } } if ($iRadMax==-1) die('$iRadMax==-1 Cas impossible !'.EOL.print_r($tabUrls,true).EOL.print_r($matches,true)); // Accès à la dernière fiche $url='http://www.cma-paris.fr/CMP/'.strtr(trim($tabUrls[$iRadMax]),array('&'=>'&')); randsleep(1,2); $page=getUrl($url, $this->cookie, '', $this->referer, false, 'www.cma-paris.fr', false, '', '', 21); $this->body=$page['body']; $this->codeRetour=$page['code']; if ($this->codeRetour<>'200') { $this->libErreur='Erreur Artisanat 200c !'; return false; } $this->referer=$url; } $tabInsert=array(); if (preg_match('/n° d\'identification \(SIREN\)<\/span><\/td>(?:.*)(.*) <\/td>(?:.*)n° de gestion rm<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) { $sirenLu=$matches[1]*1; if ($siren==$sirenLu) { $tabInsert['siren']=$matches[1]; $tabInsert['numRM']=$matches[2]; } else { $this->libErreur='Erreur Siren $sirenLu<>$siren !'; return false; } } $actif=null; if (preg_match("/Renseignements.relatif(?:.*)entreprise(.*)<\/b>/Uis", $this->body, $matches)) { switch (trim(strtr($matches[1],array(chr(160)=>'')))) { case 'en activité': $actif=1; break; case 'radiée': $actif=0; break; default: print_r($matches);die(); break; } //die(EOL.'$actif='.$actif.EOL.print_r($matches)); } $tabInsert['actif']=$actif; if ($actif===null) { //die("siren=$siren".EOL."sirenLu=$sirenLu".EOL.$this->body); $this->libErreur='Erreur Actif/Radié non trouvé !'; return false; } if (preg_match('/dénomination<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) { $tabInsert['denomination']=$matches[1]; } if (preg_match('/dénomination<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['denomination']=$matches[1]; if (preg_match('/sigle<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['sigle']=$matches[1]; if (preg_match('/ nom commercial<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['nomCommercial']=$matches[1]; if (preg_match('/enseigne<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['enseigne']=$matches[1]; if (preg_match('/forme juridique<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['fj']=$matches[1]; if (preg_match('/effectif<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['effectif']=$matches[1]; if (preg_match('/code APRM<\/span><\/td>(?:.*)(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['aprm']=$matches[1]; if (preg_match('/début d\'activité<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['debutActivite']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); if (preg_match('/ activité\(s\) exercée\(s\) donnant lieu à immatriculation<\/span>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['activite']=trim($matches[1]); if (preg_match('/adresse de l\'entreprise<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['adresse']=trim($matches[1]); if (preg_match('/code postal<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['cp']=trim($matches[1]); if (preg_match('/ville<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['ville']=trim($matches[1]); if (preg_match('/cessation d\'activité<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['cessation']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); if (preg_match('/radiation du RM<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['radiation']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); $tabEtabs=array(); if (preg_match('/(?:.*)Aucune inscription complémentaire<\/b>(?:.*)/Uis', $this->body, $matches)) $tabInsert['nbInscriptions']=0; elseif (preg_match('/(?:.*)Inscription complémentaire<\/b>(.*)/Uis', $this->body, $matches)) { $tabInsert['nbInscriptions']=0; if (preg_match_all('/(?:.*)<\/td>(?:.*)(?:.*)(.*)<\/td>(?:.*)(?:.*)(.*)<\/td>(?:.*)(?:.*)(.*)<\/td>(?:.*)(?:.*)(.*)<\/td>(?:.*)(?:.*)(.*)<\/td>(?:.*)<\/tr>/Uis', $matches[1], $matches2)) { foreach ($matches2[1] as $i=>$adresse) { $tabEtabs[$i]['siren'] =$siren; $tabEtabs[$i]['num'] =$i; $tabEtabs[$i]['adresse'] =trim(strtr(html_entity_decode($adresse),chr(160),' ')); $tabEtabs[$i]['cpVille'] =trim(strtr(html_entity_decode($matches2[2][$i]),chr(160),' ')); $tabEtabs[$i]['enseigne']=trim(strtr(html_entity_decode($matches2[3][$i]),chr(160),' ')); $tabEtabs[$i]['actDeb'] =WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches2[4][$i]),chr(160),' '))); $tabEtabs[$i]['actFin'] =WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches2[5][$i]),chr(160),' '))); $tabInsert['nbInscriptions']++; } } } /** Informations sur la Personne Physique **/ if (preg_match('/nom<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['nom']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/prénom<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['prenom']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/nom d\'usage<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['nomUsage']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/ date de naissance<\/span><\/td>(?:.*)-->(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['dateNaiss']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); // if (preg_match('/date de naissance(.*)body, $matches)) // die(print_r($matches)); if (preg_match('/ lieu de naissance<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['lieuNaiss']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/nationalité<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['natio']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/qualité<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['qualite']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/qualification artisanale<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['qualif']=trim(strtr(html_entity_decode($matches[1]),chr(160),' ')); if (preg_match('/date d\'obtention<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['datequalif']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); if (preg_match('/prise de fonction<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['dateFctDeb']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); if (preg_match('/fin de fonction<\/span><\/td>(?:.*)(.*)<\/td>/Uis', $this->body, $matches)) $tabInsert['dateFctFin']=WDate::dateT('d/m/Y', 'Y-m-d', trim(strtr(html_entity_decode($matches[1]),chr(160),' '))); } // Insertion en base de données $tabInsert['dateInsert']=date('Y-m-d H:i:s'); $id=$this->iDb->insert('artisanat', $tabInsert, true); $tabInsert['id']=$id; foreach ($tabEtabs as $tabInsert2) { $tabInsert2['dateInsert']=$tabInsert['dateInsert']; $id2=$this->iDb->insert('artisanat_etab', $tabInsert2, true); } $tabInsert['dateUpdate']=substr($tabInsert['dateInsert'],0,10); unset($tabInsert['dateInsert']); /* $tabRet=array( 'id' => $id,// A calculer après insert 'Pertinence' => 100, 'Siret' => $siren.'00000', 'Siege' => $siege, 'Nom' => $nom, 'Nom2' => $nomCom, 'Sigle' => '',//prepareString($etab['Sigle']), 'Enseigne' => $ens, 'Adresse' => $adr, 'Adresse2' => $adr2,//prepareString($etab['Adresse2']), 'CP' => $cp, 'Ville' => $ville, 'Tel' => '',//$etab['Tel'], 'Fax' => '',//$etab['Fax'], 'FJ' => $cj, 'FJLib' => $cjLib, 'Siren' => $siren, 'Nic' => '00000', 'Actif' => 0, 'NafEtab' => $naf, 'NafEtabLib' => $nafLib, 'NafEnt' => $naf, 'NafEntLib' => $nafLib, 'NumRC' => $numRC, 'NumRC2' => $numRC2, 'NumGreffe' => $greffe_num, 'DateCreation' => $dateCre, 'DateRadiation' => $dateRad, 'DateCloture' => $dateCloture, 'DateUpdate' => substr($dateInsert,0,10), ); return $tabRet; */ } return $tabInsert; } } ?>