416 |
aurelien |
1 |
<?php
|
885 |
aurelien |
2 |
/**
|
|
|
3 |
* PHP Version 5
|
|
|
4 |
*
|
|
|
5 |
* @category PHP
|
|
|
6 |
* @package jrest
|
|
|
7 |
* @author David Delon <david.delon@clapas.net>
|
|
|
8 |
* @copyright 2010 Tela-Botanica
|
|
|
9 |
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
|
|
|
10 |
* @version SVN: <svn_id>
|
|
|
11 |
* @link /doc/jrest/
|
|
|
12 |
*/
|
416 |
aurelien |
13 |
|
|
|
14 |
|
|
|
15 |
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
|
|
|
16 |
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
|
|
|
17 |
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn.es.*/
|
|
|
18 |
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
|
|
|
19 |
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
|
|
|
20 |
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://www.tela-botanica.org/~photoflo/photos/%s/min/%s');
|
|
|
21 |
/** Constante stockant l'URL du dossier de photoflora contenant les images normale.*/
|
|
|
22 |
define('EF_URL_PHOTOFLORA_IMG_MAX', 'http://www.tela-botanica.org/~photoflo/photos/%s/max/%s');
|
|
|
23 |
/** Constante stockant l'expression r.guli.re r.cup.rant l'abr.viation du photographe et le nom du fichier.*/
|
|
|
24 |
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
|
|
|
25 |
/** Constante stockant l'URL du service XML de Photoflora.*/
|
|
|
26 |
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
|
|
|
27 |
|
885 |
aurelien |
28 |
/**
|
|
|
29 |
* InventoryPDF.php
|
|
|
30 |
*
|
|
|
31 |
* in : utf8
|
|
|
32 |
* out : iso8859
|
|
|
33 |
*
|
|
|
34 |
* Formatage pdf d'un releve (a revoir)
|
|
|
35 |
*/
|
|
|
36 |
class InventoryPDF extends Cel {
|
416 |
aurelien |
37 |
|
|
|
38 |
var $extendPDFProductor;
|
2450 |
jpm |
39 |
|
416 |
aurelien |
40 |
function InventoryPDF($config) {
|
|
|
41 |
|
885 |
aurelien |
42 |
parent::__construct($config);
|
|
|
43 |
|
416 |
aurelien |
44 |
$this->config=$config;
|
|
|
45 |
// Pas d'heritage multiple en php :(
|
|
|
46 |
$this->extendPDFProductor = new PDFProductor();
|
|
|
47 |
$this->extendPDFProductor->initPDF();
|
|
|
48 |
}
|
2450 |
jpm |
49 |
|
885 |
aurelien |
50 |
/**
|
|
|
51 |
* uid[0] : utilisateur obligatoire
|
|
|
52 |
* uid[1] : si absent : valeur 'all' (commune)
|
|
|
53 |
* uid[2] : si absent : valeur 'all' (date)
|
|
|
54 |
* uid[3] : si absent : valeur 'all' (recherche libre)
|
|
|
55 |
* uid[4] : si absent : valeur 'all' (station)
|
|
|
56 |
*/
|
416 |
aurelien |
57 |
function getElement($uid){
|
2450 |
jpm |
58 |
|
|
|
59 |
// Controle detournement utilisateur
|
885 |
aurelien |
60 |
$this->controleUtilisateur($uid[0]);
|
2450 |
jpm |
61 |
|
885 |
aurelien |
62 |
if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
|
|
|
63 |
$uid[1]="all";
|
|
|
64 |
$requete_location="";
|
|
|
65 |
}
|
|
|
66 |
else {
|
1765 |
raphael |
67 |
$requete_location=" AND location= ".Cel::db()->proteger($uid[1])." ";
|
885 |
aurelien |
68 |
}
|
2450 |
jpm |
69 |
|
885 |
aurelien |
70 |
if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
|
|
|
71 |
$uid[2]="all";
|
|
|
72 |
$requete_date="";
|
|
|
73 |
}
|
|
|
74 |
else {
|
1765 |
raphael |
75 |
$requete_date=" AND date_observation= ".Cel::db()->proteger($uid[2])." ";
|
885 |
aurelien |
76 |
}
|
2450 |
jpm |
77 |
|
885 |
aurelien |
78 |
if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
|
|
|
79 |
$uid[3]="all";
|
|
|
80 |
$requete_libre="";
|
|
|
81 |
}
|
|
|
82 |
else {
|
1765 |
raphael |
83 |
$requete_libre=" AND (nom_sel LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
|
|
|
84 |
" OR nom_ret LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
|
|
|
85 |
" OR station LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
|
|
|
86 |
" OR commentaire LIKE ".Cel::db()->proteger('%'.$uid[3].'%');
|
885 |
aurelien |
87 |
}
|
416 |
aurelien |
88 |
|
885 |
aurelien |
89 |
if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
|
|
|
90 |
$uid[4]="all";
|
|
|
91 |
$requete_station="";
|
|
|
92 |
}
|
|
|
93 |
else {
|
1765 |
raphael |
94 |
$requete_station=" AND station= ".Cel::db()->proteger($uid[4])." ";
|
885 |
aurelien |
95 |
}
|
2450 |
jpm |
96 |
|
885 |
aurelien |
97 |
$value=array();
|
2450 |
jpm |
98 |
|
|
|
99 |
$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation, " .
|
|
|
100 |
"station, commentaire, transmission FROM cel_obs WHERE ce_utilisateur = ".Cel::db()->proteger($uid[0])." " .
|
|
|
101 |
$requete_location.
|
|
|
102 |
$requete_date.
|
|
|
103 |
$requete_libre.
|
|
|
104 |
$requete_station.
|
885 |
aurelien |
105 |
" ORDER BY ordre ";
|
2450 |
jpm |
106 |
|
1765 |
raphael |
107 |
$resultat_requete = Cel::db()->requeter($requete);
|
2450 |
jpm |
108 |
|
885 |
aurelien |
109 |
$observations = array();;
|
|
|
110 |
if(is_array($resultat_requete)) {
|
|
|
111 |
$observations = $resultat_requete;
|
|
|
112 |
}
|
2450 |
jpm |
113 |
|
885 |
aurelien |
114 |
// Set up the pdf object.
|
|
|
115 |
$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
|
|
|
116 |
// DesActivate compression.
|
|
|
117 |
$pdf->setCompression(false);
|
|
|
118 |
$pdf->setMargins(0, 0);
|
|
|
119 |
// Enable automatic page breaks.
|
|
|
120 |
$pdf->setAutoPageBreak(true);
|
|
|
121 |
// Start the document.
|
|
|
122 |
$pdf->open();
|
|
|
123 |
// Start a page.
|
|
|
124 |
$pdf->addPage();
|
|
|
125 |
$pdf->setFont('Times', '' , 12);
|
2450 |
jpm |
126 |
|
|
|
127 |
$i=1;
|
885 |
aurelien |
128 |
$tempfn = tempnam("","");
|
2450 |
jpm |
129 |
|
885 |
aurelien |
130 |
foreach ($observations as $obs) {
|
2450 |
jpm |
131 |
|
|
|
132 |
// Denullifiage
|
885 |
aurelien |
133 |
foreach($obs as $k=>$v) {
|
|
|
134 |
if (($v=="null") || ($v=="000null")) {
|
|
|
135 |
$obs[$k]="";
|
416 |
aurelien |
136 |
}
|
885 |
aurelien |
137 |
else {
|
|
|
138 |
$obs[$k]=utf8_decode($v);
|
416 |
aurelien |
139 |
}
|
2450 |
jpm |
140 |
}
|
|
|
141 |
|
885 |
aurelien |
142 |
if ($obs['date_observation']!="0000-00-00 00:00:00") {
|
996 |
aurelien |
143 |
list($year,$month,$day)= explode('-',$obs['date_observation']);
|
|
|
144 |
list($day)= explode(' ',$day);
|
885 |
aurelien |
145 |
$obs['date_observation']=$day."/".$month."/".$year;
|
|
|
146 |
}
|
|
|
147 |
else {
|
|
|
148 |
$obs['date_observation']="00/00/0000";
|
|
|
149 |
}
|
2450 |
jpm |
150 |
|
885 |
aurelien |
151 |
$text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
|
|
|
152 |
$obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
|
|
|
153 |
$obs['commentaire'];
|
2450 |
jpm |
154 |
|
885 |
aurelien |
155 |
$pdf->write(10, $text."\n");
|
2450 |
jpm |
156 |
|
885 |
aurelien |
157 |
$projet_photo = 'photoflora';
|
2450 |
jpm |
158 |
|
885 |
aurelien |
159 |
$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
|
2450 |
jpm |
160 |
|
|
|
161 |
|
|
|
162 |
$url_miniature ='';
|
|
|
163 |
|
885 |
aurelien |
164 |
foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
|
|
|
165 |
if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
|
|
|
166 |
$abreviation = $match[1];
|
|
|
167 |
$fichier = $match[2];
|
|
|
168 |
$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
|
2450 |
jpm |
169 |
|
885 |
aurelien |
170 |
// Priorite aux images en png
|
|
|
171 |
if (strstr($fichier, '.png')) {
|
|
|
172 |
break;
|
|
|
173 |
}
|
|
|
174 |
}
|
|
|
175 |
}
|
|
|
176 |
|
2450 |
jpm |
177 |
if ($url_miniature!='') {
|
996 |
aurelien |
178 |
list($debut,$ext)=explode("\.",basename($url_miniature));
|
885 |
aurelien |
179 |
$temp = fopen($tempfn, "w");
|
|
|
180 |
$buf=file_get_contents($url_miniature);
|
|
|
181 |
fwrite($temp,$buf);
|
|
|
182 |
fclose($temp);
|
|
|
183 |
$pdf->image($tempfn,10,($i*10),0,0,$ext);
|
|
|
184 |
}
|
2450 |
jpm |
185 |
|
885 |
aurelien |
186 |
$i++;
|
|
|
187 |
}
|
2450 |
jpm |
188 |
|
416 |
aurelien |
189 |
echo $pdf->output("Rapport");
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
function chercherIllustrationsServiceXml($url)
|
|
|
194 |
{
|
|
|
195 |
return analyserFichierRdf($url);
|
|
|
196 |
}
|
2450 |
jpm |
197 |
|
416 |
aurelien |
198 |
function analyserFichierRdf($chemin)
|
|
|
199 |
{
|
|
|
200 |
$aso_info = array();
|
|
|
201 |
$dom = new DOMDocument();
|
|
|
202 |
$dom->validateOnParse = true;
|
|
|
203 |
if (preg_match('/^http:\/\//', $chemin)) {
|
|
|
204 |
$dom->loadXML(file_get_contents($chemin));
|
|
|
205 |
} else {
|
|
|
206 |
$dom->load($chemin);
|
|
|
207 |
}
|
2450 |
jpm |
208 |
|
416 |
aurelien |
209 |
$tab_infos = array();
|
|
|
210 |
foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
|
|
|
211 |
$aso_info['about'] = $rdf_description->getAttribute('about');
|
|
|
212 |
$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
|
|
|
213 |
$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
|
|
|
214 |
$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
|
|
|
215 |
$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
|
|
|
216 |
$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
|
|
|
217 |
$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
|
|
|
218 |
$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
|
|
|
219 |
if (function_exists('date_default_timezone_set')) {
|
|
|
220 |
date_default_timezone_set('Europe/Paris');
|
|
|
221 |
}
|
|
|
222 |
if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
|
2450 |
jpm |
223 |
$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));
|
416 |
aurelien |
224 |
} else {
|
|
|
225 |
$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
|
|
|
226 |
}
|
|
|
227 |
$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
|
|
|
228 |
$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
|
|
|
229 |
$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
|
2450 |
jpm |
230 |
$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
|
416 |
aurelien |
231 |
}
|
885 |
aurelien |
232 |
|
416 |
aurelien |
233 |
return $tab_infos;
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/* +--Fin du code ---------------------------------------------------------------------------------------+
|
|
|
237 |
* $Log$
|
|
|
238 |
* Revision 1.2 2008-01-30 08:57:28 ddelon
|
|
|
239 |
* fin mise en place mygwt
|
|
|
240 |
*
|
|
|
241 |
* Revision 1.1 2007-06-06 13:31:16 ddelon
|
|
|
242 |
* v0.09
|
|
|
243 |
*
|
|
|
244 |
* Revision 1.4 2007-05-22 12:54:09 ddelon
|
|
|
245 |
* Securisation acces utilisateur
|
|
|
246 |
*
|
|
|
247 |
*/
|
885 |
aurelien |
248 |
?>
|