From e08564bad54f1cca4b80ccd7277b3092e7b7adae Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Wed, 5 Mar 2014 15:11:14 +0000 Subject: [PATCH] Correction Bilan association --- application/controllers/PiecesController.php | 41 ++++++++++++++----- .../scripts/pieces/associationbilan.phtml | 5 +++ 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 application/views/default/scripts/pieces/associationbilan.phtml diff --git a/application/controllers/PiecesController.php b/application/controllers/PiecesController.php index 9fd5d476e..0b269eb62 100644 --- a/application/controllers/PiecesController.php +++ b/application/controllers/PiecesController.php @@ -19,7 +19,6 @@ class PiecesController extends Zend_Controller_Action public function init() { require_once 'Scores/WsScores.php'; - require_once 'Infogreffe/Infogreffe.php'; $request = $this->getRequest(); $this->siret = $request->getParam('siret'); @@ -937,8 +936,8 @@ class PiecesController extends Zend_Controller_Action if ( $user->checkPerm('actes') ) { if ( !empty($item->File) ) { $href = $this->view->url(array( - 'controller'=>'telechargement', - 'action'=>'bilan', + 'controller'=>'pieces', + 'action'=>'associationbilan', 'siren'=> $siren, 'dateCloture'=> $item->DateCloture, 'reference'=> $item->File, @@ -984,23 +983,45 @@ class PiecesController extends Zend_Controller_Action { //Désactivation affichage $this->_helper->layout()->disableLayout(); - $this->_helper->viewRenderer->setNoRender(true); $request = $this->getRequest(); $siren = $request->getParam('siren'); - $diffusion = $request->getParam('diffusion'); + $diffusion = 'T'; $dateCloture = $request->getParam('dateCloture'); $reference = $request->getParam('reference'); + $type = 'association'; //Récupération du l'URL $ws = new WsScores(); - $url = $ws->getPiecesBilan($siren, $diffusion, $dateCloture, $reference); + $url = $ws->getPiecesBilan($siren, $type, $diffusion, $dateCloture, $reference); + + if ( !empty($url) ) { + + try { + $client = new Zend_Http_Client($url); + $client->setStream(); + $stream = $client->request('GET'); + if ( $stream->isSuccessful() && substr($stream->getBody(),0,4)=='%PDF' ) { + $c = Zend_Registry::get('config'); + $file = 'bilan-'.$siren.'-'.$type.'-'.$dateCloture.'.pdf'; + if (copy($stream->getStreamName(), $c->profil->path->files . '/' . $file)) { + $this->view->assign('url', $this->view->url(array( + 'controller' => 'fichier', + 'action' => 'greffe', + ), null, true).'/'.$file); + } else { + $this->view->assign('msg', "Impossible de distribuer le fichier."); + } + } else { + $this->view->assign('msg', "Erreur lors du téléchargement du fichier."); + } + } catch (Zend_Http_Client_Exception $e) { + Zend_Registry::get('firebug')->info('HTTP Exception : '.$e->getMessage()); + $this->view->assign('msg', "Erreur lors du téléchargement du fichier."); + } - //Téléchargement du fichier - if( $url !== false) { - echo '
Cliquez ici pour ouvrir le fichier'; } else { - echo '
Fichier indisponible !'; + $this->view->assign('msg', "Fichier indisponible !"); } } diff --git a/application/views/default/scripts/pieces/associationbilan.phtml b/application/views/default/scripts/pieces/associationbilan.phtml new file mode 100644 index 000000000..74eeaaa92 --- /dev/null +++ b/application/views/default/scripts/pieces/associationbilan.phtml @@ -0,0 +1,5 @@ +msg) {?> + msg?> + + Télécharger le fichier + \ No newline at end of file