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
2
 
3
// In : utf8
4
// Out : iso8859
5
 
6
// Formatage pdf d'un releve (a revoir)
7
 
8
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
9
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
10
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn.es.*/
11
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
12
/** Constante stockant l'URL du dossier de photoflora contenant les images miniatures.*/
13
define('EF_URL_PHOTOFLORA_IMG_MIN', 'http://www.tela-botanica.org/~photoflo/photos/%s/min/%s');
14
/** Constante stockant l'URL du dossier de photoflora contenant les images normale.*/
15
define('EF_URL_PHOTOFLORA_IMG_MAX', 'http://www.tela-botanica.org/~photoflo/photos/%s/max/%s');
16
/** Constante stockant l'expression r.guli.re r.cup.rant l'abr.viation du photographe et le nom du fichier.*/
17
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
18
/** Constante stockant l'URL du service XML de Photoflora.*/
19
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
20
 
21
 
22
Class InventoryPDF extends DBAccessor  {
23
 
24
 
25
	var $config;
26
	var $extendPDFProductor;
27
 
28
	function InventoryPDF($config) {
29
 
30
		$this->config=$config;
31
		// Pas d'heritage multiple en php :(
32
		$this->extendPDFProductor = new PDFProductor();
33
		$this->extendPDFProductor->initPDF();
34
	}
35
 
36
 
37
	function getElement($uid){
38
 
39
		   // Controle detournement utilisateur
40
		    session_start();
41
		 	$this->controleUtilisateur($uid[0]);
42
 
43
			// uid[0] : utilisateur obligatoire
44
			// uid[1] : si absent : valeur 'all' (commune)
45
			// uid[2] : si absent : valeur 'all' (date)
46
			// uid[3] : si absent : valeur 'all' (recherche libre)
47
			// uid[4] : si absent : valeur 'all' (station)
48
 
49
			$DB=$this->connectDB($this->config,'database_cel');
50
 
51
			if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
52
				$uid[1]="all";
53
				$query_location="";
54
			}
55
			else {
56
				$query_location=" AND location='".$DB->escapeSimple($uid[1])."' ";
57
			}
58
 
59
			if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
60
				$uid[2]="all";
61
				$query_date="";
62
			}
63
			else {
64
				$query_date=" AND date_observation='".$DB->escapeSimple($uid[2])."' ";
65
			}
66
 
67
			if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
68
				$uid[3]="all";
69
				$query_libre="";
70
			}
71
			else {
72
				$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])."%') ";
73
			}
74
 
75
			if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
76
				$uid[4]="all";
77
				$query_station="";
78
			}
79
			else {
80
				$query_station=" AND station='".$DB->escapeSimple($uid[4])."' ";
81
			}
82
 
83
 
84
			$value=array();
85
 
86
 
87
		   	$query="SELECT identifiant, ordre, nom_sel, num_nom_sel, nom_ret, num_nom_ret, num_taxon, famille, location, date_observation," .
88
		           " station, commentaire, transmission  FROM cel_inventory WHERE identifiant='".$DB->escapeSimple($uid[0])."' " .
89
					$query_location.
90
	        		$query_date.
91
	        		$query_libre.
92
	         		$query_station.
93
	          		" ORDER BY ordre ";
94
 
95
       	    $res =& $DB->query($query);
96
 
97
 
98
			if (DB::isError($res)) {
99
			     die($res->getMessage());
100
			}
101
 
102
 
103
			// Set up the pdf object.
104
			$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
105
			// DesActivate compression.
106
			$pdf->setCompression(false);
107
			$pdf->setMargins(0, 0);
108
			// Enable automatic page breaks.
109
			$pdf->setAutoPageBreak(true);
110
			// Start the document.
111
			$pdf->open();
112
			// Start a page.
113
			$pdf->addPage();
114
			$pdf->setFont('Times', '' , 12);
115
 
116
			$i=1;
117
		    $tempfn = tempnam("","");
118
 
119
			 while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
120
			 	// Denullifiage
121
				foreach($row as $k=>$v) {
122
					if (($v=="null") || ($v=="000null")) {
123
						$row[$k]="";
124
					}
125
					else {
126
						$row[$k]=utf8_decode($v);
127
					}
128
				}
129
 
130
			  	if ($row['date_observation']!="0000-00-00 00:00:00") {
131
	                list($year,$month,$day)= split ('-',$row['date_observation']);
132
    	            list($day)= split (' ',$day);
133
	                $row['date_observation']=$day."/".$month."/".$year;
134
	        	}
135
	        	else {
136
	                $row['date_observation']="00/00/0000";
137
	        	}
138
 
139
                $text= $row['nom_sel']." ".$row['num_nom_sel']." ".$row['nom_ret']." ".$row['num_nom_ret']." ".$row['num_taxon']." ".
140
                $row['famille']." ".$row['location']." ".$row['id_location']." ".$row['date_observation']." ".$row['station'];
141
                $row['commentaire'];
142
 
143
				$pdf->write(10, $text."\n");
144
 
145
				$projet_photo = 'photoflora';
146
 
147
				$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $row['num_taxon']));
148
 
149
 
150
		      	$url_miniature ='';
151
 
152
				foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
153
					if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
154
					$abreviation = $match[1];
155
					$fichier = $match[2];
156
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
157
 
158
					// Priorite aux images en png
159
						if (strstr($fichier, '.png')) {
160
							break;
161
						}
162
					}
163
				}
164
 
165
 
166
 
167
				if ($url_miniature!='') {
168
					list($debut,$ext)=split("\.",basename($url_miniature));
169
	       		    $temp = fopen($tempfn, "w");
170
					$buf=file_get_contents($url_miniature);
171
					fwrite($temp,$buf);
172
        			fclose($temp);
173
					$pdf->image($tempfn,10,($i*10),0,0,$ext);
174
				}
175
 
176
                $i++;
177
    	    }
178
 
179
 
180
			// Print the generated file.
181
 
182
		echo $pdf->output("Rapport");
183
 
184
 
185
	}
186
 
187
 
188
 
189
}
190
 
191
function chercherIllustrationsServiceXml($url)
192
{
193
		return  analyserFichierRdf($url);
194
}
195
 
196
function analyserFichierRdf($chemin)
197
{
198
		$aso_info = array();
199
		$dom = new DOMDocument();
200
		$dom->validateOnParse = true;
201
		if (preg_match('/^http:\/\//', $chemin)) {
202
			$dom->loadXML(file_get_contents($chemin));
203
		} else {
204
			$dom->load($chemin);
205
		}
206
 
207
		$tab_infos = array();
208
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
209
			$aso_info['about'] = $rdf_description->getAttribute('about');
210
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
211
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
212
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
213
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
214
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
215
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
216
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
217
			if (function_exists('date_default_timezone_set')) {
218
				date_default_timezone_set('Europe/Paris');
219
			}
220
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
221
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));
222
			} else {
223
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
224
			}
225
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
226
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
227
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
228
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
229
		}
230
		//echo '<pre>'.$chemin.print_r($tab_infos, true).'</pre>';
231
		return $tab_infos;
232
}
233
 
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
*
248
*
249
*/
250
 
251
 
252
?>