From 94cf63e5a3b440cf782696d7579788cd6a01bcbc Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Fri, 18 Oct 2013 09:55:31 +0000 Subject: [PATCH] Session --- application/controllers/ReportController.php | 106 ++++++++++++++++-- application/views/scripts/report/cmd.phtml | 22 ++-- .../views/scripts/report/deliver.phtml | 2 +- application/views/scripts/report/index.phtml | 56 ++++++++- 4 files changed, 160 insertions(+), 26 deletions(-) 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 @@
siren && $this->CmdID ) {?>
msg?>
+

* Champs obligatoires

+
- + form->email->hasErrors()) {?>
@@ -38,7 +40,7 @@
- + form->rs->hasErrors()) {?>
@@ -50,7 +52,7 @@
- + form->nom->hasErrors()) {?>
@@ -62,7 +64,7 @@
- + form->prenom->hasErrors()) {?>
@@ -74,7 +76,7 @@
- + form->adresse->hasErrors()) {?>
@@ -86,7 +88,7 @@
- + form->cp->hasErrors()) {?>
@@ -98,7 +100,7 @@
- + form->ville->hasErrors()) {?>
@@ -110,7 +112,7 @@
- + form->tel->hasErrors()) {?>
@@ -122,7 +124,7 @@
- + form->mobile->hasErrors()) {?>
diff --git a/application/views/scripts/report/deliver.phtml b/application/views/scripts/report/deliver.phtml index 024480b..7837b11 100644 --- a/application/views/scripts/report/deliver.phtml +++ b/application/views/scripts/report/deliver.phtml @@ -14,7 +14,7 @@
diff --git a/application/views/scripts/report/index.phtml b/application/views/scripts/report/index.phtml index 436edae..dc7d2a4 100644 --- a/application/views/scripts/report/index.phtml +++ b/application/views/scripts/report/index.phtml @@ -14,7 +14,7 @@
SirenExiste === false ) {?> @@ -23,10 +23,58 @@ -
Siren : Siren?>
-
Raison Sociale : RaisonSociale?>
+
+
Siren :
+
Siren?>
+
Raison Sociale :
+
RaisonSociale?>
+
Adresse :
+
AdresseL1?>
+
+
AdresseL2?>
+
- +
Liste des informations disponibles
+
    +
  • + Inclus + Identité complète +
  • + +
  • + Inclus + Dirigeants +
  • + +
  • + NbLiens?> + Liens inter-entreprises +
  • + +
  • + NbAnnonces?> + Annonces légales +
  • + +
  • + NbBilans?> + Bilans, ratios et SIG +
  • + +
  • + Inclus + Analyse financière et les commentaires +
  • + +
  • + Inclus + Indiscore (scoring financier) et encours conseillé +
  • + +
+ + +