Subversion Repositories eFlore/Applications.cel

Rev

Rev 2450 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2450 Rev 2458
Line 1... Line 1...
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
2
/**
3
/**
3
* PHP Version 5
4
 * Service générant un PDF d'export des observations pour réaliser des étiquettes d'herbier.
4
*
5
 *
-
 
6
 * @internal   Mininum PHP version : 5.2
5
* @category  PHP
7
 * @category   CEL
6
* @package   jrest
8
 * @package    Services
-
 
9
 * @subpackage Export
-
 
10
 * @version    0.1
7
* @author    David Delon <david.delon@clapas.net>
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
8
* @copyright 2010 Tela-Botanica
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
-
 
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
9
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
10
* @version   SVN: <svn_id>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
11
* @link      /doc/jrest/
-
 
12
*/
17
 */
13
 
-
 
Line 14... Line 18...
14
 
18
 
15
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
19
/** Constante stockant l'URL de la page d'accueil de Photoflora.*/
16
define('EF_URL_PHOTOFLORA', 'http://photoflora.free.fr/');
20
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.*/
21
/** Constante stockant l'URL de la page de Photoflora affichant toutes les images d'un taxon donn.es.*/
Line 23... Line 27...
23
/** Constante stockant l'expression r.guli.re r.cup.rant l'abr.viation du photographe et le nom du fichier.*/
27
/** 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\/(.+)$/');
28
define('EF_URL_PHOTOFLORA_REGEXP', '/\/photos\/([^\/]+)\/max\/(.+)$/');
25
/** Constante stockant l'URL du service XML de Photoflora.*/
29
/** Constante stockant l'URL du service XML de Photoflora.*/
26
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
30
define('EF_URL_PHOTOFLORA_SERVICE', EF_URL_PHOTOFLORA.'ef_photoflora.php?nt=%s');
Line 27... Line -...
27
 
-
 
28
/**
-
 
29
* InventoryPDF.php
-
 
30
*
-
 
31
* in : utf8
-
 
32
* out : iso8859
-
 
33
*
-
 
34
* Formatage pdf d'un releve (a revoir)
-
 
35
*/
31
 
