2009-12-04 17:17:09 +00:00
< ? php
2009-07-08 13:24:01 +00:00
isset ( $_REQUEST [ 'ajax' ]) ? $ajax = TRUE : $ajax = FALSE ;
2009-11-06 16:57:54 +00:00
if ( $ajax === TRUE )
{
//require_once realpath(dirname(__FILE__).'/../../config/prepend.php');
2009-07-08 13:24:01 +00:00
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-12-04 17:17:09 +00:00
$firephp -> log ( $siren , 'siren' );
2009-11-06 16:57:54 +00:00
$firephp -> log ( $start , 'start' );
2009-12-04 17:17:09 +00:00
2009-10-16 12:30:19 +00:00
//Commande aupr<70> s du webservice
2009-11-06 16:57:54 +00:00
if ( $start > 0 && $start < 3 )
2009-10-16 12:30:19 +00:00
{
2009-12-04 17:17:09 +00:00
//$url = 'http://tville.scores-decisions.com:8088/data/kbis/kbis-699809174.pdf';
$url = getKbis ( $siren );
2009-07-08 14:58:52 +00:00
$firephp -> info ( 'getKbis' );
$firephp -> log ( $url , 'url' );
2009-11-06 16:57:54 +00:00
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-11-06 16:57:54 +00:00
echo 'Une erreur est survenue. Merci de r<> ssayez en cliquant <a href="/?page=kbis2&siret=' . $siren . '">ici</a>' ;
2009-07-08 14:58:52 +00:00
} else {
2009-12-04 17:17:09 +00:00
echo $url ;
2009-07-08 14:58:52 +00:00
}
}
2009-11-06 16:57:54 +00:00
//Apr<70> s 2 essais, on tente de relancer la commande
elseif ( $start >= 3 )
{
echo 'Une erreur est survenue. Merci de r<> ssayez en cliquant <a href="/?page=kbis2&siret=' . $siren . '">ici</a>' ;
}
2009-12-04 17:17:09 +00:00
elseif ( $start == 0 )
2009-11-06 16:57:54 +00:00
{
2009-12-04 17:17:09 +00:00
$firephp -> info ( 'Test fichier' );
//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' ) > 2000
)
{
$firephp -> info ( 'Check du fichier sur le serveur local' );
echo '<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 ( 'Essai dl fichier' );
//Suppression du fichier si il existe
if ( file_exists ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' )) unlink ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' );
//On check si le fichier est pr<70> sent sur l'url
$url = $_REQUEST [ 'url' ];
$firephp -> log ( $url , 'url' );
$page = getUrl ( $url , '' , '' , '' , false );
//Fichier non disponible
if ( $page [ 'code' ] == 408 || $page [ 'code' ] == 400 ){
echo 'FALSE' ;
//Ecriture du fichier sur le serveur en local
} else {
$body = $page [ 'body' ];
$fp = fopen ( PATH_DATA . '/pdf/kbis-' . $siren . '.pdf' , 'w' );
fwrite ( $fp , $body );
fclose ( $fp );
echo 'FALSE' ;
}
2009-07-08 13:24:01 +00:00
}
}
exit ;
}
2009-08-28 07:26:32 +00:00
//Envoi d'un mail de demande de reception de kbis par mail
if ( isset ( $_REQUEST [ 'mailkbis' ]) && $_REQUEST [ 'mailkbis' ] == 'Ok' )
{
mail ( 'support@scores-decisions.com' , " Demande de kbis par email " ,
'Demande pour recevoir le kbis de siren : ' . $_REQUEST [ 'siren' ] . EOL .
'pour login ' . $_REQUEST [ 'login' ] . '(' . $_REQUEST [ 'mail' ] . ')'
);
$message = 'Votre demande de reception de Kbis par email <20> <20> t<EFBFBD> prise en compte' ;
}
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> ' );
2009-12-10 09:54:47 +00:00
elseif ( ! preg_match ( '/\bKBIS\b/i' , $_SESSION [ 'tabInfo' ][ 'droits' ]))
2009-07-07 14:50:59 +00:00
echo ( 'Vous n\'avez pas les droits n<> cessaires pour utiliser cette fonctionnalit<69> ' );
else {
2009-07-21 07:17:54 +00:00
require_once 'common/dates.php' ;
require_once '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 ;
2009-12-04 17:17:09 +00:00
$firephp -> log ( $siren , 'siren' );
2009-07-07 14:50:59 +00:00
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-12-04 17:17:09 +00:00
$firephp -> log ( $xml , 'infogreffe XML' );
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 ;
}
}
2009-09-10 15:31:37 +00:00
if ( $errCJ || $errDep || $errNum )
{
2009-11-06 16:57:54 +00:00
?>
2009-08-28 07:26:32 +00:00
< div id = " center " >
2009-11-06 16:57:54 +00:00
2009-08-28 07:26:32 +00:00
< h1 > PIECES OFFICIELLES </ h1 >
2009-07-07 14:50:59 +00:00
2009-08-28 07:26:32 +00:00
< table >
< 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 >
</ table >
2009-07-08 14:58:52 +00:00
2009-08-28 07:26:32 +00:00
< h2 > Actes & amp ; Status </ h2 >
< table >
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 550 " colspan = " 2 " class = " StyleInfoData " >
< h3 >
< ?
if ( $errCJ ) echo 'K-Bis inexistant pour cette forme juridique.' ;
2009-10-28 14:19:10 +00:00
elseif ( $errDep ) echo 'K-Bis en ligne indisponible pour ce d<> partement. ' ;
2009-08-28 07:26:32 +00:00
else echo 'Retour Greffe : ' . $errMsg . '<!--' . $req . '-->' ;
?>
</ h3 >
</ td >
</ tr >
2009-10-28 14:19:10 +00:00
< ? php
if ( $errDep )
{
?>
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 550 " colspan = " 2 " class = " StyleInfoData " >
Afin d ' obtenir un extrait K - bis , contactez directement le greffe du tribunal <EFBFBD> comp<EFBFBD> tence commercial
dont vous trouverez les coordonn<EFBFBD> es < a href = " ./?page=competences&idEntreprise=<?= $idEntreprise ?>&siret=<?= $siret ?>&type=tri " > ici </ a >.
</ td >
</ tr >
< ? php
}
?>
2009-08-28 07:26:32 +00:00
</ table >
2009-12-04 17:17:09 +00:00
</ div >
2009-08-28 07:26:32 +00:00
< ?
2009-09-10 15:31:37 +00:00
}
else
{
2009-08-28 07:26:32 +00:00
?>
< script src = " ./js/jqueryprogressbar.js " type = " text/javascript " ></ script >
< div id = " center " >
< h1 > PIECES OFFICIELLES </ h1 >
< table >
2009-07-07 14:50:59 +00:00
< ? php
2009-12-04 17:17:09 +00:00
if ( $message != '' )
{
2009-07-07 14:50:59 +00:00
?>
2009-08-28 07:26:32 +00:00
< tr >
< td width = " 30 " >& nbsp ; </ td >
< td width = " 550 " colspan = " 2 " class = " StyleInfoData " >< h3 >< ? = $message ; ?> </h3></td>
</ tr >
2009-07-07 14:50:59 +00:00
< ? php
}
?>
2009-08-28 07:26:32 +00:00
< 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 >
</ table >
< h2 > Actes & amp ; Status </ h2 >
< table >
< tr >
< td width = " 100 " >& nbsp ; </ td >
< td width = " 380 " >
2009-12-04 17:17:09 +00:00
< ? php
if ( empty ( $message ))
{
?>
2009-08-28 07:26:32 +00:00
< div id = " result " >< div id = " progressbar " ></ div ></ div >
2009-12-04 17:17:09 +00:00
< ? php
}
?>
2009-08-28 07:26:32 +00:00
< span id = " formMail " style = " display:none " >
< form name = " mailkbis " method = " post " action = " ./?page=kbis2&siret=<?= $siret ?> " >
2009-12-04 17:17:09 +00:00
< input type = " hidden " name = " login " value = " <?= $_SESSION['tabInfo'] ['login']?> " />
< input type = " hidden " name = " siren " value = " <?= $siren ?> " />
2009-08-28 07:26:32 +00:00
< label > Votre Email : </ label >
2009-12-04 17:17:09 +00:00
< input type = " text " name = " mail " value = " <?= $_SESSION['tabInfo'] ['email']?> " />
< input type = " submit " name = " mailkbis " value = " Ok " />
2009-08-28 07:26:32 +00:00
</ form >
</ span >
</ td >
< td width = " 100 " >& nbsp ; </ td >
</ tr >
2009-07-07 14:50:59 +00:00
</ table >
2009-08-28 07:26:32 +00:00
</ div >
2009-11-06 16:57:54 +00:00
< script type = " text/javascript " >
$ ( document ) . ready ( function ()
{
$ ( 'input[type=checkbox][name=sendmail]' ) . live ( 'click' , function ()
{
2009-08-28 07:26:32 +00:00
if ( $ ( this ) . attr ( 'checked' ) == true ){
$ ( '#formMail' ) . css ( 'display' , 'block' );
2009-11-06 16:57:54 +00:00
} else {
$ ( '#formMail' ) . css ( 'display' , 'none' );
2009-08-28 07:26:32 +00:00
}
});
2009-11-06 16:57:54 +00:00
< ? php
if ( ! ( isset ( $_REQUEST [ 'mailkbis' ]) && $_REQUEST [ 'mailkbis' ] == 'Ok' ) )
{
?>
2009-08-28 07:26:32 +00:00
var start = < ? = $start ?> ;
var pct = 0 ;
var prec = 0 ;
2009-11-09 08:48:27 +00:00
var checkInterval = 5 ;
2009-08-28 07:26:32 +00:00
var url = '' ;
2009-11-06 16:57:54 +00:00
var message = 'Le temps maximum d"attente a <20> t<EFBFBD> atteint. Merci de r<> ssayez en cliquant <a href="./?page=kbis2&siret=<?=$siren?>&start=<?=$start+1?>">ici</a><br/>ou faire la demande pour recevoir le kbis par mail <input type="checkbox" name="sendmail" value="1"/>' ;
2009-08-28 07:26:32 +00:00
function checkKbis ( start )
{
if ( start >= 1 ){
2009-12-04 17:17:09 +00:00
$ . post ( 'pages/kbis2.php' , { ajax : 'true' , start : start , siret : '<?=$siren?>' },
2009-11-06 16:57:54 +00:00
function ( data , textStatus ) { url = data ; }
2009-08-28 07:26:32 +00:00
);
} else {
2009-12-04 17:17:09 +00:00
$ . post ( 'pages/kbis2.php' , { ajax : 'true' , start : 0 , url : url , siret : '<?=$siren?>' },
2009-08-28 07:26:32 +00:00
function ( data , textStatus ) { if ( data != '' && data != 'FALSE' ){ updateInfo ( data ); } }
);
}
}
function update ()
{
$ ( '#progressbar' ) . reportprogress ( ++ pct );
if ( pct == 100 ){
updateInfo ( message );
pct = 0 ;
}
if ( Math . floor ( pct / checkInterval ) != prec ){
prec = Math . floor ( pct / checkInterval );
checkKbis ( false );
}
}
function updateInfo ( html ){
$ ( '#result' ) . html ( html );
clearInterval ( holdTheInterval );
}
checkKbis ( start );
var holdTheInterval = setInterval ( update , 1200 );
$ ( '#progressbar' ) . reportprogress ( 0 );
2009-12-04 17:17:09 +00:00
< ? php
2009-11-06 16:57:54 +00:00
}
?>
2009-08-28 07:26:32 +00:00
});
</ script >
< ? php
2009-09-10 15:31:37 +00:00
}
2009-07-07 14:50:59 +00:00
}
2009-09-10 15:31:37 +00:00