Subversion Repositories eFlore/Applications.cel

Rev

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

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