Ajout code Iris
This commit is contained in:
parent
7e45391497
commit
a5d000f6d3
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,22 @@
|
||||
<br/>
|
||||
<b>Code commune / Rivoli :</b><br/>
|
||||
<?php print $this->infos->Dept.' '.$this->infos->codeCommune.' / '.$this->infos->Rivoli; ?>
|
||||
<?php
|
||||
if (count($this->infos->InfosIris)>0){
|
||||
$InfosIris = $this->infos->InfosIris;
|
||||
$codComIris = str_replace($InfosIris->codIris, '', $InfosIris->codComIris);
|
||||
?>
|
||||
<br/><br/><b>Iris :</b>
|
||||
<?php
|
||||
if ($InfosIris->codIris*1 == 0){
|
||||
?>
|
||||
<br/>Commune non découpée en Iris
|
||||
<?php } else {?>
|
||||
<br/>Code : <?=$codComIris?> <?=$InfosIris->codIris?>
|
||||
<br/>Libellé : <a title="Consulter le plan d'assemblage de la commune" href="<?=$this->url(array('controller'=>'identite', 'action'=>'iris', 'code'=>$codComIris), null, true)?>" target="_blank"><?=$InfosIris->libIris?></a>
|
||||
<img title="<?=$InfosIris->typIris?>" style="vertical-align:middle;" src="/themes/default/images/info.gif">
|
||||
<?php }?>
|
||||
<?php }?>
|
||||
</div>
|
||||
<?php if ($this->source == 'google'):?>
|
||||
<div id="infogeo_photo">
|
||||
|
61
library/Scores/Iris.php
Normal file
61
library/Scores/Iris.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
class Iris
|
||||
{
|
||||
protected static $timeout = 10;
|
||||
protected $pathIrisPdf;
|
||||
protected $codeCommune;
|
||||
protected $erreur = '';
|
||||
|
||||
public function __construct($codeCommune)
|
||||
{
|
||||
require_once 'common/curl.php';
|
||||
$configuration = Zend_Registry::get('configuration');
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user