Subversion Repositories eFlore/Applications.cel

Rev

Rev 2450 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2450 Rev 2458
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
 
-
 
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.*/
18
define('EF_URL_PHOTOFLORA_TAXON', EF_URL_PHOTOFLORA.'FiTax.php?NumTaxon=%s');
22
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.*/
23
/** 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');
24
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.*/
25
/** 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');
26
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.*/
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');
27
 
-
 
28
/**
-
 
29
* InventoryPDF.php
-
 
30
*
-
 
31
* in : utf8
-
 
32
* out : iso8859
-
 
33
*
-
 
34
* Formatage pdf d'un releve (a revoir)
-
 
35
*/
31
 
36
class InventoryPDF extends Cel  {
32
class InventoryPDF extends Cel  {
37
 
33
 
38
	var $extendPDFProductor;
34
	var $extendPDFProductor;
39
 
35
 
40
	function InventoryPDF($config) {
-
 
41
 
36
	public function __construct($config) {
42
		parent::__construct($config);
37
		parent::__construct($config);
43
 
38
 
44
		$this->config=$config;
39
		$this->config = $config;
45
		// Pas d'heritage multiple en php :(
40
		// Pas d'heritage multiple en php :(
46
		$this->extendPDFProductor = new PDFProductor();
41
		$this->extendPDFProductor = new PDFProductor();
47
		$this->extendPDFProductor->initPDF();
42
		$this->extendPDFProductor->initPDF();
48
	}
43
	}
49
 
44
 
50
	/**
45
	/**
51
	* uid[0] : utilisateur obligatoire
46
	* uid[0] : utilisateur obligatoire
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]);
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]).' ';
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 {
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].'%').
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';
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.
103
        		$requete_libre.
94
			$requete_libre.
104
         		$requete_station.
95
			$requete_station.' '.
105
          		" ORDER BY ordre ";
96
			'ORDER BY ordre '.
106
 
97
			' -- '.__FILE__.':'.__LINE__;
107
		$resultat_requete = Cel::db()->requeter($requete);
98
		$resultat = Cel::db()->requeter($requete);
108
 
99
 
109
		$observations = array();;
100
		$observations = array();;
110
		if(is_array($resultat_requete)) {
101
		if (is_array($resultat)) {
111
			$observations = $resultat_requete;
102
			$observations = $resultat;
112
		}
103
		}
113
 
104
 
114
		// Set up the pdf object.
105
		// Set up the pdf object.
115
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
106
		$pdf = &File_PDF::factory(array('orientation' => 'P', 'format' => 'A4'));
116
		// DesActivate compression.
107
		// DesActivate compression.
117
		$pdf->setCompression(false);
108
		$pdf->setCompression(false);
118
		$pdf->setMargins(0, 0);
109
		$pdf->setMargins(0, 0);
119
		// Enable automatic page breaks.
110
		// Enable automatic page breaks.
120
		$pdf->setAutoPageBreak(true);
111
		$pdf->setAutoPageBreak(true);
121
		// Start the document.
112
		// Start the document.
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);
126
 
117
 
127
		$i=1;
118
		$i = 1;
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);
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']);
132
				list($year,$month,$day)= explode('-', $obs['date_observation']);
144
	            list($day)= explode(' ',$day);
133
				list($day)= explode(' ', $day);
145
                $obs['date_observation']=$day."/".$month."/".$year;
-
 
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
 
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']." ".
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'];
141
				$obs['commentaire'];
154
 
142
 
155
			$pdf->write(10, $text."\n");
143
			$pdf->write(10, $text."\n");
156
 
144
 
157
			$projet_photo = 'photoflora';
145
			$projet_photo = 'photoflora';
158
 
-
 
159
			$tab_retour[$projet_photo]=chercherIllustrationsServiceXml(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
146
			$tab_retour[$projet_photo] = $this->analyserRdf(sprintf(EF_URL_PHOTOFLORA_SERVICE, $obs['nt']));
160
 
-
 
161
 
-
 
162
	      	$url_miniature ='';
147
			$url_miniature = '';
163
 
-
 
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
 
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));
162
				list($debut,$ext)=explode('\.',basename($url_miniature));
179
       		    $temp = fopen($tempfn, "w");
163
				$temp = fopen($tempfn, 'w');
180
				$buf=file_get_contents($url_miniature);
164
				$buf=file_get_contents($url_miniature);
181
				fwrite($temp,$buf);
165
				fwrite($temp,$buf);
182
    			fclose($temp);
166
				fclose($temp);
183
				$pdf->image($tempfn,10,($i*10),0,0,$ext);
167
				$pdf->image($tempfn, 10, ($i*10), 0, 0, $ext);
184
			}
-
 
185
 
168
			}
186
            $i++;
169
			$i++;
187
	    }
-
 
188
 
170
		}
189
		echo $pdf->output("Rapport");
171
		echo $pdf->output('Rapport');
190
	}
-
 
191
}
-
 
192
 
-
 
193
function chercherIllustrationsServiceXml($url)
-
 
194
{
-
 
195
		return  analyserFichierRdf($url);
-
 
196
}
172
	}
197
 
-
 
198
function analyserFichierRdf($chemin)
173
 
199
{
174
	private function analyserRdf($chemin) {
200
		$aso_info = array();
175
		$aso_info = array();
201
		$dom = new DOMDocument();
176
		$dom = new DOMDocument();
202
		$dom->validateOnParse = true;
177
		$dom->validateOnParse = true;
203
		if (preg_match('/^http:\/\//', $chemin)) {
178
		if (preg_match('/^http:\/\//', $chemin)) {
204
			$dom->loadXML(file_get_contents($chemin));
179
			$dom->loadXML(file_get_contents($chemin));
205
		} else {
180
		} else {
206
			$dom->load($chemin);
181
			$dom->load($chemin);
207
		}
182
		}
208
 
183
 
209
		$tab_infos = array();
184
		$tab_infos = array();
210
		foreach ($dom->getElementsByTagNameNS('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'Description') as $rdf_description) {
185
		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');
186
			$aso_info['about'] = $rdf_description->getAttribute('about');
212
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
187
			$aso_info['dc:identifier'] = $rdf_description->getAttribute('identifier');
213
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
188
			$aso_info['dc:title'] = utf8_decode($rdf_description->getAttribute('title'));
214
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
189
			$aso_info['dc:creator'] = utf8_decode($rdf_description->getAttribute('creator'));
215
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
190
			$aso_info['dc:contributor'] = utf8_decode($rdf_description->getAttribute('contributor'));
216
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
191
			$aso_info['dc:publisher'] = utf8_decode($rdf_description->getAttribute('publisher'));
217
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
192
			$aso_info['dc:type'] = utf8_decode($rdf_description->getAttribute('type'));
218
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
193
			$aso_info['dc:format'] = utf8_decode($rdf_description->getAttribute('format'));
219
			if (function_exists('date_default_timezone_set')) {
194
			if (function_exists('date_default_timezone_set')) {
220
				date_default_timezone_set('Europe/Paris');
195
				date_default_timezone_set('Europe/Paris');
221
			}
196
			}
222
			if (preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/', $rdf_description->getAttribute('created'))) {
197
			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')));
198
				$aso_info['dcterms:created'] = date('j-m-Y � H:i:s', strtotime($rdf_description->getAttribute('created')));
224
			} else {
199
			} else {
225
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
200
				$aso_info['dcterms:created'] = $rdf_description->getAttribute('created');
226
			}
201
			}
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