Subversion Repositories eFlore/Applications.cel

Rev

Rev 416 | Rev 996 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 416 Rev 885
1
<?php
1
<?php
-
 
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
*/
2
 
-
 
3
// In : utf8
-
 
4
// Out : iso8859
-
 
5
 
-
 
6
// Formatage pdf d'un releve (a revoir)
13
 
7
 
14
 
8
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
15
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
9
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
16
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.*/
17
/** 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');
18
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.*/
19
/** 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');
20
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.*/
21
/** 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');
22
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.*/
23
/** 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\/(.+)$/');
24
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
18
/** Constante stockant l'URL du service XML de Photoflora.*/
25
/** Constante stockant l'URL du service XML de Photoflora.*/
19
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
26
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
-
 
27
 
-
 
28
/**
-
 
29
* InventoryPDF.php
-
 
30
*
-
 
31
* in : utf8
-
 
32
* out : iso8859
-
 
33
*
-
 
34
* Formatage pdf d'un releve (a revoir)
-
 
35
*/
20
 
-
 
21
 
-
 
22
Class InventoryPDF extends DBAccessor  {
-
 
23
 
-
 
24
 
36
class InventoryPDF extends Cel  {
25
	var $config;
37
 
26
	var $extendPDFProductor;
38
	var $extendPDFProductor;
27
	
39
	
28
	function InventoryPDF($config) {
40
	function InventoryPDF($config) {
-
 
41
 
-
 
42
		parent::__construct($config);
29
 
43
 
30
		$this->config=$config;
44
		$this->config=$config;
31
		// Pas d'heritage multiple en php :(
45
		// Pas d'heritage multiple en php :(
32
		$this->extendPDFProductor = new PDFProductor();
46
		$this->extendPDFProductor = new PDFProductor();
33
		$this->extendPDFProductor->initPDF();
47
		$this->extendPDFProductor->initPDF();
34
	}
48
	}
-
 
49
	
-
 
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)
35
	
55
	* uid[4] : si absent : valeur 'all' (station)
36
 
56
	*/
37
	function getElement($uid){
57
	function getElement($uid){
38
		
58
		
39
		   // Controle detournement utilisateur 
59
	   // 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
			
60
	    session_start();
49
			$DB=$this->connectDB($this->config,'database_cel');
61
	 	$this->controleUtilisateur($uid[0]);
50
			 
62
	 				 
51
			if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
63
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
52
				$uid[1]="all";
64
			$uid[1]="all";
53
				$query_location="";
65
			$requete_location="";
54
			}
66
		}
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)) {
67
		else {
99
			     die($res->getMessage());
-
 
100
			}
-
 
101
					
68
			$requete_location=" AND location= ".$this->proteger($uid[1])." ";
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.
69
		}
109
			$pdf->setAutoPageBreak(true);
-
 
110
			// Start the document.
70
		
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) {
71
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
122
					if (($v=="null") || ($v=="000null")) {
72
			$uid[2]="all";
123
						$row[$k]="";
73
			$requete_date="";
124
					}
-
 
125
					else {
74
		}
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
                
-
 
-
 
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
		}
-
 
89
 
-
 
90
		if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
143
				$pdf->write(10, $text."\n");
91
			$uid[4]="all";
-
 
92
			$requete_station="";
-
 
93
		}
-
 
94
		else {
-
 
95
			$requete_station=" AND station= ".$this->proteger($uid[4])." ";
-
 
96
		}
-
 
97
		
144
				
98
		$value=array();
-
 
99
		
-
 
100
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation," .
145
				$projet_photo = 'photoflora';
101
	           " station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".$this->proteger($uid[0])." " .
146
		
102
				$requete_location.	
147
				$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $row['num_taxon']));
-
 
-
 
103
        		$requete_date.	
148
		
104
        		$requete_libre.	
149
		
105
         		$requete_station.	
150
		      	$url_miniature =''; 
106
          		" ORDER BY ordre ";
-
 
107
		
151
		      	
108
		$resultat_requete = $this->requeter($requete);
-
 
109
		
-
 
110
		$observations = array();;
152
				foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
111
		if(is_array($resultat_requete)) {
-
 
112
			$observations = $resultat_requete;
-
 
113
		}
153
					if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
114
		
-
 
115
		// Set up the pdf object.
-
 
116
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
154
					$abreviation = $match[1];
117
		// DesActivate compression.
-
 
118
		$pdf->setCompression(false);
-
 
119
		$pdf->setMargins(0, 0);
-
 
120
		// Enable automatic page breaks.
-
 
121
		$pdf->setAutoPageBreak(true);
155
					$fichier = $match[2];
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("","");
156
			      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
130
		
157
					
131
		foreach ($observations as $obs) {
158
					// Priorite aux images en png
-
 
159
						if (strstr($fichier, '.png')) {
-
 
160
							break;
-
 
161
						}
132
			
162
					}
