367 lines
11 KiB
PHP
367 lines
11 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Configuration of provider
|
||
*/
|
||
require_once realpath(dirname(__FILE__)).'/Config.php';
|
||
|
||
/**
|
||
* Infogreffe Provider
|
||
*
|
||
*
|
||
*/
|
||
class Infogreffe extends Infogreffe_Config
|
||
{
|
||
|
||
/**
|
||
* Where pdf file are store
|
||
* @var string
|
||
*/
|
||
protected $dataPath = '';
|
||
|
||
/**
|
||
* SIREN
|
||
* @var string
|
||
*/
|
||
protected $siren;
|
||
|
||
/**
|
||
* Internal Command ID
|
||
* @var string
|
||
*/
|
||
protected $idCommande;
|
||
|
||
/**
|
||
* KB = Kbis, PN = privilèges et nantissements, BI = Bilan complet, BS = bilan saisi,
|
||
* ST = Dernier Statut à jour, AC = Acte, SD = Surveillance Demande et Accusé,
|
||
* SR = Surveillance Révélation, SP = Surveillance Portefeuille, FA = Recherche PCL,
|
||
* FI = Inventaire, FJ = Jugement, FO = Ordonnance, FD = Dépôt divers,
|
||
* LE = Liste Etablissements
|
||
* @var string
|
||
*/
|
||
protected $typeCommande;
|
||
|
||
/**
|
||
* Mode de diffusion : C = Courrier, T = Téléchargement, M = Mail, XL = XML
|
||
* @var string
|
||
*/
|
||
protected $vecteur;
|
||
|
||
/**
|
||
* String which contain reference
|
||
* @var string
|
||
*/
|
||
protected $option;
|
||
|
||
/**
|
||
* Error number
|
||
* @var int
|
||
*/
|
||
protected $errorNum;
|
||
|
||
/**
|
||
* Error message
|
||
* @var string
|
||
*/
|
||
protected $errorMsg;
|
||
|
||
|
||
public function __construct()
|
||
{
|
||
/**
|
||
* Define path where PDF file are store
|
||
*/
|
||
$this->dataPath = '';
|
||
|
||
/**
|
||
* Define path where XML cache file are store
|
||
*/
|
||
$this->cachePath = '';
|
||
|
||
}
|
||
|
||
/**
|
||
* Send XML Request
|
||
* We have some problem to use SOAP so we use CURL
|
||
* @return string XML Response
|
||
*/
|
||
protected function getProduitsXML()
|
||
{
|
||
$xmlStr = '';
|
||
$env = 'PRD';
|
||
|
||
//Construct the request
|
||
$xml = new SimpleXMLElement('<demande></demande>');
|
||
$emetteur = $xml->addChild('emetteur');
|
||
$emetteur->addChild('code_abonne', $this->config[$env]['USER']);
|
||
$emetteur->addChild('mot_passe', $this->config[$env]['PASS']);
|
||
|
||
//Set Command ID
|
||
$emetteur->addChild('reference_client', 'G'.$this->idCommande);
|
||
$code_requete = $emetteur->addChild('code_requete');
|
||
$code_requete->addChild('type_profil', 'A');
|
||
$code_requete->addChild('origine_emetteur', 'IC');
|
||
|
||
// C = Commande de documents
|
||
$code_requete->addChild('nature_requete', 'C');
|
||
|
||
$code_requete->addChild('type_document', $this->typeCommande);
|
||
$code_requete->addChild('type_requete', 'S'); // S = Simple
|
||
|
||
$mode_diffusion = $code_requete->addChild('mode_diffusion');
|
||
// Mode de diffusion : C = Courrier, T = Téléchargement, M = Mail, XL = XML
|
||
if ($this->vecteur=='XL' && $this->option=='')
|
||
{
|
||
//On ajoute tout les types de diffusions pour $vecteur = XL
|
||
$mode_diffusion->addChild('mode')->addAttribute('type', 'C');
|
||
$mode_diffusion->addChild('mode')->addAttribute('type', 'T');
|
||
}
|
||
$mode_diffusion->addChild('mode')->addAttribute('type', $this->vecteur);
|
||
|
||
$code_requete->addChild('media', 'WS');
|
||
|
||
$commande = $xml->addChild('commande');
|
||
$commande->addChild('num_siren', $this->siren);
|
||
|
||
// Commande de documents : bilan saisie ou bilan complet
|
||
if ( ($this->typeCommande=='BS' || $this->typeCommande=='BI') && $this->option!='' )
|
||
{
|
||
|
||
/* Format de la variable option pour la commande de type BI ou BS
|
||
* 0 => millesime
|
||
* 1 => date_cloture
|
||
* 2 => greffe
|
||
* 3 => dossier_millesime
|
||
* 4 => dossier_statut
|
||
* 5 => dossier_chrono
|
||
* 6 => num_depot
|
||
*/
|
||
$ref = explode('-', $this->option);
|
||
$commande->addChild('greffe',$ref[2]);
|
||
$commande->addChild('dossier_millesime',$ref[3]);
|
||
$commande->addChild('dossier_statut',$ref[4]);
|
||
$commande->addChild('dossier_chrono',$ref[5]);
|
||
$commande->addChild('num_depot',$ref[6]);
|
||
$commande->addChild('date_cloture', WDate::dateT('Ymd','d/m/Y', $ref[1]));
|
||
}
|
||
// Commande de documents : actes
|
||
elseif ( $this->typeCommande=='AC' && !empty($this->option) )
|
||
{
|
||
/* Format de la variable option pour commande type AC
|
||
* 0 => type_acte
|
||
* 1 => date de référence
|
||
* 2 => greffe
|
||
* 3 => dossier_millesime
|
||
* 4 => dossier_statut
|
||
* 5 => dossier_chrono
|
||
* 6 => num_depot
|
||
* 7 => num_acte
|
||
*/
|
||
$ref = explode('-', $this->option);
|
||
$num_actes = explode('|', $ref[7]);
|
||
$commande->addChild('greffe',$ref[2]);
|
||
$commande->addChild('dossier_millesime', $ref[3]);
|
||
$commande->addChild('dossier_statut', $ref[4]);
|
||
$commande->addChild('dossier_chrono', $ref[5]);
|
||
$commande->addChild('num_depot', $ref[6]);
|
||
$liste_actes = $commande->addChild('liste_actes');
|
||
if(is_array($num_actes) && count($num_actes)>1)
|
||
{
|
||
foreach($num_actes as $num_acte)
|
||
{
|
||
$liste_actes->addChild('acte')->addAttribute('num', $num_acte);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
$liste_actes->addChild('acte')->addAttribute('num', $ref[7]);
|
||
$fichierOption = $this->option;
|
||
}
|
||
}
|
||
|
||
$xmlStr = str_replace('<?xml version="1.0"?>', '', $xml->asXML());
|
||
|
||
//Be sure it's in UTF-8
|
||
$req = utf8_encode($xml);
|
||
|
||
//Create XML request
|
||
$post = '<?xml version="1.0" encoding="UTF-8"?>'.
|
||
'<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" '.
|
||
'xmlns:ns1="https://webservices.infogreffe.fr/" '.
|
||
'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '.
|
||
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '.
|
||
'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" '.
|
||
'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">'.
|
||
'<SOAP-ENV:Body>'.
|
||
'<ns1:getProduitsWebServicesXML>'.
|
||
'<param0 xsi:type="xsd:string">'.$req.'</param0>'.
|
||
'</ns1:getProduitsWebServicesXML>'.
|
||
'</SOAP-ENV:Body>'.
|
||
'</SOAP-ENV:Envelope>';
|
||
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $this->url);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($ch, CURLOPT_COOKIEFILE,TRUE);
|
||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
|
||
$response = curl_exec($ch);
|
||
|
||
//Remove SOAP part of XML
|
||
$response = str_replace("<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' xmlns:SOAP-ENC='http://schemas.xmlsoap.org/soap/encoding/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema'><SOAP-ENV:Body><ns0:getProduitsWebServicesXMLResponse xmlns:ns0='urn:local' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><return xsi:type='xsd:string'>", '', $response);
|
||
$response = str_replace('</return></ns0:getProduitsWebServicesXMLResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>','', $response);
|
||
|
||
return $response;
|
||
}
|
||
|
||
protected function log(){}
|
||
|
||
/**
|
||
* Detect error
|
||
* @param string $xml
|
||
* @throws Exception
|
||
*/
|
||
protected function error($xml)
|
||
{
|
||
if (!empty($xml))
|
||
{
|
||
$doc = new DOMDocument();
|
||
$load = $doc->loadXML($xml, LIBXML_NOERROR | LIBXML_NOWARNING);
|
||
if (!$load) {
|
||
$tmp = explode('-', $xml);
|
||
$errNum = intval($tmp[0]);
|
||
$errMsg = $tmp[1];
|
||
if( $errNum == '5' ){
|
||
$errMsg = 'Service partenaire indisponible.';
|
||
}
|
||
throw new Exception($errNum . '-' . $errMsg, 'ERR');
|
||
}
|
||
}
|
||
else
|
||
{
|
||
throw new Exception('Fichier vide', 'ERR');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Return true if the file modification time is in the period of caching
|
||
* @param string $file
|
||
* Path of file
|
||
*/
|
||
protected function cachetimeover($file)
|
||
{
|
||
$timeover = false;
|
||
$dateFile = filemtime($file);
|
||
$now = mktime(date('G'), date('i'), date('s'), date('m') , date('d'), date('Y'));
|
||
$maxTime = mktime(date('G',$dateFile)+$this->cacheFiletime, date('i',$dateFile), date('s',$dateFile), date("m",$dateFile), date("d",$dateFile), date("Y",$dateFile));
|
||
if($now>$maxTime) $timeover = true;
|
||
return $timeover;
|
||
}
|
||
|
||
public function download(){}
|
||
|
||
public function getStatut($siren, $typeCommande = '', $ref = '', $idCommande = 0)
|
||
{
|
||
$this->typeCommande = 'ST';
|
||
$this->vecteur = 'C';
|
||
|
||
$reponse = $this->getProduitsXML();
|
||
|
||
//Gestion du retour infogreffe
|
||
if($this->erreur($xmlReponse))
|
||
{
|
||
$error = $this->erreurMsg($xmlReponse);
|
||
}
|
||
//@todo result non définie
|
||
return array('error' => $error , 'result' => $result );
|
||
|
||
|
||
}
|
||
|
||
/**
|
||
* Retourne la liste des bilans
|
||
* @param string $siren
|
||
* @return array
|
||
*/
|
||
public function getBilans($siren)
|
||
{
|
||
$this->siren = $siren;
|
||
$this->vecteur = 'XL';
|
||
$this->typeCommande = 'BI';
|
||
|
||
$cacheFile = $this->cachePath.'/'.$this->typeCommande.'-'.$siren.'.xml';
|
||
|
||
//Get cache information
|
||
if (file_exists($cacheFile) && $this->cachetimeover($cacheFile) )
|
||
{
|
||
$xml = file_get_contents($cacheFile);
|
||
}
|
||
//Make the request
|
||
else
|
||
{
|
||
$xml = $this->getProduitsXML();
|
||
$this->error($xml);
|
||
|
||
//Create file for the cache
|
||
file_put_contents($cacheFile, $xml);
|
||
}
|
||
|
||
//Parse XML to make tab
|
||
$doc = new DOMDocument();
|
||
$doc->loadXML($xml);
|
||
$liste_bilan_complet = $doc->getElementsByTagName('liste_bilan_complet')->item(0);
|
||
$bilan_complet = $liste_bilan_complet->getElementsByTagName('bilan_complet');
|
||
|
||
$bilans = array();
|
||
if (count($bilan_complet)>0)
|
||
{
|
||
foreach($bilan_complet as $element)
|
||
{
|
||
$bilan = array();
|
||
$num_gest = $element->getElementsByTagName('num_gest')->item(0);
|
||
$bilan['greffe'] = $num_gest->getElementsByTagName('greffe')->item(0)->nodeValue;
|
||
$bilan['dossier_millesime'] = $num_gest->getElementsByTagName('dossier_millesime')->item(0)->nodeValue;
|
||
$bilan['dossier_statut'] = $num_gest->getElementsByTagName('dossier_statut')->item(0)->nodeValue;
|
||
$bilan['dossier_chrono'] = $num_gest->getElementsByTagName('dossier_chrono')->item(0)->nodeValue;
|
||
$bilan['num_siren'] = $element->getElementsByTagName('num_siren')->item(0)->nodeValue;
|
||
$bilan['date_cloture'] = $element->getElementsByTagName('date_cloture')->item(0)->nodeValue;
|
||
$bilan['date_cloture_iso'] = $element->getElementsByTagName('date_cloture_iso')->item(0)->nodeValue;
|
||
$bilan['millesime'] = $element->getElementsByTagName('millesime')->item(0)->nodeValue;
|
||
$bilan['num_depot'] = $element->getElementsByTagName('num_depot')->item(0)->nodeValue;
|
||
$bilan['type_comptes'] = $element->getElementsByTagName('type_comptes')->item(0)->nodeValue;
|
||
$mode_diffusion = $element->getElementsByTagName('mode_diffusion')->item(0)->getElementsByTagName('mode');
|
||
foreach($mode_diffusion as $mode)
|
||
{
|
||
$bilan['mode_diffusion'][] = $mode->getAttribute('type');
|
||
}
|
||
|
||
//Génération de l'index pour le tri
|
||
$date = $bilan['date_cloture_iso'];
|
||
if(!empty($date))
|
||
{
|
||
$datef = substr($date,0,4).substr($date,5,2).substr($date,8,2);
|
||
//Affectation liste générale avec un index permettant le tri
|
||
$bilans[$datef] = $bilan;
|
||
}
|
||
}
|
||
}
|
||
krsort($bilans);
|
||
|
||
return $bilans;
|
||
}
|
||
|
||
public function getBilan()
|
||
{
|
||
//Retourner la référence de commande interne, chez infogreffe
|
||
}
|
||
|
||
|
||
public function getActes(){}
|
||
|
||
public function getActe()
|
||
{
|
||
//Retourner la référence de commande interne, chez infogreffe
|
||
}
|
||
|
||
} |