2010-11-04 11:21:31 +00:00
< ?
class MOrias {
private $referer = '' ;
private $body = '' ;
private $header = '' ;
private $cookie = '' ;
private $codeRetour = 0 ;
private $accesDist = true ;
private $iDb ;
public $enCache = false ;
public $force = false ;
public $annee = 0 ;
public $erreur = '' ;
function __construct ( $accesDist = true ) { // $adresse, $cp, $ville, $pays='France') {
$this -> accesDist = $accesDist ;
$this -> iDb = new WDb ( 'sdv1' );
}
public function getMaxOrias ( $annee = 0 ) {
if ( $annee * 1 > 0 && $annee * 1 < 100 ) {
$this -> annee = '20' . $annee ;
2011-12-05 08:14:54 +00:00
$annee ++ ;
2010-11-04 11:21:31 +00:00
$strWhere = " (numOrias/1000000)<= $annee " ;
} elseif ( $annee * 1 > 1900 && $annee * 1 < 9999 ) {
$this -> annee = $annee ;
$annee = substr ( '' . $annee , 2 , 2 ) * 1 + 1 ;
$strWhere = " (numOrias/1000000)<= $annee " ;
} else {
$strWhere = '1' ;
$this -> annee = date ( 'Y' ) * 1 ;
}
$ret = $this -> iDb -> select ( 'orias' , 'MAX(numOrias) AS numOrias' , $strWhere , false , MYSQL_ASSOC );
//die($strWhere);
return sprintf ( '%08d' , $ret [ 0 ][ 'numOrias' ]);
}
public function getInfosOrias ( $siren , $numOrias = 0 ) {
//die('numOrias 1:"'.$numOrias.'"');
2011-01-07 09:16:16 +00:00
if ( $siren * 1 > 1000 )
2010-11-04 11:21:31 +00:00
$strWhere = " siren= $siren " ;
elseif ( $numOrias * 1 > 0 ) {
// $numOrias=preg_replace('/[^0-9]/','',$numOrias);
// $numOrias=substr($numOrias,0,2).' '.substr($numOrias,2,3).' '.substr($numOrias,5,3);
$strWhere = " numOrias= $numOrias " ;
// die($strWhere);
//die('numOrias 2:"'.$numOrias.'"');
} else return false ;
/* echo " ================================================================================================= " . EOL ;
echo " ==== SELECT siren, id, nom, cp, ville, adresse, numOrias FROM orias WHERE $strWhere ; " . EOL ;
echo " ================================================================================================= " . EOL ;
*/
$ret = $this -> iDb -> select ( 'orias' , 'siren, id, nom, cp, ville, adresse, numOrias, numOriasAttribue' , $strWhere , false , MYSQL_ASSOC );
if ( ! $this -> force && count ( $ret ) > 0 ) {
$this -> enCache = true ;
$tabRet = $ret [ 0 ]; //array();
$ret = $this -> iDb -> select ( 'orias' , 'categorie, cat, dateInscription, typeStatut, rcsVille, rcsCode, rcsSiren, contact, encaissement, nature, paysPresta, paysEtab' , $strWhere , false , MYSQL_ASSOC );
foreach ( $ret as $i => $tabTmp )
$tabRet [ 'categories' ][] = $tabTmp ;
//die('numOrias 3:"'.$numOrias.'"');
} elseif ( $this -> accesDist == true ) {
$this -> enCache = false ;
// Initialisation Cookies
if ( $numOrias > 0 ) $this -> referer = 'http://www.orias.fr/orias/public/index.jsp' ;
else $this -> referer = 'http://www.orias.fr/orias/public/rechercheavance.html' ;
2011-03-25 16:18:01 +00:00
$page = getUrl ( $this -> referer , '' , '' , '' , false , '' , '' , 15 );
2010-11-04 11:21:31 +00:00
//print_r($page);
if ( $page [ 'code' ] == 200 ) {
$this -> cookie = str_replace ( ' Path=/orias' , '' , $page [ 'header' ][ 'Set-Cookie' ]);
if ( preg_match ( '/id="javax\.faces\.ViewState" value="(.*)"/Ui' , $page [ 'body' ], $matches ))
$this -> codeRetour = $matches [ 1 ];
else {
echo 'Erreur Url=' . $this -> referer . EOL ;
print_r ( $page [ 'body' ]);
return false ;
}
} else return false ;
if ( $numOrias > 0 ) {
$url = 'http://www.orias.fr/orias/public/index.html' ;
$post = array ( 'menu%3AiasSearchForm' => 'menu%3AiasSearchForm' ,
'menu%3AiasSearchForm%3AiasInputText' => sprintf ( '%08s' , $numOrias ),
'javax.faces.ViewState' => $this -> codeRetour ,
'menu%3AiasSearchForm%3AiasSearch' => 'menu%3AiasSearchForm%3AiasSearch' ,
);
} else {
2011-12-05 08:14:54 +00:00
// Recherche avec Siren
2010-11-04 11:21:31 +00:00
$url = 'http://www.orias.fr/orias/public/rechercheavance.html' ;
$post = array ( 'j_id_id45' => 'j_id_id45' ,
'j_id_id45%3Aj_id_id52' => '' ,
'j_id_id45%3AtagRCS' => '' ,
'j_id_id45%3AtagSIREN' => $siren , //441921574,
'j_id_id45%3Aj_id_id160' => '' ,
'j_id_id45%3Aj_id_id167' => '' ,
'j_id_id45%3Aj_id_id175' => '' ,
'javax.faces.ViewState' => $this -> codeRetour ,
'j_id_id45%3Aj_id_id203' => 'j_id_id45%3Aj_id_id203' );
2011-12-05 08:14:54 +00:00
$this -> referer = 'http://www.orias.fr/orias/public/list.html' ;
2010-11-04 11:21:31 +00:00
}
randsleep ( 1 , 2 );
2011-03-25 16:18:01 +00:00
$page = getUrl ( $url , $this -> cookie , $post , $this -> referer , false , '' , '' , 15 );
2010-11-04 11:21:31 +00:00
$this -> referer = $url ;
if ( $page [ 'code' ] == 302 ) $url = $page [ 'header' ][ 'Location' ];
else {
if ( preg_match ( " /Le numéro d'immatriculation n'existe pas/ " , $page [ 'body' ])) {
$tabInsert = array ( 'actif' => 0 ,
'numOrias' => $numOrias ,
'numOriasAttribue' => 0 ,
'dateInsert' => date ( 'YmdHis' ));
$this -> erreur = 'Numéro Orias inexistant' ;
// On enregistre ce numéro comme non attribué si < au dernier numéro attribué
if ( $numOrias < $this -> getMaxOrias ())
$this -> iDb -> insert ( 'orias' , $tabInsert );
}
return false ;
}
if ( $url == 'http://www.orias.fr/orias/public/intermediaire.html' ) {
$page = getUrl ( $url , $this -> cookie , '' , $this -> referer , false , '' , '' , 24 );
$this -> referer = $url ;
$this -> body = $page [ 'body' ];
echo " Recherche par Orias : url= $url " . EOL ;
2011-12-05 08:14:54 +00:00
die ( print_r ( $page ));
2010-11-04 11:21:31 +00:00
} /* else { */
// Liste contenant l'entreprise
$url = 'http://www.orias.fr/orias/public/list.html' ;
randsleep ( 1 , 2 );
$page = getUrl ( $url , $this -> cookie , '' , $this -> referer , false , '' , '' , 24 );
$this -> referer = $url ;
$this -> body = $page [ 'body' ];
if ( preg_match ( '/<td>R\é\;sultat\(s\) de votre recherche \:(?:.*)<strong>(.*)<(?:.*)Interm\é\;diaire\(s\)/Uis' , $this -> body , $matches )) {
$nbInter = trim ( $matches [ 1 ]) * 1 ;
if ( $nbInter == 0 ) return false ;
if ( $nbInter > 1 ) {
@ sendMail ( 'production@scores-decisions.com' , 'ylenaour@scores-decisions.com' , " classMOrias::getInfosOrias sur $siren " , " Plus de 1 intermédiaire recensé... Merci de gérer le cas ! " );
return false ;
}
}
// Initalisation du tableau retour
$tabRet = array ( 'siren' => $siren );
//id="formResult:intermediariesList:13910
if ( preg_match ( '/<td class="dr-table-cell rich-table-cell haut " id="formResult\:intermediariesList\:(.*)\:j_id_id117">(?:.*)<center>(.*)<\/center>/Uis' , $this -> body , $matches )) {
$tabRet [ 'id' ] = trim ( $matches [ 1 ]);
$tabRet [ 'nom' ] = html_entity_decode ( trim ( $matches [ 2 ]));
}
if ( preg_match ( '/<td class="dr-table-cell rich-table-cell r.cp_ville " id="formResult\:intermediariesList\:(?:.*)\:j_id_id124">(?:.*)<center>(.*)<\/center>/Uis' , $this -> body , $matches )) {
$tabTmp = explode ( ' ' , $matches [ 1 ]);
$tabRet [ 'cp' ] = trim ( $tabTmp [ 0 ]);
$tabRet [ 'ville' ] = html_entity_decode ( trim ( $tabTmp [ 1 ]));
//$tabRet['cpVille']=explotrim(str_replace(' ',' ',$matches[1]));
}
if ( preg_match ( '/<td class="dr-table-cell rich-table-cell r.adresse " id="formResult\:intermediariesList\:(?:.*)\:j_id_id133">(.*)<\/td>/Uis' , $this -> body , $matches ))
$tabRet [ 'adresse' ] = html_entity_decode ( trim ( $matches [ 1 ]));
$tabRet [ 'actif' ] = 1 ;
$tabRet [ 'numOriasAttribue' ] = 1 ;
if ( preg_match ( '/<td class="dr-table-cell rich-table-cell r.immat " id="formResult\:intermediariesList\:(?:.*)\:j_id_id138">(?:.*|)(<span style="white-space\: no-wrap;">|Radi\é\; le \:)(.*)(?:<\/span>|<\/td>)/Uis' , $this -> body , $matches )) {
$str = trim ( strtr ( $matches [ 2 ], array ( ' ' => '' , ' ' => '' )));
if ( html_entity_decode ( trim ( str_replace ( ':' , '' , $matches [ 1 ]))) == 'Radié le' ) {
$tabRet [ 'actif' ] = 0 ;
$tabRet [ 'numOrias' ] = $numOrias ;
$tabRet [ 'dateRadiation' ] = $str ;
}
else
$tabRet [ 'numOrias' ] = $str ;
}
if ( preg_match ( '/ id="javax\.faces\.ViewState" value="(.*)" /Uis' , $this -> body , $matches ))
$this -> codeRetour = $matches [ 1 ];
2011-12-05 08:14:54 +00:00
$tabTmp = explode ( " <a href= \" # \" onclick= \" if(typeof jsfcljs == 'function') { jsfcljs(document.getElementById('formResult'), { ' " , $this -> body );
// die($this->body);
2010-11-04 11:21:31 +00:00
foreach ( $tabTmp as $i => $strCat ) {
if ( $i == 0 ) {
if ( count ( $tabTmp ) == 1 ) {
$tabInsert = array_merge ( $tabRet , array ( 'dateInsert' => date ( 'YmdHis' )));
//print_r($tabInsert);
$this -> iDb -> insert ( 'orias' , $tabInsert );
}
$tabRet [ 'categories' ] = array ();
continue ;
}
$tabCat = array ();
//echo "$i:$strCat";
2011-12-05 08:14:54 +00:00
//die();
//:formResult:intermediariesList:107501:j_id_id159:0:j_id_id166':'formResult:intermediariesList:107501:j_id_id159:0:j_id_id166','intermediaryIdParam':'107501','intermediaryRoleIdParam':'Mia'},'');}return false">
2010-11-04 11:21:31 +00:00
if ( preg_match ( '/<span style="text-align\: left">(.*)<\/span>/Ui' , $strCat , $matches ))
$tabCat [ 'categorie' ] = html_entity_decode ( trim ( $matches [ 1 ]));
2011-12-05 08:14:54 +00:00
if ( preg_match ( '/intermediaryRoleIdParam\'\:\'(.*)\'/Uis' , $strCat , $matches ))
2010-11-04 11:21:31 +00:00
$tabCat [ 'cat' ] = $matches [ 1 ];
//print_r($tabCat);
if ( $i == 1 ) { // Tout est dans la même page Html
// Construction du lien vers la fiche d'identité de l'entreprise
$url = 'http://www.orias.fr/orias/public/list.html' ;
$post = array ( 'formResult' => 'formResult' ,
'formResult%3AajaxLoadingModalBoxOpenedState' => '' ,
'javax.faces.ViewState' => $this -> codeRetour ,
'intermediaryIdParam' => $tabRet [ 'id' ],
'intermediaryRoleIdParam' => $tabCat [ 'cat' ],
);
if ( preg_match ( '/(formResult\:intermediariesList\:(?:.*)),intermediaryIdParam,/Ui' , $strCat , $matches )) {
$tabTmp2 = explode ( ',' , $matches [ 1 ]);
$post [ urlencode ( $tabTmp2 [ 0 ])] = urlencode ( $tabTmp2 [ 1 ]);
/* echo " $i " ;
print_r ( $tabCat );
print_r ( $matches ); */
}
randsleep ( 1 , 2 );
$page = getUrl ( $url , $this -> cookie , $post , $this -> referer , false , '' , '' , 24 );
//$this->referer=$url;
$tmpCat = explode ( 'class="dr-tbpnl-cntnt-pstn rich-tabpanel-content-position"' , $page [ 'body' ]);
2011-12-05 08:14:54 +00:00
//die(print_r($page,1));
2010-11-04 11:21:31 +00:00
}
if ( preg_match ( '/<dd class="col3">Date d\'inscription \: <strong>(.*)<\/strong><\/dd>/Uis' , $tmpCat [ $i ], $matches ))
$tabCat [ 'dateInscription' ] =/* Wdate :: dateT ( 'd/m/y' , 'Y-m-d' , */ trim ( $matches [ 1 ]); //);
if ( preg_match ( '/<td align="right"(?: |)>Statut \:<\/td>(.*)<\/strong>/Uis' , $tmpCat [ $i ], $matches ))
$tabCat [ 'typeStatut' ] = trim ( strip_tags ( $matches [ 1 ]));
if ( preg_match ( '/<td align="right">RCS \:<\/td>(?:.*)<td width="5%"><\/td>(?:.*)<td width="70%"><strong>(.*)<\/strong>(.*)SIREN \:(?:.*)<strong>(.*)<\/strong>/Uis' , $tmpCat [ $i ], $matches )) {
$tabCat [ 'rcsVille' ] = trim ( $matches [ 1 ]);
$tabCat [ 'rcsCode' ] = trim ( strtr ( strip_tags ( $matches [ 2 ]), array ( ' ' => '' , ' ' => '' , chr ( 160 ) => '' , " \r " => '' , " \n " => '' )));
$tabCat [ 'rcsSiren' ] = trim ( $matches [ 3 ]);
if ( $siren == 0 ) $tabRet [ 'siren' ] = $tabCat [ 'rcsSiren' ];
2011-12-05 08:14:54 +00:00
}
2010-11-04 11:21:31 +00:00
/*< td align = " right " > Contact </ td >
< td ></ td >
< td >< strong > Fran & ccedil ; ois Meunier
</ strong ></ td >
*/
if ( preg_match ( '/<td align="right">Contact<\/td>(.*)<\/tr>/Uis' , $tmpCat [ $i ], $matches )) {
$tabCat [ 'contact' ] = html_entity_decode ( trim ( strip_tags ( $matches [ 1 ])));
/* < td ></ td >
< td >
< strong >
JEAN - PIERRE CHAUSSAT
</ strong >
</ td >
</ table >*/
}
//print_r($tmpCat[$i]);
if ( preg_match ( " /<strong>(.*)Cet intermédiaire n'est pas autorisé à encaisser les primes ou cotisations d'assurances(.*)< \ /strong>/Uis " , $tmpCat [ $i ]))
$tabCat [ 'encaissement' ] = 0 ;
else
$tabCat [ 'encaissement' ] = 1 ;
if ( preg_match ( '/<span class="txt_ssTitre">(?:.*)Nature de l\'activit\é\; d\'interm\é\;diation(.*)<\/dd>/Uis' , $tmpCat [ $i ], $matches ))
$tabCat [ 'nature' ] = html_entity_decode ( trim ( strip_tags ( $matches [ 1 ])));
if ( preg_match ( '/<td width="50%" valign="top" align="left">\- Etats dans lesquels cet interm\é\;diaire exerce en libre prestation de service(.*)<\/table>(.*)<\/tr>/Uis' , $tmpCat [ $i ], $matches ))
$tabCat [ 'paysPresta' ] = trim ( strip_tags ( $matches [ 1 ]));
if ( preg_match ( '/<td width="222" align="left">\- Etats dans lesquels cet interm\é\;diaire exerce en libert\é\; d\'\é\;tablissement(.*)<\/table>(.*)<\/tr>/Uis' , $tmpCat [ $i ], $matches ))
$tabCat [ 'paysEtab' ] = trim ( strip_tags ( $matches [ 1 ]));
$tabRet [ 'categories' ][] = $tabCat ;
$tabInsert = $tabRet ;
unset ( $tabInsert [ 'categories' ]);
$tabInsert = array_merge ( $tabInsert , $tabCat , array ( 'dateInsert' => date ( 'YmdHis' )));
//print_r($tabInsert);
$this -> iDb -> insert ( 'orias' , $tabInsert );
//echo $tmpCat[$i];
}
2011-12-05 08:14:54 +00:00
}
2010-11-04 11:21:31 +00:00
return $tabRet ;
}
}
2011-01-07 09:16:16 +00:00
?>