-
 
163
				}
-
 
164
 
-
 
165
 
133
		 	// Denullifiage   
166
 
-
 
167
				if ($url_miniature!='') {				
-
 
168
					list($debut,$ext)=split("\.",basename($url_miniature));
134
			foreach($obs as $k=>$v) {
169
	       		    $temp = fopen($tempfn, "w");
-
 
170
					$buf=file_get_contents($url_miniature);
-
 
171
					fwrite($temp,$buf);
135
				if (($v=="null") || ($v=="000null")) {
172
        			fclose($temp);
-
 
173
					$pdf->image($tempfn,10,($i*10),0,0,$ext);
-
 
174
				}
-
 
-
 
136
					$obs[$k]="";
-
 
137
				}
-
 
138
				else {
-
 
139
					$obs[$k]=utf8_decode($v);
-
 
140
				}
-
 
141
			} 
-
 
142
			
-
 
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 {
175
		
149
                $obs['date_observation']="00/00/0000";
176
                $i++;
-
 
177
    	    }
-
 
-
 
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");
-
 
157
			
-
 
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!='') {				
178
    	
179
				list($debut,$ext)=split("\.",basename($url_miniature));
-
 
180
       		    $temp = fopen($tempfn, "w");
-
 
181
				$buf=file_get_contents($url_miniature);
179
			
182
				fwrite($temp,$buf);
180
			// Print the generated file.
183
    			fclose($temp);
181
			
184
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
182
		echo $pdf->output("Rapport");
185
			}
183
			
186
	
184
 
187
            $i++;
185
	}
188
	    }
186
	
189
    			
187
 
190
		echo $pdf->output("Rapport");
188
 
191
	}
189
}
192
}
190
 
193
 
191
function chercherIllustrationsServiceXml($url)
194
function chercherIllustrationsServiceXml($url)
192
{
195
{
193
		return  analyserFichierRdf($url);
196
		return  analyserFichierRdf($url);
194
}
197
}
195
	
198
	
196
function analyserFichierRdf($chemin)
199
function analyserFichierRdf($chemin)
197
{
200
{
198
		$aso_info = array();
201
		$aso_info = array();
199
		$dom = new DOMDocument();
202
		$dom = new DOMDocument();
200
		$dom->validateOnParse = true;
203
		$dom->validateOnParse = true;
201
		if (preg_match('/^http:\/\//', $chemin)) {
204
		if (preg_match('/^http:\/\//', $chemin)) {
202
			$dom->loadXML(file_get_contents($chemin));
205
			$dom->loadXML(file_get_contents($chemin));
203
		} else {
206
		} else {
204
			$dom->load($chemin);
207
			$dom->load($chemin);
205
		}
208
		}
206
		
209
		
207
		$tab_infos = array();
210
		$tab_infos = array();
208
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
211
		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');
212
			$aso_info['about'] = $rdf_description->getAttribute('about');
210
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
213
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
211
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
214
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
212
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
215
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
213
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
216
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
214
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
217
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
215
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
218
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
216
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
219
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
217
			if (function_exists('date_default_timezone_set')) {
220
			if (function_exists('date_default_timezone_set')) {
218
				date_default_timezone_set('Europe/Paris');
221
				date_default_timezone_set('Europe/Paris');
219
			}
222
			}
220
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
223
			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')));				
224
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));				
222
			} else {
225
			} else {
223
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
226
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
224
			}
227
			}
225
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
228
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
226
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
229
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
227
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
230
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
228
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
231
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info; 
229
		}
232
		}
230
		//echo '<pre>'.$chemin.print_r($tab_infos, true).'</pre>';
-
 
-
 
233
 
231
		return $tab_infos;
234
		return $tab_infos;
232
}
235
}
233
 
-
 
234
 
-
 
235
 
236
 
236
/* +--Fin du code ---------------------------------------------------------------------------------------+
237
/* +--Fin du code ---------------------------------------------------------------------------------------+
237
* $Log$
238
* $Log$
238
* Revision 1.2  2008-01-30 08:57:28  ddelon
239
* Revision 1.2  2008-01-30 08:57:28  ddelon
239
* fin mise en place mygwt
240
* fin mise en place mygwt
240
*
241
*
241
* Revision 1.1  2007-06-06 13:31:16  ddelon
242
* Revision 1.1  2007-06-06 13:31:16  ddelon
242
* v0.09
243
* v0.09
243
*
244
*
244
* Revision 1.4  2007-05-22 12:54:09  ddelon
245
* Revision 1.4  2007-05-22 12:54:09  ddelon
245
* Securisation acces utilisateur
246
* Securisation acces utilisateur
246
*
247
*
247
*
-
 
248
* 
-
 
249
*/
248
*/
250
 
-
 
251
 
-
 
252
?>
249
?>
253
250