1,10 → 1,17 |
<?php |
/** |
* PHP Version 5 |
* |
* @category PHP |
* @package jrest |
* @author David Delon <david.delon@clapas.net> |
* @copyright 2010 Tela-Botanica |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL |
* @version SVN: <svn_id> |
* @link /doc/jrest/ |
*/ |
|
// In : utf8 |
// Out : iso8859 |
|
// Formatage pdf d'un releve (a revoir) |
|
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/ |
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/'); |
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn.es.*/ |
18,15 → 25,22 |
/** Constante stockant l'URL du service XML de Photoflora.*/ |
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s'); |
|
/** |
* InventoryPDF.php |
* |
* in : utf8 |
* out : iso8859 |
* |
* Formatage pdf d'un releve (a revoir) |
*/ |
class InventoryPDF extends Cel { |
|
Class InventoryPDF extends DBAccessor { |
|
|
var $config; |
var $extendPDFProductor; |
|
function InventoryPDF($config) { |
|
parent::__construct($config); |
|
$this->config=$config; |
// Pas d'heritage multiple en php :( |
$this->extendPDFProductor = new PDFProductor(); |
33,159 → 47,148 |
$this->extendPDFProductor->initPDF(); |
} |
|
|
/** |
* uid[0] : utilisateur obligatoire |
* uid[1] : si absent : valeur 'all' (commune) |
* uid[2] : si absent : valeur 'all' (date) |
* uid[3] : si absent : valeur 'all' (recherche libre) |
* uid[4] : si absent : valeur 'all' (station) |
*/ |
function getElement($uid){ |
|
// Controle detournement utilisateur |
session_start(); |
$this->controleUtilisateur($uid[0]); |
// Controle detournement utilisateur |
session_start(); |
$this->controleUtilisateur($uid[0]); |
|
if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) { |
$uid[1]="all"; |
$requete_location=""; |
} |
else { |
$requete_location=" AND location= ".$this->proteger($uid[1])." "; |
} |
|
if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") { |
$uid[2]="all"; |
$requete_date=""; |
} |
else { |
$requete_date=" AND date_observation= ".$this->proteger($uid[2])." "; |
} |
|
if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") { |
$uid[3]="all"; |
$requete_libre=""; |
} |
else { |
$requete_libre=" AND (nom_sel LIKE ".$this->proteger('%'.$uid[3].'%'). |
" OR nom_ret LIKE ".$this->proteger('%'.$uid[3].'%'). |
" OR station LIKE ".$this->proteger('%'.$uid[3].'%'). |
" OR commentaire LIKE ".$this->proteger('%'.$uid[3].'%'); |
} |
|
// uid[0] : utilisateur obligatoire |
// uid[1] : si absent : valeur 'all' (commune) |
// uid[2] : si absent : valeur 'all' (date) |
// uid[3] : si absent : valeur 'all' (recherche libre) |
// uid[4] : si absent : valeur 'all' (station) |
|
$DB=$this->connectDB($this->config,'database_cel'); |
|
if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) { |
$uid[1]="all"; |
$query_location=""; |
} |
else { |
$query_location=" AND location='".$DB->escapeSimple($uid[1])."' "; |
} |
|
if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") { |
$uid[2]="all"; |
$query_date=""; |
} |
else { |
$query_date=" AND date_observation='".$DB->escapeSimple($uid[2])."' "; |
} |
|
if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") { |
$uid[3]="all"; |
$query_libre=""; |
} |
else { |
$query_libre=" AND (nom_sel like '%".$DB->escapeSimple($uid[3])."%' OR nom_ret like '%".$DB->escapeSimple($uid[3])."%' OR station like '%".$DB->escapeSimple($uid[3])."%' OR commentaire like '%".$DB->escapeSimple($uid[3])."%') "; |
} |
|
if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") { |
$uid[4]="all"; |
$query_station=""; |
} |
else { |
$query_station=" AND station='".$DB->escapeSimple($uid[4])."' "; |
} |
|
|
$value=array(); |
|
|
$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," . |
" station, commentaire, transmission FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " . |
$query_location. |
$query_date. |
$query_libre. |
$query_station. |
" ORDER BY ordre "; |
|
$res =& $DB->query($query); |
|
|
if (DB::isError($res)) { |
die($res->getMessage()); |
} |
|
if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") { |
$uid[4]="all"; |
$requete_station=""; |
} |
else { |
$requete_station=" AND station= ".$this->proteger($uid[4])." "; |
} |
|
// Set up the pdf object. |
$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4')); |
// DesActivate compression. |
$pdf->setCompression(false); |
$pdf->setMargins(0, 0); |
// Enable automatic page breaks. |
$pdf->setAutoPageBreak(true); |
// Start the document. |
$pdf->open(); |
// Start a page. |
$pdf->addPage(); |
$pdf->setFont('Times', '' , 12); |
|
$i=1; |
$tempfn = tempnam("",""); |
|
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) { |
// Denullifiage |
foreach($row as $k=>$v) { |
if (($v=="null") || ($v=="000null")) { |
$row[$k]=""; |
} |
else { |
$row[$k]=utf8_decode($v); |
} |
} |
|
if ($row['date_observation']!="0000-00-00 00:00:00") { |
list($year,$month,$day)= split ('-',$row['date_observation']); |
list($day)= split (' ',$day); |
$row['date_observation']=$day."/".$month."/".$year; |
} |
else { |
$row['date_observation']="00/00/0000"; |
} |
|
$text= $row['nom_sel']." ".$row['num_nom_sel']." ".$row['nom_ret']." ".$row['num_nom_ret']." ".$row['num_taxon']." ". |
$row['famille']." ".$row['location']." ".$row['id_location']." ".$row['date_observation']." ".$row['station']; |
$row['commentaire']; |
|
$pdf->write(10, $text."\n"); |
|
$projet_photo = 'photoflora'; |
$value=array(); |
|
$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $row['num_taxon'])); |
$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," . |
" station, commentaire, transmission FROM cel_obs WHERE ce_utilisateur = ".$this->proteger($uid[0])." " . |
$requete_location. |
$requete_date. |
$requete_libre. |
$requete_station. |
" ORDER BY ordre "; |
|
$resultat_requete = $this->requeter($requete); |
|
$url_miniature =''; |
|
foreach ($tab_retour[$projet_photo] as $cle => $illustration) { |
if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) { |
$abreviation = $match[1]; |
$fichier = $match[2]; |
$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);; |
|
// Priorite aux images en png |
if (strstr($fichier, '.png')) { |
break; |
} |
} |
$observations = array();; |
if(is_array($resultat_requete)) { |
$observations = $resultat_requete; |
} |
|
// Set up the pdf object. |
$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4')); |
// DesActivate compression. |
$pdf->setCompression(false); |
$pdf->setMargins(0, 0); |
// Enable automatic page breaks. |
$pdf->setAutoPageBreak(true); |
// Start the document. |
$pdf->open(); |
// Start a page. |
$pdf->addPage(); |
$pdf->setFont('Times', '' , 12); |
|
$i=1; |
$tempfn = tempnam("",""); |
|
foreach ($observations as $obs) { |
|
// Denullifiage |
foreach($obs as $k=>$v) { |
if (($v=="null") || ($v=="000null")) { |
$obs[$k]=""; |
} |
|
|
|
if ($url_miniature!='') { |
list($debut,$ext)=split("\.",basename($url_miniature)); |
$temp = fopen($tempfn, "w"); |
$buf=file_get_contents($url_miniature); |
fwrite($temp,$buf); |
fclose($temp); |
$pdf->image($tempfn,10,($i*10),0,0,$ext); |
else { |
$obs[$k]=utf8_decode($v); |
} |
|
$i++; |
} |
|
} |
|
// Print the generated file. |
if ($obs['date_observation']!="0000-00-00 00:00:00") { |
list($year,$month,$day)= split ('-',$obs['date_observation']); |
list($day)= split (' ',$day); |
$obs['date_observation']=$day."/".$month."/".$year; |
} |
else { |
$obs['date_observation']="00/00/0000"; |
} |
|
$text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ". |
$obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station']; |
$obs['commentaire']; |
|
$pdf->write(10, $text."\n"); |
|
$projet_photo = 'photoflora'; |
|
$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt'])); |
|
|
$url_miniature =''; |
|
foreach ($tab_retour[$projet_photo] as $cle => $illustration) { |
if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) { |
$abreviation = $match[1]; |
$fichier = $match[2]; |
$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);; |
|
// Priorite aux images en png |
if (strstr($fichier, '.png')) { |
break; |
} |
} |
} |
|
if ($url_miniature!='') { |
list($debut,$ext)=split("\.",basename($url_miniature)); |
$temp = fopen($tempfn, "w"); |
$buf=file_get_contents($url_miniature); |
fwrite($temp,$buf); |
fclose($temp); |
$pdf->image($tempfn,10,($i*10),0,0,$ext); |
} |
|
$i++; |
} |
|
echo $pdf->output("Rapport"); |
|
|
} |
|
|
|
} |
|
function chercherIllustrationsServiceXml($url) |
227,12 → 230,10 |
$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence')); |
$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; |
} |
//echo '<pre>'.$chemin.print_r($tab_infos, true).'</pre>'; |
|
return $tab_infos; |
} |
|
|
|
/* +--Fin du code ---------------------------------------------------------------------------------------+ |
* $Log$ |
* Revision 1.2 2008-01-30 08:57:28 ddelon |
244,9 → 245,5 |
* Revision 1.4 2007-05-22 12:54:09 ddelon |
* Securisation acces utilisateur |
* |
* |
* |
*/ |
|
|
?> |
?> |