2009-07-07 14:50:59 +00:00
< ?
2009-07-08 13:24:01 +00:00
isset ( $_REQUEST [ 'ajax' ]) ? $ajax = TRUE : $ajax = FALSE ;
if ( $ajax === TRUE ){
session_start ();
require_once realpath ( dirname ( __FILE__ ) . '/../../config/prepend.php' );
require_once 'common/dates.php' ;
require_once 'common/curl.php' ;
require_once 'infogreffe/kbis.php' ;
//Connection au webservice
$client = new SoapClient ( null , array ( 'trace' => 1 ,
'soap_version' => SOAP_1_1 ,
'location' => WEBSERVICE_URL ,
'uri' => WEBSERVICE_URI ,
'login' => $_SESSION [ 'tabInfo' ][ 'login' ],
'password' => $_SESSION [ 'tabInfo' ][ 'password' ],
));
isset ( $_REQUEST [ 'siret' ]) ? $siret = $_REQUEST [ 'siret' ] : $siret = '' ;
2009-07-10 07:29:54 +00:00
isset ( $_REQUEST [ 'start' ]) ? $start = $_REQUEST [ 'start' ] : $start = 0 ;
2009-07-10 08:12:36 +00:00
$login = strtolower ( $_SESSION [ 'tabInfo' ][ 'login' ]);
2009-07-08 13:24:01 +00:00
$siren = substr ( $siret , 0 , 9 );
2009-07-08 14:58:52 +00:00
//getKbis pour la premiere requete
2009-07-10 07:29:54 +00:00
if ( $start != 0 ){
if ( $start > 1 ){
mail ( 'ylenaour@scores-decisions.com' , " Commande de KBIS essai: $start pour $login ( $siren ) " ,
'REQUEST=' . EOL . print_r ( $_REQUEST , true ) . 'EOL' .
'SERVER=' . EOL . print_r ( $_SERVER , true ) . 'EOL' .
'SESSION=' . EOL . print_r ( $_SESSION , true ) . 'EOL' .
'ENV=' . EOL . print_r ( $_ENV , true ) . 'EOL' .
'tabInfo=' . print_r ( $tabInfo , true ) . EOL .
'O=' . print_r ( $O , true ) . EOL
);
}
2009-07-08 14:58:52 +00:00
$url = getKbis ( $siren );
$firephp -> info ( 'getKbis' );
$firephp -> log ( $url , 'url' );
if ( $url === FALSE ){
2009-07-10 07:29:54 +00:00
mail ( 'ylenaour@scores-decisions.com' , " Commande de KBIS pour $login ( $siren ) : Erreur " ,
'REQUEST=' . EOL . print_r ( $_REQUEST , true ) . 'EOL' .
'SERVER=' . EOL . print_r ( $_SERVER , true ) . 'EOL' .
'SESSION=' . EOL . print_r ( $_SESSION , true ) . 'EOL' .
'ENV=' . EOL . print_r ( $_ENV , true ) . 'EOL' .
'tabInfo=' . print_r ( $tabInfo , true ) . EOL .
'O=' . print_r ( $O , true ) . EOL
);
2009-07-08 14:58:52 +00:00
print 'Une erreur est survenue. Merci de r<> ssayez en cliquant <a href="/?page=kbis2&siret=' . $siren . '">ici</a>' ;
} else {
print $url ;
}
}
2009-07-08 13:24:01 +00:00
//Le fichier existe sur l'extranet, etc....
if ( file_exists ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' )
&& date ( 'Ymd' , filemtime ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' )) == date ( 'Ymd' )
&& filesize ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' ) > 500
){
2009-07-10 07:29:54 +00:00
mail ( 'ylenaour@scores-decisions.com' , " Commande de KBIS pour $login ( $siren ) " ,
2009-07-08 13:24:01 +00:00
'REQUEST=' . EOL . print_r ( $_REQUEST , true ) . 'EOL' .
'SERVER=' . EOL . print_r ( $_SERVER , true ) . 'EOL' .
'SESSION=' . EOL . print_r ( $_SESSION , true ) . 'EOL' .
'ENV=' . EOL . print_r ( $_ENV , true ) . 'EOL' .
'tabInfo=' . print_r ( $tabInfo , true ) . EOL .
'O=' . print_r ( $O , true ) . EOL
2009-07-10 07:29:54 +00:00
);
2009-07-08 13:24:01 +00:00
$firephp -> info ( 'Check du fichier sur le serveur local' );
print '<u><a title="Cliquez ici pour visualiser le kbis" target="_blank" href="/?page=actes&siret=' . $siret . '&ref=kbis">Visualiser le Kbis <img src="/img/icone_pdf.gif"></a></u>' ;
//Le fichier n'existe pas sur l'extranet, etc...
} else {
$firephp -> info ( 'D<> marage recup<75> ration du fichier' );
//On check si le fichier est pr<70> sent sur l'url
2009-07-08 14:58:52 +00:00
$url = $_REQUEST [ 'url' ];
$page = getUrl ( $url , '' , '' , '' , false );
//Fichier non disponible
if ( $page [ 'code' ] == 408 || $page [ 'code' ] == 400 ){
return 'FALSE' ;
//Ecriture du fichier sur le serveur en local
2009-07-08 13:24:01 +00:00
} else {
2009-07-08 14:58:52 +00:00
$body = $page [ 'body' ];
$fp = fopen ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' , 'w' );
fwrite ( $fp , $body );
fclose ( $fp );
return 'FALSE' ;
2009-07-08 13:24:01 +00:00
}
}
exit ;
}
2009-07-07 14:50:59 +00:00
if ( ! $_SESSION [ 'connected' ])
echo ( 'Vous devez <20> tre connect<63> afin de pouvoir utiliser cette fonctionnalit<69> ' );
elseif ( ! preg_match ( '/KBIS/i' , $_SESSION [ 'tabInfo' ][ 'droits' ]))
echo ( 'Vous n\'avez pas les droits n<> cessaires pour utiliser cette fonctionnalit<69> ' );
else {
2009-07-08 13:24:01 +00:00
require_once ( FWK_PATH . '/common/dates.php' );
require_once ( FWK_PATH . '/common/curl.php' );
2009-07-07 14:50:59 +00:00
2009-07-08 13:24:01 +00:00
isset ( $_REQUEST [ 'siret' ]) ? $siret = $_REQUEST [ 'siret' ] : $siret = '' ;
2009-07-10 07:29:54 +00:00
isset ( $_REQUEST [ 'start' ]) ? $start = $_REQUEST [ 'start' ] : $start = 1 ;
2009-07-08 13:24:01 +00:00
$siren = substr ( $siret , 0 , 9 );
$login = strtolower ( $_SESSION [ 'tabInfo' ][ 'login' ]);
2009-07-07 14:50:59 +00:00
$tabInfo = $_SESSION [ 'tabInfo' ];
2009-07-08 13:24:01 +00:00
$raisonSociale = $tabInfo [ 'entrep' ][ 'raisonSociale' ];
$cj = $tabInfo [ 'entrep' ][ 'fj' ];
$dep = substr ( '' . $tabInfo [ 'entrep' ][ 'codeCommune' ], 0 , 2 );
2009-07-07 14:50:59 +00:00
$errCJ = $errDep = $errNum = false ;
if ( ( $cj >= 91 && $cj <= 93 ) || ( $cj >= 9110 && $cj <= 9300 ) )
$errCJ = true ;
elseif ( $dep == '00' || $dep == '57' || $dep == '67' || $dep == '68' || $dep == '97' || $dep == '98' )
$errDep = true ;
else
{
2009-07-08 13:24:01 +00:00
$type = 'AC' ;
$fichier = $type . '-' . $siren . '.xml' ;
$perisable = true ;
2009-07-07 14:50:59 +00:00
if ( ! file_exists ( PATH_DATA . '/infogreffe/xml/' . $fichier ) // Le fichier n'existe pas en cache
|| ( file_exists ( PATH_DATA . '/infogreffe/xml/' . $fichier ) && $perisable && date ( 'Ymd' , filemtime ( PATH_DATA . '/infogreffe/xml/' . $fichier )) <> date ( 'Ymd' ) ) // Le fichier existe en cache mais est p<> risable (liste)
|| ( file_exists ( PATH_DATA . '/infogreffe/xml/' . $fichier ) && ! $perisable && date ( 'Ymd' , filemtime ( PATH_DATA . '/infogreffe/xml/' . $fichier )) <> date ( 'Ymd' ) && filesize ( PATH_DATA . '/infogreffe/xml/' . $fichier ) <= 200 ) // Le fichier existe en cache, n'est pas p<> risable (acte) mais contient un message d'erreur
){
require_once 'infogreffe/kbis.php' ;
2009-07-08 13:24:01 +00:00
$xml = infogreffeProduits ( $siren , $type );
2009-07-07 14:50:59 +00:00
/** Enregistrement du fichier XML en provenance des greffes **/
if ( strlen ( $xml ) != 0 ) {
$fp =@ fopen ( PATH_DATA . '/infogreffe/xml/' . $fichier , 'w' );
@ fwrite ( $fp , $xml );
@ fclose ( $fp );
}
} else {
/** Lecture du fichier XML en provenance des greffes **/
$xml = file_get_contents ( PATH_DATA . '/infogreffe/xml/' . $fichier );
}
/** Affichage des erreurs Infogreffe **/
if ( strlen ( $xml ) < 200 ) {
$tmp = explode ( '-' , $xml );
$errNum = $tmp [ 0 ] * 1 ;
$errMsg = $xml ;
if ( $errNum == 0 ) $errNum =- 1 ;
elseif ( $errNum == 45 || $errNum == 14 ) $errNum = false ;
}
}
if ( $errCJ || $errDep || $errNum ) {
2009-07-08 13:24:01 +00:00
?>
< table width = " 580 " border = " 0 " align = " left " bgcolor = " #FFFFFF " >
< tr >
< td colspan = " 3 " align = " center " >< img src = " ./img/rub_pieces.png " width = " 577 " height = " 36 " /></ td >
</ tr >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 200 " class = " StyleInfoLib " > Num & eacute ; ro identifiant Siren </ td >
< td width = " 350 " class = " StyleInfoData " >< ? = substr ( $siren , 0 , 3 ) . ' ' . substr ( $siren , 3 , 3 ) . ' ' . substr ( $siren , 6 , 3 ) ?> </td>
</ tr >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 200 " class = " StyleInfoLib " > Raison Sociale </ td >
< td width = " 350 " class = " StyleInfoData " >< ? = $raisonSociale ?> </td>
</ tr >
< tr >
< td colspan = " 3 " >& nbsp ; </ td >
</ tr >
< tr >
< td colspan = " 3 " >< img src = " ./img/srub_actes.png " width = " 576 " height = " 27 " /></ td >
</ tr >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 550 " colspan = " 2 " class = " StyleInfoData " >
< h3 >
< ?
2009-07-07 14:50:59 +00:00
if ( $errCJ ) echo 'K-Bis inexistant pour cette forme juridique.' ;
elseif ( $errDep ) echo 'K-Bis inexistant dans ce d<> partement.' ;
else echo 'Retour Greffe : ' . $errMsg . '<!--' . $req . '-->' ;
2009-07-08 13:24:01 +00:00
?>
</ h3 >
</ td >
</ tr >
2009-07-07 14:50:59 +00:00
< ?
} else {
2009-07-08 13:24:01 +00:00
?>
< script src = " ./js/jqueryprogressbar.js " type = " text/javascript " ></ script >
< script type = " text/javascript " >
$ ( document ) . ready ( function (){
function checkKbis ( start )
{
2009-07-10 07:29:54 +00:00
if ( start >= 1 ){
$ . post ( 'pages/kbis2.php' , { ajax : 'true' , start : start , siret : '<?=$siren?>' },
2009-07-09 06:48:47 +00:00
function ( data , textStatus ) { url = data ; }
2009-07-08 13:24:01 +00:00
);
} else {
2009-07-10 07:29:54 +00:00
$ . post ( 'pages/kbis2.php' , { ajax : 'true' , start : 0 , url : url , siret : '<?=$siren?>' },
2009-07-09 06:48:47 +00:00
function ( data , textStatus ) { if ( data != '' && data != 'FALSE' ){ updateInfo ( data ); } }
2009-07-08 13:24:01 +00:00
);
}
2009-07-07 14:50:59 +00:00
}
2009-07-08 13:24:01 +00:00
function update ()
{
$ ( " #progressbar " ) . reportprogress ( ++ pct );
if ( pct == 100 ){
2009-07-10 07:29:54 +00:00
updateInfo ( 'Le temps maximum d\'attente a <20> t<EFBFBD> atteint. Merci de r<> ssayez en cliquant <a href="/?page=kbis2&siret=<?=$siren?>&start=<?$start++?>">ici</a>' );
2009-07-08 13:24:01 +00:00
pct = 0 ;
}
if ( Math . floor ( pct / checkInterval ) != prec ){
prec = Math . floor ( pct / checkInterval );
checkKbis ( false );
}
}
2009-07-07 14:50:59 +00:00
2009-07-08 13:24:01 +00:00
function updateInfo ( html ){
$ ( " #result " ) . html ( html );
clearInterval ( holdTheInterval );
}
2009-07-08 14:58:52 +00:00
2009-07-08 13:24:01 +00:00
var pct = 0 ;
var prec = 0 ;
2009-07-08 14:58:52 +00:00
var checkInterval = 5 ;
2009-07-08 13:24:01 +00:00
var url = '' ;
2009-07-10 07:29:54 +00:00
checkKbis ( < ? = $start ?> );
var holdTheInterval = setInterval ( update , 900 );
2009-07-08 13:24:01 +00:00
$ ( " #progressbar " ) . reportprogress ( 0 );
});
</ script >
2009-07-07 14:50:59 +00:00
< table width = " 580 " border = " 0 " align = " left " bgcolor = " #FFFFFF " >
< ? php
if ( $message <> '' ) {
?>
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 550 " colspan = " 2 " class = " StyleInfoData " >< h3 >< ? = $message ; ?> </h3></td>
</ tr >
< ? php
}
?>
< tr >
< td colspan = " 3 " align = " center " >< img src = " ./img/rub_pieces.png " width = " 577 " height = " 36 " /></ td >
</ tr >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 200 " class = " StyleInfoLib " > Num & eacute ; ro identifiant Siren </ td >
< td width = " 350 " class = " StyleInfoData " >< ? = substr ( $siren , 0 , 3 ) . ' ' . substr ( $siren , 3 , 3 ) . ' ' . substr ( $siren , 6 , 3 ) ?> </td>
</ tr >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 200 " class = " StyleInfoLib " > Raison Sociale </ td >
< td width = " 350 " class = " StyleInfoData " >< ? = $raisonSociale ?> </td>
</ tr >
< tr >
< td colspan = " 3 " >& nbsp ; </ td >
</ tr >
< tr >
< td colspan = " 3 " >< img src = " ./img/srub_actes.png " width = " 576 " height = " 27 " /></ td >
</ tr >
< tr >
< td colspan = " 3 " align = " center " >
2009-07-08 13:24:01 +00:00
< div id = " result " >
< div id = " progressbar " ></ div >
</ div >
</ td >
2009-07-07 14:50:59 +00:00
</ tr >
< ?
}
?>
</ table >
< ?
}
?>