From a5d000f6d3955b6e4ca2c0080ae24263865edec6 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 17 Oct 2011 09:38:38 +0000 Subject: [PATCH] Ajout code Iris --- .../controllers/IdentiteController.php | 27 ++++++++ .../scripts/geolocalisation/geophoto.phtml | 16 +++++ library/Scores/Iris.php | 61 +++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 library/Scores/Iris.php diff --git a/application/controllers/IdentiteController.php b/application/controllers/IdentiteController.php index 8fe6bf883..d3b51108b 100644 --- a/application/controllers/IdentiteController.php +++ b/application/controllers/IdentiteController.php @@ -684,4 +684,31 @@ class IdentiteController extends Zend_Controller_Action echo $avis->erreurmsg(); } } + + public function irisAction() + { + $this->_helper->layout()->disableLayout(); + $this->_helper->viewRenderer->setNoRender(true); + + $request = $this->getRequest(); + $codeCommune = $request->getParam('code'); + // ==> Start + require_once 'Scores/Iris.php'; + $iris = new Iris($codeCommune); + $body = $iris->get('pdf'); + if($body !== false) { + header("Pragma: public"); + header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); + header("Cache-Control: must-revalidate"); + header("Content-type: application/pdf"); + header("Content-Length: ".strlen($body)); + header('Content-disposition: inline; filename="carte_iris_'.$codeCommune.'.pdf"'); + header("Accept-Ranges: ".strlen($body)); + echo $body; + } else { + echo $iris->erreur(); + } + } + } \ No newline at end of file diff --git a/application/views/default/scripts/geolocalisation/geophoto.phtml b/application/views/default/scripts/geolocalisation/geophoto.phtml index 53812c433..8cc5e8a4e 100644 --- a/application/views/default/scripts/geolocalisation/geophoto.phtml +++ b/application/views/default/scripts/geolocalisation/geophoto.phtml @@ -12,6 +12,22 @@
Code commune / Rivoli :
infos->Dept.' '.$this->infos->codeCommune.' / '.$this->infos->Rivoli; ?> + infos->InfosIris)>0){ + $InfosIris = $this->infos->InfosIris; + $codComIris = str_replace($InfosIris->codIris, '', $InfosIris->codComIris); + ?> +

Iris : + codIris*1 == 0){ + ?> +
Commune non découpée en Iris + +
Code : codIris?> +
Libellé : libIris?> + + + source == 'google'):?>
diff --git a/library/Scores/Iris.php b/library/Scores/Iris.php new file mode 100644 index 000000000..beed7e81c --- /dev/null +++ b/library/Scores/Iris.php @@ -0,0 +1,61 @@ +pathIrisPdf = realpath($configuration->path->data).'/iris'; + } + + /** + * Récupére l'avis de situtation à partir du site au format pdf + * @param string $format Format 'pdf' ou 'array' + * @param boolean $force True aller obligatoirement le chercher à l'insee + * @return string Le PDF demandé + */ + function get($format='pdf', $force=0) + { + $force=$force*1; + $date=date('Ymd'); + if (!file_exists($this->pathIrisPdf)) mkdir($this->pathIrisPdf); + $fichier = $this->pathIrisPdf.'/carte_iris_'.$this->codeCommune.'.pdf'; + if ($format!='pdf') return 'Format pdf uniquement'; + if ($force==0 && file_exists($fichier)) + { + // On délivre le fichier + return file_get_contents($fichier); + } + else + { + $url = 'http://www.insee.fr/fr/methodes/zonages/iris/cartes/carte_iris_'.$this->codeCommune.'.pdf'; + $referer = $cookie = ''; + $page = getUrl($url, $cookie, '', $referer, false, 'www.insee.fr', '', $this->timeout); + //Code en 4xx ou 5xx signifie une erreur du serveur + $codeN = floor($page['code']/100); + if($codeN==4 || $codeN==5 || substr($page['body'],0,4)!='%PDF') + { + $this->erreur = "Fichier introuvable à l'insee !"; + return false; + } + else + { + $fp = @fopen($fichier, "w"); + @fwrite($fp, $body); + @fclose($fp); + return $page['body']; + } + } + } + + public function erreur() + { + return $this->erreur; + } + +} \ No newline at end of file