Subversion Repositories eFlore/Applications.cel

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
39
 
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
	}
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){
58
 
885 aurelien 59
	   // Controle detournement utilisateur
60
	    session_start();
61
	 	$this->controleUtilisateur($uid[0]);
62
 
63
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
64
			$uid[1]="all";
65
			$requete_location="";
66
		}
67
		else {
68
			$requete_location=" AND location= ".$this->proteger($uid[1])." ";
69
		}
70
 
71
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
72
			$uid[2]="all";
73
			$requete_date="";
74
		}
75
		else {
76
			$requete_date=" AND date_observation= ".$this->proteger($uid[2])." ";
77
		}
78
 
79
		if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
80
			$uid[3]="all";
81
			$requete_libre="";
82
		}
83
		else {
84
			$requete_libre=" AND (nom_sel LIKE ".$this->proteger('%'.$uid[3].'%').
85
						" OR nom_ret LIKE ".$this->proteger('%'.$uid[3].'%').
86
						" OR station LIKE ".$this->proteger('%'.$uid[3].'%').
87
						" OR commentaire LIKE ".$this->proteger('%'.$uid[3].'%');
88
		}
416 aurelien 89
 
885 aurelien 90
		if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
91
			$uid[4]="all";
92
			$requete_station="";
93
		}
94
		else {
95
			$requete_station=" AND station= ".$this->proteger($uid[4])." ";
96
		}
416 aurelien 97
 
885 aurelien 98
		$value=array();
416 aurelien 99
 
885 aurelien 100
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," .
101
	           " station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".$this->proteger($uid[0])." " .
102
				$requete_location.
103
        		$requete_date.
104
        		$requete_libre.
105
         		$requete_station.
106
          		" ORDER BY ordre ";
416 aurelien 107
 
885 aurelien 108
		$resultat_requete = $this->requeter($requete);
416 aurelien 109
 
885 aurelien 110
		$observations = array();;
111
		if(is_array($resultat_requete)) {
112
			$observations = $resultat_requete;
113
		}
114
 
115
		// Set up the pdf object.
116
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
117
		// DesActivate compression.
118
		$pdf->setCompression(false);
119
		$pdf->setMargins(0, 0);
120
		// Enable automatic page breaks.
121
		$pdf->setAutoPageBreak(true);
122
		// Start the document.
123
		$pdf->open();
124
		// Start a page.
125
		$pdf->addPage();
126
		$pdf->setFont('Times', '' , 12);
127
 
128
		$i=1;
129
	    $tempfn = tempnam("","");
130
 
131
		foreach ($observations as $obs) {
132
 
133
		 	// Denullifiage
134
			foreach($obs as $k=>$v) {
135
				if (($v=="null") || ($v=="000null")) {
136
					$obs[$k]="";
416 aurelien 137
				}
885 aurelien 138
				else {
139
					$obs[$k]=utf8_decode($v);
416 aurelien 140
				}
885 aurelien 141
			}
416 aurelien 142
 
885 aurelien 143
		  	if ($obs['date_observation']!="0000-00-00 00:00:00") {
144
                list($year,$month,$day)= split ('-',$obs['date_observation']);
145
	            list($day)= split (' ',$day);
146
                $obs['date_observation']=$day."/".$month."/".$year;
147
        	}
148
        	else {
149
                $obs['date_observation']="00/00/0000";
150
        	}
151
 
152
            $text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
153
            $obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
154
            $obs['commentaire'];
155
 
156
			$pdf->write(10, $text."\n");
416 aurelien 157
 
885 aurelien 158
			$projet_photo = 'photoflora';
159
 
160
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
161
 
162
 
163
	      	$url_miniature ='';
164
 
165
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
166
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
167
				$abreviation = $match[1];
168
				$fichier = $match[2];
169
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
170
 
171
				// Priorite aux images en png
172
					if (strstr($fichier, '.png')) {
173
						break;
174
					}
175
				}
176
			}
177
 
178
			if ($url_miniature!='') {
179
				list($debut,$ext)=split("\.",basename($url_miniature));
180
       		    $temp = fopen($tempfn, "w");
181
				$buf=file_get_contents($url_miniature);
182
				fwrite($temp,$buf);
183
    			fclose($temp);
184
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
185
			}
186
 
187
            $i++;
188
	    }
189
 
416 aurelien 190
		echo $pdf->output("Rapport");
191
	}
192
}
193
 
194
function chercherIllustrationsServiceXml($url)
195
{
196
		return  analyserFichierRdf($url);
197
}
198
 
199
function analyserFichierRdf($chemin)
200
{
201
		$aso_info = array();
202
		$dom = new DOMDocument();
203
		$dom->validateOnParse = true;
204
		if (preg_match('/^http:\/\//', $chemin)) {
205
			$dom->loadXML(file_get_contents($chemin));
206
		} else {
207
			$dom->load($chemin);
208
		}
209
 
210
		$tab_infos = array();
211
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
212
			$aso_info['about'] = $rdf_description->getAttribute('about');
213
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
214
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
215
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
216
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
217
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
218
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
219
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
220
			if (function_exists('date_default_timezone_set')) {
221
				date_default_timezone_set('Europe/Paris');
222
			}
223
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
224
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));
225
			} else {
226
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
227
			}
228
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
229
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
230
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
231
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
232
		}
885 aurelien 233
 
416 aurelien 234
		return $tab_infos;
235
}
236
 
237
/* +--Fin du code ---------------------------------------------------------------------------------------+
238
* $Log$
239
* Revision 1.2  2008-01-30 08:57:28  ddelon
240
* fin mise en place mygwt
241
*
242
* Revision 1.1  2007-06-06 13:31:16  ddelon
243
* v0.09
244
*
245
* Revision 1.4  2007-05-22 12:54:09  ddelon
246
* Securisation acces utilisateur
247
*
248
*/
885 aurelien 249
?>