Line 36... Line 32...
36
class InventoryPDF extends Cel  {
32
class InventoryPDF extends Cel  {
Line 37... Line 33...
37
 
33
 
38
	var $extendPDFProductor;
-
 
39
 
34
	var $extendPDFProductor;
Line 40... Line 35...
40
	function InventoryPDF($config) {
35
 
41
 
36
	public function __construct($config) {
42
		parent::__construct($config);
37
		parent::__construct($config);
43
 
38
 
44
		$this->config=$config;
39
		$this->config = $config;
Line 52... Line 47...
52
	* uid[1] : si absent : valeur 'all' (commune)
47
	* uid[1] : si absent : valeur 'all' (commune)
53
	* uid[2] : si absent : valeur 'all' (date)
48
	* uid[2] : si absent : valeur 'all' (date)
54
	* uid[3] : si absent : valeur 'all' (recherche libre)
49
	* uid[3] : si absent : valeur 'all' (recherche libre)
55
	* uid[4] : si absent : valeur 'all' (station)
50
	* uid[4] : si absent : valeur 'all' (station)
56
	*/
51
	*/
57
	function getElement($uid){
52
	public function getElement($uid){
58
 
-
 
59
	   // Controle detournement utilisateur
53
		// Controle detournement utilisateur
60
	 	$this->controleUtilisateur($uid[0]);
54
	 	$this->controleUtilisateur($uid[0]);
Line 61... Line 55...
61
 
55
 
62
		if (!isset($uid[1]) || $uid[1]=="" || $uid[1]=="all" ) {
56
		if (!isset($uid[1]) || $uid[1] == '' || $uid[1] == 'all' ) {
63
			$uid[1]="all";
57
			$uid[1] = 'all';
64
			$requete_location="";
-
 
65
		}
58
			$requete_location = '';
66
		else {
59
		} else {
67
			$requete_location=" AND location= ".Cel::db()->proteger($uid[1])." ";
60
			$requete_location = ' AND location= '.Cel::db()->proteger($uid[1]).' ';
Line 68... Line 61...
68
		}
61
		}
69
 
62
 
70
		if (!isset($uid[2]) || $uid[2]=="" || $uid[2]=="all") {
63
		if (!isset($uid[2]) || $uid[2] == '' || $uid[2] == 'all') {
71
			$uid[2]="all";
-
 
72
			$requete_date="";
64
			$uid[2] = 'all';
73
		}
65
			$requete_date = '';
74
		else {
66
		} else {
Line 75... Line 67...
75
			$requete_date=" AND date_observation= ".Cel::db()->proteger($uid[2])." ";
67
			$requete_date = ' AND date_observation= '.Cel::db()->proteger($uid[2]).' ';
76
		}
68
		}
77
 
69
 
78
		if (!isset($uid[3]) || $uid[3]=="" || $uid[3]=="all") {
-
 
79
			$uid[3]="all";
70
		if (!isset($uid[3]) || $uid[3] == '' || $uid[3] == 'all') {
80
			$requete_libre="";
71
			$uid[3] = 'all';
81
		}
72
			$requete_libre = '';
82
		else {
73
		} else {
83
			$requete_libre=" AND (nom_sel LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
74
			$requete_libre = ' AND (nom_sel LIKE '.Cel::db()->proteger('%'.$uid[3].'%').
84
						" OR nom_ret LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
75
						' OR nom_ret LIKE '.Cel::db()->proteger('%'.$uid[3].'%').
Line 85... Line 76...
85
						" OR station LIKE ".Cel::db()->proteger('%'.$uid[3].'%').
76
						' OR station LIKE '.Cel::db()->proteger('%'.$uid[3].'%').
86
						" OR commentaire LIKE ".Cel::db()->proteger('%'.$uid[3].'%');
77
						' OR commentaire LIKE '.Cel::db()->proteger('%'.$uid[3].'%');
87
		}
78
		}
88
 
-
 
89
		if (!isset($uid[4]) || $uid[4]=="" || $uid[4]=="all") {
79
 
90
			$uid[4]="all";
80
		if (!isset($uid[4]) || $uid[4] == '' || $uid[4] == 'all') {
91
			$requete_station="";
81
			$uid[4] = 'all';
Line 92... Line 82...
92
		}
82
			$requete_station ='';
93
		else {
-
 
94
			$requete_station=" AND station= ".Cel::db()->proteger($uid[4])." ";
83
		} else {
-
 
84
			$requete_station = ' AND station= '.Cel::db()->proteger($uid[4]).' ';
-
 
85
		}
95
		}
86
 
96
 
87
		$value = array();
97
		$value=array();
88
		$requete = 'SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation, '.
98
 
89
			'station, commentaire, transmission '.
99
	   	$requete="SELECT ce_utilisateur, ordre, nom_sel, nom_sel_nn, nom_ret, nom_ret_nn, nt, famille, zone_geo, date_observation, " .
90
			'FROM cel_obs '.
100
	           "station, commentaire, transmission  FROM cel_obs WHERE ce_utilisateur = ".Cel::db()->proteger($uid[0])." " .
91
			'WHERE ce_utilisateur = '.Cel::db()->proteger($uid[0]).' '.
101
				$requete_location.
-
 
-
 
92
			$requete_location.
102
        		$requete_date.
93
			$requete_date.
Line 103... Line 94...
103
        		$requete_libre.
94
			$requete_libre.
104
         		$requete_station.
95
			$requete_station.' '.
105
          		" ORDER BY ordre ";
96
			'ORDER BY ordre '.
106
 
97
			' -- '.__FILE__.':'.__LINE__;
Line 107... Line 98...
107
		$resultat_requete = Cel::db()->requeter($requete);
98
		$resultat = Cel::db()->requeter($requete);
108
 
99
 
109
		$observations = array();;
100
		$observations = array();;
Line 122... Line 113...
122
		$pdf->open();
113
		$pdf->open();
123
		// Start a page.
114
		// Start a page.
124
		$pdf->addPage();
115
		$pdf->addPage();
125
		$pdf->setFont('Times', '' , 12);
116
		$pdf->setFont('Times', '' , 12);
Line 126... Line 117...
126
 
117
 
127
		$i=1;
118
		$i = 1;
Line 128... Line 119...
128
	    $tempfn = tempnam("","");
119
		$tempfn = tempnam('', '');
129
 
-
 
130
		foreach ($observations as $obs) {
120
 
131
 
121
		foreach ($observations as $obs) {
132
		 	// Denullifiage
122
			// Denullifiage
133
			foreach($obs as $k=>$v) {
123
			foreach($obs as $k=>$v) {
134
				if (($v=="null") || ($v=="000null")) {
-
 
135
					$obs[$k]="";
124
				if (($v == 'null') || ($v == '000null')) {
136
				}
125
					$obs[$k] = '';
137
				else {
126
				} else {
138
					$obs[$k]=utf8_decode($v);
127
					$obs[$k] = utf8_decode($v);
Line 139... Line 128...
139
				}
128
				}
140
			}
129
			}
141
 
130
 
142
		  	if ($obs['date_observation']!="0000-00-00 00:00:00") {
131
			if ($obs['date_observation'] != '0000-00-00 00:00:00') {
143
                list($year,$month,$day)= explode('-',$obs['date_observation']);
-
 
144
	            list($day)= explode(' ',$day);
132
				list($year,$month,$day)= explode('-', $obs['date_observation']);
145
                $obs['date_observation']=$day."/".$month."/".$year;
133
				list($day)= explode(' ', $day);
146
        	}
134
				$obs['date_observation'] = "$day/$month/$year";
147
        	else {
135
			} else {
148
                $obs['date_observation']="00/00/0000";
136
				$obs['date_observation'] = '00/00/0000';
149
        	}
137
			}
150
 
138
 
Line 151... Line 139...
151
            $text= $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
139
			$text = $obs['nom_sel']." ".$obs['nom_sel_nn']." ".$obs['nom_ret']." ".$obs['nom_ret_nn']." ".$obs['nt']." ".
Line 152... Line 140...
152
            $obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
140
				$obs['famille']." ".$obs['zone_geo']." ".$obs['ce_zone_geo']." ".$obs['date_observation']." ".$obs['station'];
153
            $obs['commentaire'];
-
 
154
 
141
				$obs['commentaire'];
155
			$pdf->write(10, $text."\n");
-
 
156
 
-
 
157
			$projet_photo = 'photoflora';
142
 
158
 
-
 
159
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
143
			$pdf->write(10, $text."\n");
160
 
144
 
161
 
145
			$projet_photo = 'photoflora';
162
	      	$url_miniature ='';
146
			$tab_retour[$projet_photo] = $this->analyserRdf(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
163
 
147
			$url_miniature = '';
Line 164... Line 148...
164
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
148
			foreach ($tab_retour[$projet_photo] as $cle => $illustration) {
165
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
149
				if (preg_match(EF_URL_PHOTOFLORA_REGEXP, $illustration['about'], $match)) {
166
				$abreviation = $match[1];
150
					$abreviation = $match[1];
167
				$fichier = $match[2];
151
					$fichier = $match[2];
168
		      	$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
152
					$url_miniature = sprintf(EF_URL_PHOTOFLORA_IMG_MIN, $abreviation, $fichier);;
169
 
153
 
Line 170... Line 154...
170
				// Priorite aux images en png
154
					// Priorite aux images en png
171
					if (strstr($fichier, '.png')) {
155
					if (strstr($fichier, '.png')) {
172
						break;
156
						break;
173
					}
157
					}
174
				}
158
				}
175
			}
159
			}
176
 
160
 
177
			if ($url_miniature!='') {
161
			if ($url_miniature != '') {
178
				list($debut,$ext)=explode("\.",basename($url_miniature));
-
 
179
       		    $temp = fopen($tempfn, "w");
162
				list($debut,$ext)=explode('\.',basename($url_miniature));
180
				$buf=file_get_contents($url_miniature);
163
				$temp = fopen($tempfn, 'w');
181
				fwrite($temp,$buf);
-
 
182
    			fclose($temp);
164
				$buf=file_get_contents($url_miniature);
183
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
165
				fwrite($temp,$buf);
184
			}
-
 
185
 
-
 
186
            $i++;
-
 
187
	    }
-
 
188
 
-
 
189
		echo $pdf->output("Rapport");
-
 
Line 190... Line 166...
190
	}
166
				fclose($temp);
191
}
-
 
192
 
167
				$pdf->image($tempfn, 10, ($i*10), 0, 0, $ext);
193
function chercherIllustrationsServiceXml($url)
168
			}
194
{
169
			$i++;
195
		return  analyserFichierRdf($url);
170
		}
196
}
171
		echo $pdf->output('Rapport');
Line 227... Line 202...
227
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
202
			$aso_info['dcterms:dateSubmitted'] = utf8_decode($rdf_description->getAttribute('dateSubmitted'));
228
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
203
			$aso_info['dcterms:spatial'] = utf8_decode($rdf_description->getAttribute('spatial'));
229
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
204
			$aso_info['dcterms:licence'] = utf8_decode($rdf_description->getAttribute('licence'));
230
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
205
			$tab_infos[$rdf_description->getAttribute('identifier')] = $aso_info;
231
		}
206
		}
232
 
-
 
233
		return $tab_infos;
207
		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
*/
-
 
248
?>
-
 
249
208
	}
-
 
209
}
-
 
210
250
211