diff --git a/application/controllers/ReportController.php b/application/controllers/ReportController.php index bfa565e..1516908 100644 --- a/application/controllers/ReportController.php +++ b/application/controllers/ReportController.php @@ -16,6 +16,11 @@ class ReportController extends Zend_Controller_Action { $this->_helper->layout()->disableLayout(); + //Open session to backup the state of the process + $cmdState = 0; + $session = new Zend_Session_Namespace('Cmd'); + $session->state = $cmdState; + $request = $this->getRequest(); //Define title @@ -31,14 +36,42 @@ class ReportController extends Zend_Controller_Action $ws = new WsScores('mricois', 'ju2loh6o'); $response = $ws->getIdentiteLight($siren); if ($response !== false) { + + //Identite $this->view->Siren = $response->Siren; $this->view->RaisonSociale = $response->Nom; + $this->view->AdresseL1 = $response->Adresse; + $this->view->AdresseL2 = $response->CP . ' ' . $response->Ville; $this->view->SirenExiste = true; $this->view->ButtonUrl = $this->view->url(array( 'controller'=>'report', 'action'=>'cmd', 'siren'=>$response->Siren )); + + //Nombre + $response = $ws->getLiens($siren); + if ( $response !== false ) { + $this->view->NbLiens = count($response->actionnaires->item) + + count($response->participations->item) + + count($response->directions->item); + } + + $response = $ws->getAnnoncesNum($siren); + if ( $response !== false ) { + foreach ( $response->item as $nb) { + if ( $nb->type == 'bodacc' ) { + $this->view->NbAnnonces = $nb->num; + break; + } + } + } + + $response = $ws->getListeBilans($siren); + if ( $response !== false ) { + $this->view->NbBilans = $response->nbReponses; + } + } } @@ -55,10 +88,29 @@ class ReportController extends Zend_Controller_Action $siren = $request->getParam('siren'); + $url = $this->view->url(array( + 'controller' => 'report', + 'action' => 'index', + 'siren' => $siren, + )); + //Affichage du formulaires $form = new Application_Form_Command(); if ( $request->isPost() ) { + //Write the state to the session + $cmdState = 2; + if ( Zend_Session::namespaceIsset('Cmd') ) { + $session = new Zend_Session_Namespace('Cmd'); + if ( $session->state > $cmdState ) { + $this->redirect($url); + } else { + $session->state = $cmdState; + } + } else { + $this->redirect($url); + } + $values = $request->getPost(); $form->populate($values); @@ -79,26 +131,44 @@ class ReportController extends Zend_Controller_Action $this->view->msg = "Impossible de passer la commande."; } } + } else { - if (intval($siren)>100) { - //Get report - $report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o'); - $html = $report->getContent(); + //Write the state to the session + $cmdState = 1; + $session = new Zend_Session_Namespace('Cmd'); + if ( $session->state > $cmdState ) { + $this->redirect($url); + } else { + $session->state = $cmdState; + } - if ( $html !== false ) { + if ( !isset($session->CmdID) || empty($session->CmdID) ) { - $c = Zend_Registry::get('config'); - $pathCmd = $c->profil->path->data; + //Get the report + if (intval($siren)>100) { + $report = new Scores_Partner_Report('indiscore3', $siren, 'mricois', 'ju2loh6o'); + $html = $report->getContent(); - $id = uniqid(); - //Write the file (name with commande id) - if ( file_put_contents($pathCmd . DIRECTORY_SEPARATOR . $id.'.html', $html) ) { + if ( $html !== false ) { - $this->view->CmdID = $id; + $c = Zend_Registry::get('config'); + $pathCmd = $c->profil->path->data; + $id = uniqid(); + //Write the file (name with commande id) + if ( file_put_contents($pathCmd . DIRECTORY_SEPARATOR . $id.'.html', $html) ) { + + $session->CmdID = $this->view->CmdID = $id; + + } } } + + } else { + + $this->view->CmdID = $session->CmdID; + } } @@ -121,6 +191,20 @@ class ReportController extends Zend_Controller_Action //Commande ID $cmdId = $request->getParam('id'); + //Write the state to the session + $cmdState = 3; + if ( Zend_Session::namespaceIsset('Cmd') ) { + $session = new Zend_Session_Namespace('Cmd'); + if ( $session->state > $cmdState || $session->CmdID != $cmdId ) { + $this->redirect($url); + } else { + $session->state = $cmdState; + } + } else { + $this->redirect($url); + } + + //Est ce que la commande existe $commandM = new Application_Model_Command(); $where = $commandM->select()->where('cmdId=?', $cmdId); diff --git a/application/views/scripts/report/cmd.phtml b/application/views/scripts/report/cmd.phtml index f4bc50e..afb0c25 100644 --- a/application/views/scripts/report/cmd.phtml +++ b/application/views/scripts/report/cmd.phtml @@ -14,19 +14,21 @@
* Champs obligatoires
+