Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2272 Rev 2394
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * Format du service :
6
 * Format du service :
7
 * /CelSyndicationObservation/liste-des-flux
7
 * /CelSyndicationObservation/liste-des-flux
8
 * /CelSyndicationObservation/opml
8
 * /CelSyndicationObservation/opml
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
13
 *
13
 *
14
 * Les paramêtres :
14
 * Les paramêtres :
15
 *  - "start" indique le numéro du premier item à afficher
15
 *  - "start" indique le numéro du premier item à afficher
16
 *  - "limit" nombre d'items à afficher
16
 *  - "limit" nombre d'items à afficher
17
 *
17
 *
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright 2010
22
 * @copyright 2010
23
 */
23
 */
24
class CelSyndicationObservation extends Cel {
24
class CelSyndicationObservation extends Cel {
25
 
25
 
26
	private $parametres_origines = null;
26
	private $parametres_origines = null;
27
	private $format = null;
27
	private $format = null;
28
	private $service = null;
28
	private $service = null;
29
	private $squelette = null;
29
	private $squelette = null;
30
	private $squelette_dossier = null;
30
	private $squelette_dossier = null;
31
	private $auteurs = array();
31
	private $auteurs = array();
32
	private $flux = array();
32
	private $flux = array();
33
	private $criteres = array(
33
	private $criteres = array(
34
		'utilisateur' => 'courriel_utilisateur',
34
		'utilisateur' => 'courriel_utilisateur',
35
		'commune' => 'zone_geo',
35
		'commune' => 'zone_geo',
36
		'dept' => 'ce_zone_geo',
36
		'dept' => 'ce_zone_geo',
37
		'taxon' => 'nom_ret',
37
		'taxon' => 'nom_ret',
38
		'num_taxon' => 'nt',
38
		'num_taxon' => 'nt',
39
		'commentaire' => 'commentaire',
39
		'commentaire' => 'commentaire',
40
		'date' => 'date_observation',
40
		'date' => 'date_observation',
41
		'motcle' => 'tags',
41
		'motcle' => 'tags',
42
		'projet' => 'mots-cles');
42
		'projet' => 'mots-cles');
-
 
43
	private $catalogue_cles_labels_champs_etendus = array();
43
 
44
 
44
	/**
45
	/**
45
	 * Méthode appelée avec une requête de type GET.
46
	 * Méthode appelée avec une requête de type GET.
46
	 */
47
	 */
47
	public function getElement($params = array()) {
48
	public function getElement($params = array()) {
48
		// Initialisation des variables
49
		// Initialisation des variables
49
		$this->parametres_origines = $params;
50
		$this->parametres_origines = $params;
50
		$info = array();
51
		$info = array();
51
		$contenu = '';
52
		$contenu = '';
52
 
53
 
53
		if (! $this->etreFluxAdmin() || $this->authentifierAdmin()) {
54
		if (! $this->etreFluxAdmin() || $this->authentifierAdmin()) {
54
			// Pré traitement des paramêtres
55
			// Pré traitement des paramêtres
55
			$pour_bdd = false;
56
			$pour_bdd = false;
56
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
57
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
57
			extract($p);
58
			extract($p);
58
			$this->parametres = $params;
59
			$this->parametres = $params;
59
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
60
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
60
 
61
 
61
			// Récupération de la liste des flux
62
			// Récupération de la liste des flux
62
			$this->chargerListeDesFlux();
63
			$this->chargerListeDesFlux();
63
 
64
 
64
			// Chargement du bon type de service demandé
65
			// Chargement du bon type de service demandé
65
			if (isset($service)) {
66
			if (isset($service)) {
66
				$this->service = $this->traiterNomService($service);
67
				$this->service = $this->traiterNomService($service);
67
				$methode = $this->getNomMethodeService();
68
				$methode = $this->getNomMethodeService();
68
				if (method_exists($this, $methode)) {
69
				if (method_exists($this, $methode)) {
69
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
70
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
70
						// Mise en minuscule de l'indication du format
71
						// Mise en minuscule de l'indication du format
71
						$this->format = strtolower($format);
72
						$this->format = strtolower($format);
72
						// Définition du fichier squelette demandé
73
						// Définition du fichier squelette demandé
73
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
74
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
74
					} else if (isset($this->flux[$this->service])) {
75
					} else if (isset($this->flux[$this->service])) {
75
						$this->format = '';
76
						$this->format = '';
76
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
77
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
77
					}
78
					}
78
 
79
 
79
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
80
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
80
						// Suppression des paramêtres inutile pour le reste des méthodes
81
						// Suppression des paramêtres inutile pour le reste des méthodes
81
						array_shift($this->parametres);
82
						array_shift($this->parametres);
82
						array_shift($this->parametres);
83
						array_shift($this->parametres);
83
 
84
 
84
						// Récupération du contenu à renvoyer
85
						// Récupération du contenu à renvoyer
85
						$contenu = $this->$methode();
86
						$contenu = $this->$methode();
86
					}
87
					}
87
				} else {
88
				} else {
88
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
89
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
89
				}
90
				}
90
			} else {
91
			} else {
91
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
92
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
92
			}
93
			}
93
		}
94
		}
94
 
95
 
95
		// Envoie sur la sortie standard
96
		// Envoie sur la sortie standard
96
		$encodage = 'utf-8';
97
		$encodage = 'utf-8';
97
		$mime = $this->getTypeMime();
98
		$mime = $this->getTypeMime();
98
		$formatage_json = $this->getFormatageJson();
99
		$formatage_json = $this->getFormatageJson();
99
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
100
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
100
	}
101
	}
101
 
102
 
102
	private function getUrlBase() {
103
	private function getUrlBase() {
103
		$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
104
		$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
104
		return $url_base;
105
		return $url_base;
105
	}
106
	}
106
 
107
 
107
	private function getUrlServiceBase() {
108
	private function getUrlServiceBase() {
108
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
109
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
109
		return $url_service;
110
		return $url_service;
110
	}
111
	}
111
 
112
 
112
	private function traiterNomService($nom) {
113
	private function traiterNomService($nom) {
113
		$nom = strtolower($nom);
114
		$nom = strtolower($nom);
114
		return $nom;
115
		return $nom;
115
	}
116
	}
116
 
117
 
117
	private function getNomMethodeService() {
118
	private function getNomMethodeService() {
118
		$methode = '';
119
		$methode = '';
119
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
120
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
120
		$methode = 'getService'.$service_formate;
121
		$methode = 'getService'.$service_formate;
121
		return $methode;
122
		return $methode;
122
	}
123
	}
123
 
124
 
124
	private function getTypeMime() {
125
	private function getTypeMime() {
125
		$mime = '';
126
		$mime = '';
126
		$test = isset($this->format) ? $this->format : $this->service;
127
		$test = isset($this->format) ? $this->format : $this->service;
127
		switch ($test) {
128
		switch ($test) {
128
			case 'atom' :
129
			case 'atom' :
129
				$mime = 'application/atom+xml';
130
				$mime = 'application/atom+xml';
130
				break;
131
				break;
131
			case 'rss1' :
132
			case 'rss1' :
132
			case 'rss2' :
133
			case 'rss2' :
133
				$mime = 'application/rss+xml';
134
				$mime = 'application/rss+xml';
134
				break;
135
				break;
135
			case 'opml' :
136
			case 'opml' :
136
				$mime = 'text/x-opml';
137
				$mime = 'text/x-opml';
137
				break;
138
				break;
138
			default:
139
			default:
139
				$mime = 'text/html';
140
				$mime = 'text/html';
140
		}
141
		}
141
		return $mime;
142
		return $mime;
142
	}
143
	}
143
 
144
 
144
	private function getFormatageJson() {
145
	private function getFormatageJson() {
145
		$json = false;
146
		$json = false;
146
		switch ($this->service) {
147
		switch ($this->service) {
147
			case 'liste-des-flux' :
148
			case 'liste-des-flux' :
148
				$json = true;
149
				$json = true;
149
				break;
150
				break;
150
			default:
151
			default:
151
				$json = false;
152
				$json = false;
152
		}
153
		}
153
		return $json;
154
		return $json;
154
	}
155
	}
155
 
156
 
156
	private function getFlux($nom) {
157
	private function getFlux($nom) {
157
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
158
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
158
	}
159
	}
159
 
160
 
160
	private function setFlux($nom, $titre, $description) {
161
	private function setFlux($nom, $titre, $description) {
161
		$url_base = $this->getUrlBase();
162
		$url_base = $this->getUrlBase();
162
		$formats = array('atom', 'rss2', 'rss1');
163
		$formats = array('atom', 'rss2', 'rss1');
163
		$flux = array();
164
		$flux = array();
164
		foreach ($formats as $format) {
165
		foreach ($formats as $format) {
165
			$url = $url_base.$nom.'/'.$format;
166
			$url = $url_base.$nom.'/'.$format;
166
			$flux[$format] = $url;
167
			$flux[$format] = $url;
167
		}
168
		}
168
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
169
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
169
	}
170
	}
170
 
171
 
171
	private function chargerListeDesFlux() {
172
	private function chargerListeDesFlux() {
172
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL',
173
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL',
173
			'Ce flux fournit des informations sur les observations du CEL.');
174
			'Ce flux fournit des informations sur les observations du CEL.');
174
		$this->setFlux('par-mots-cles', 'Flux de syndication obsolète',
175
		$this->setFlux('par-mots-cles', 'Flux de syndication obsolète',
175
			"Ce flux est désormais accessible via le flux multicriteres/atom/M?tag='mot-cle'.");
176
			"Ce flux est désormais accessible via le flux multicriteres/atom/M?tag='mot-cle'.");
176
		$this->setFlux('par-commune','Flux de syndication obsolète',
177
		$this->setFlux('par-commune','Flux de syndication obsolète',
177
			"Ce flux  est désormais accessible via le flux multicriteres/atom/M?commune='commune'.");
178
			"Ce flux  est désormais accessible via le flux multicriteres/atom/M?commune='commune'.");
178
		$this->setFlux('multicriteres','Flux de syndication des nouvelles observations publiques du CEL '.
179
		$this->setFlux('multicriteres','Flux de syndication des nouvelles observations publiques du CEL '.
179
			'filtrées par un ou plusieurs critères',
180
			'filtrées par un ou plusieurs critères',
180
			"Ce flux fournit des informations sur les nouvelles observations du CEL filtrées par ".
181
			"Ce flux fournit des informations sur les nouvelles observations du CEL filtrées par ".
181
			"auteur (mail), commune (nom), departement (code postal), taxon (nom scientifique), commentaire, projet ".
182
			"auteur (mail), commune (nom), departement (code postal), taxon (nom scientifique), commentaire, projet ".
182
			"et/ou date.");
183
			"et/ou date.");
183
	}
184
	}
184
 
185
 
185
	private function getServiceListeDesFlux() {
186
	private function getServiceListeDesFlux() {
186
		return $this->flux;
187
		return $this->flux;
187
	}
188
	}
188
 
189
 
189
	private function getServiceOpml() {
190
	private function getServiceOpml() {
190
		$donnees = array();
191
		$donnees = array();
191
		$id = 1;
192
		$id = 1;
192
		foreach ($this->flux as $flux_nom => $flux){
193
		foreach ($this->flux as $flux_nom => $flux){
193
			$info = array();
194
			$info = array();
194
			$info['type'] = 'atom';
195
			$info['type'] = 'atom';
195
			$info['titre'] = $flux['titre'];
196
			$info['titre'] = $flux['titre'];
196
			$info['texte'] = "CEL - Obs - $flux_nom";
197
			$info['texte'] = "CEL - Obs - $flux_nom";
197
			$info['description'] = $flux['description'];
198
			$info['description'] = $flux['description'];
198
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
199
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
199
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
200
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
200
			$donnees['liste_flux'][] = $info;
201
			$donnees['liste_flux'][] = $info;
201
		}
202
		}
202
 
203
 
203
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
204
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
204
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
205
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
205
		return $contenu;
206
		return $contenu;
206
	}
207
	}
207
 
208
 
208
	private function getServiceParDefaut() {
209
	private function getServiceParDefaut() {
209
		// Construction de la requête
210
		// Construction de la requête
210
		$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
211
		$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
211
			'FROM cel_obs '.
212
			'FROM cel_obs '.
212
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
213
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
213
			'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
214
			'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
214
			"LIMIT $this->start,$this->limit ";
215
			"LIMIT $this->start,$this->limit ";
215
 
216
 
216
		$elements = Cel::db()->requeter($requete);
217
		$elements = Cel::db()->requeter($requete);
217
 
218
 
218
		// Création du contenu
219
		// Création du contenu
219
		$contenu = $this->executerService($elements);
220
		$contenu = $this->executerService($elements);
220
		return $contenu;
221
		return $contenu;
221
	}
222
	}
222
 
223
 
223
	private function getServiceParMotsCles() {
224
	private function getServiceParMotsCles() {
224
		$infos=array();
225
		$infos=array();
225
		$infos[0]['nom_sel_nn'] = '';
226
		$infos[0]['nom_sel_nn'] = '';
226
		$infos[0]['date_modification'] = '2011-06-28';
227
		$infos[0]['date_modification'] = '2011-06-28';
227
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
228
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
228
		$donnees['items'][0]['guid'] = 0;
229
		$donnees['items'][0]['guid'] = 0;
229
		$donnees['items'][0]['description'] =  'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
230
		$donnees['items'][0]['description'] =  'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
230
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?projet=';
231
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?projet=';
231
		if (isset($this->parametres[0])) {
232
		if (isset($this->parametres[0])) {
232
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
233
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
233
		} else {
234
		} else {
234
			$donnees['items'][0]['description'] .= '</b>';
235
			$donnees['items'][0]['description'] .= '</b>';
235
		}
236
		}
236
		$donnees['items'][0]['titre'] = '';
237
		$donnees['items'][0]['titre'] = '';
237
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
238
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
238
		return $contenu;
239
		return $contenu;
239
	}
240
	}
240
 
241
 
241
	private function getServiceParCommune() {
242
	private function getServiceParCommune() {
242
		$infos=array();
243
		$infos=array();
243
		$infos[0]['nom_sel_nn'] = '';
244
		$infos[0]['nom_sel_nn'] = '';
244
		$infos[0]['date_modification'] = '2011-06-28';
245
		$infos[0]['date_modification'] = '2011-06-28';
245
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
246
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
246
		$donnees['items'][0]['guid'] = 0;
247
		$donnees['items'][0]['guid'] = 0;
247
		$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
248
		$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
248
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?commune=';
249
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?commune=';
249
		if (isset($this->parametres[0])) {
250
		if (isset($this->parametres[0])) {
250
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
251
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
251
		} else {
252
		} else {
252
			$donnees['items'][0]['description'] .= '</b>';
253
			$donnees['items'][0]['description'] .= '</b>';
253
		}
254
		}
254
		$donnees['items'][0]['titre'] = '';
255
		$donnees['items'][0]['titre'] = '';
255
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
256
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
256
		return $contenu;
257
		return $contenu;
257
	}
258
	}
258
 
259
 
259
	private function getServiceMultiCriteres() {
260
	private function getServiceMultiCriteres() {
260
		$contenu = '';
261
		$contenu = '';
261
		if (isset($_GET['debut'])) $this->start = $_GET['debut'];
262
		if (isset($_GET['debut'])) $this->start = $_GET['debut'];
262
		if (isset($_GET['limite'])) $this->limit = $_GET['limite'];
263
		if (isset($_GET['limite'])) $this->limit = $_GET['limite'];
263
 
264
 
264
		$this->limit = ($this->limit < 1000) ? $this->limit : 1000;// Pour éviter les abus !
265
		$this->limit = ($this->limit < 1000) ? $this->limit : 1000;// Pour éviter les abus !
265
 
266
 
266
		// Construction de la requête
267
		// Construction de la requête
267
		$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
268
		$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
268
				'FROM cel_obs '.
269
				'FROM cel_obs '.
269
				'WHERE 1 AND '.(($this->etreFluxAdmin()) ? '' : ' transmission = 1 AND ');
270
				'WHERE 1 AND '.(($this->etreFluxAdmin()) ? '' : ' transmission = 1 AND ');
270
 
271
 
271
		if ($this->estUneRechercheGenerale()) {
272
		if ($this->estUneRechercheGenerale()) {
272
			$chaine_requete = $_GET['recherche'];
273
			$chaine_requete = $_GET['recherche'];
273
			$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
274
			$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
274
		} else {
275
		} else {
275
			$criteres = $this->traiterCriteresMultiples($_GET) ;
276
			$criteres = $this->traiterCriteresMultiples($_GET) ;
276
			if (!empty($criteres)) {
277
			if (!empty($criteres)) {
277
				$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
278
				$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
278
			}
279
			}
279
		}
280
		}
280
		$requete = rtrim($requete, 'AND ');
281
		$requete = rtrim($requete, 'AND ');
281
		$requete .= ' ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  :
282
		$requete .= ' ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  :
282
			'date_modification DESC, zone_geo ASC').' '.
283
			'date_modification DESC, zone_geo ASC').' '.
283
				"LIMIT $this->start,$this->limit ";
284
				"LIMIT $this->start,$this->limit ";
284
 
285
 
285
		$elements = Cel::db()->requeter($requete);
286
		$elements = Cel::db()->requeter($requete);
286
 
287
 
287
		// Création du contenu
288
		// Création du contenu
288
		if ($elements != false && count($elements) > 0) {
289
		if ($elements != false && count($elements) > 0) {
289
			$contenu = $this->executerService($elements);
290
			$contenu = $this->executerService($elements);
290
		} else {
291
		} else {
291
			$this->messages[] = "Aucune observation disponible.";
292
			$this->messages[] = "Aucune observation disponible.";
292
		}
293
		}
293
 
294
 
294
        return $contenu;
295
        return $contenu;
295
	}
296
	}
296
 
297
 
297
	private function creerSousRequeteRechercheParCriteres($criteres) {
298
	private function creerSousRequeteRechercheParCriteres($criteres) {
298
		$requete = '';
299
		$requete = '';
299
		foreach ($criteres as $pair) {
300
		foreach ($criteres as $pair) {
300
			$nom_valeur = explode("=",$pair);
301
			$nom_valeur = explode("=",$pair);
301
			if (sizeof($nom_valeur) != 0) {
302
			if (sizeof($nom_valeur) != 0) {
302
				switch ($nom_valeur[0]) {
303
				switch ($nom_valeur[0]) {
303
					case "ci_limite" : $this->limit = Cel::db()->quote($nom_valeur[1]); break;
304
					case "ci_limite" : $this->limit = Cel::db()->quote($nom_valeur[1]); break;
304
					case "commentaire" : $mots_comment_liste = explode(" " , $nom_valeur[1]);
305
					case "commentaire" : $mots_comment_liste = explode(" " , $nom_valeur[1]);
305
						foreach($mots_comment_liste as $mot_comment) {
306
						foreach($mots_comment_liste as $mot_comment) {
306
							$mot_comment = trim($mot_comment) ;
307
							$mot_comment = trim($mot_comment) ;
307
							$requete .= $nom_valeur[0].' LIKE '.Cel::db()->quote('%'.$mot_comment.'%').' AND ';
308
							$requete .= $nom_valeur[0].' LIKE '.Cel::db()->quote('%'.$mot_comment.'%').' AND ';
308
						}
309
						}
309
						break;
310
						break;
310
					case "date_observation" :
311
					case "date_observation" :
311
						$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
312
						$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
312
						if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
313
						if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
313
							$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
314
							$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
314
						}
315
						}
315
						$requete .= $nom_valeur[0].'='.Cel::db()->quote($nom_valeur[1]).' AND '; break;
316
						$requete .= $nom_valeur[0].'='.Cel::db()->quote($nom_valeur[1]).' AND '; break;
316
					case "ce_zone_geo" :
317
					case "ce_zone_geo" :
317
						$requete .= ' ('.$nom_valeur[0].' LIKE "INSEE-C:'.$nom_valeur[1].'%") AND '; break;
318
						$requete .= ' ('.$nom_valeur[0].' LIKE "INSEE-C:'.$nom_valeur[1].'%") AND '; break;
318
					case "nom_ret" :
319
					case "nom_ret" :
319
						if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';
320
						if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';
320
						$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
321
						$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
321
							$nom_valeur[1].'%") AND '; break;
322
							$nom_valeur[1].'%") AND '; break;
322
					case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]).' AND '; break;
323
					case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]).' AND '; break;
323
					case "tags" : $requete .= $this->creerSousRequeteTags($nom_valeur[1]).' AND '; break;
324
					case "tags" : $requete .= $this->creerSousRequeteTags($nom_valeur[1]).' AND '; break;
324
					default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
325
					default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
325
				}
326
				}
326
			}
327
			}
327
		}
328
		}
328
		$requete = rtrim($requete,' AND ');
329
		$requete = rtrim($requete,' AND ');
329
		return $requete;
330
		return $requete;
330
	}
331
	}
331
 
332
 
332
	private function creerSousRequeteMotsCles($mot_cle) {
333
	private function creerSousRequeteMotsCles($mot_cle) {
333
		$requete = '';
334
		$requete = '';
334
		if (preg_match('/.*OU.*/', $mot_cle)) {
335
		if (preg_match('/.*OU.*/', $mot_cle)) {
335
			$mots_cles_tab = explode('OU',$mot_cle);
336
			$mots_cles_tab = explode('OU',$mot_cle);
336
			foreach($mots_cles_tab as $mot_cle_item) {
337
			foreach($mots_cles_tab as $mot_cle_item) {
337
				$requete .= '(mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') OR ';
338
				$requete .= '(mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') OR ';
338
			}
339
			}
339
			$requete = '('.rtrim($requete,'OR ').') ';
340
			$requete = '('.rtrim($requete,'OR ').') ';
340
		} else if (preg_match('/.*ET.*/', $mot_cle)) {
341
		} else if (preg_match('/.*ET.*/', $mot_cle)) {
341
			$mots_cles_tab = explode('ET',$mot_cle);
342
			$mots_cles_tab = explode('ET',$mot_cle);
342
			foreach($mots_cles_tab as $mot_cle_item) {
343
			foreach($mots_cles_tab as $mot_cle_item) {
343
				$requete .= '(mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') AND ';
344
				$requete .= '(mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') AND ';
344
			}
345
			}
345
			$requete = '('.rtrim($requete, 'AND ').') ';
346
			$requete = '('.rtrim($requete, 'AND ').') ';
346
		} else {
347
		} else {
347
			$requete = "(mots_cles_texte LIKE ".Cel::db()->proteger('%'.$mot_cle.'%').') ';
348
			$requete = "(mots_cles_texte LIKE ".Cel::db()->proteger('%'.$mot_cle.'%').') ';
348
		}
349
		}
349
		return $requete;
350
		return $requete;
350
	}
351
	}
351
 
352
 
352
	private function creerSousRequeteTags($tag) {
353
	private function creerSousRequeteTags($tag) {
353
		$requete = '(id_observation IN (SELECT id_observation FROM cel_obs_images coi INNER JOIN cel_images ci ON coi.id_image = ci.id_image WHERE ';
354
		$requete = '(id_observation IN (SELECT id_observation FROM cel_obs_images coi INNER JOIN cel_images ci ON coi.id_image = ci.id_image WHERE ';
354
		$where = '';
355
		$where = '';
355
		if (preg_match('/.*OU.*/', $tag)) {
356
		if (preg_match('/.*OU.*/', $tag)) {
356
			$mots_cles_tab = explode('OU',$tag);
357
			$mots_cles_tab = explode('OU',$tag);
357
			foreach($mots_cles_tab as $mot_cle_item) {
358
			foreach($mots_cles_tab as $mot_cle_item) {
358
				$where .= '(ci.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') OR ';
359
				$where .= '(ci.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') OR ';
359
			}
360
			}
360
			$where .= '('.rtrim($where,'OR ').') ';
361
			$where .= '('.rtrim($where,'OR ').') ';
361
		} else if (preg_match('/.*ET.*/', $tag)) {
362
		} else if (preg_match('/.*ET.*/', $tag)) {
362
			$mots_cles_tab = explode('ET',$tag);
363
			$mots_cles_tab = explode('ET',$tag);
363
			foreach($mots_cles_tab as $mot_cle_item) {
364
			foreach($mots_cles_tab as $mot_cle_item) {
364
				$where .= '(ci.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') AND ';
365
				$where .= '(ci.mots_cles_texte LIKE '.Cel::db()->proteger('%'.$mot_cle_item.'%').') AND ';
365
			}
366
			}
366
			$where .= '('.rtrim($where, 'AND ').') ';
367
			$where .= '('.rtrim($where, 'AND ').') ';
367
		} else {
368
		} else {
368
			$where .= "(ci.mots_cles_texte LIKE ".Cel::db()->proteger('%'.$tag.'%').') ';
369
			$where .= "(ci.mots_cles_texte LIKE ".Cel::db()->proteger('%'.$tag.'%').') ';
369
		}
370
		}
370
		$requete .= $where.' ))';
371
		$requete .= $where.' ))';
371
		return $requete;
372
		return $requete;
372
	}
373
	}
373
 
374
 
374
	private function traiterCriteresMultiples($tableau_criteres) {
375
	private function traiterCriteresMultiples($tableau_criteres) {
375
		$tableau_criteres_pour_bdd = array();
376
		$tableau_criteres_pour_bdd = array();
376
 
377
 
377
		foreach($tableau_criteres as $nom_critere => $valeur_critere) {
378
		foreach($tableau_criteres as $nom_critere => $valeur_critere) {
378
			if (isset($this->criteres[$nom_critere])) {
379
			if (isset($this->criteres[$nom_critere])) {
379
				$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
380
				$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
380
			}
381
			}
381
		}
382
		}
382
		return $tableau_criteres_pour_bdd;
383
		return $tableau_criteres_pour_bdd;
383
	}
384
	}
384
 
385
 
385
	private function creerSousRequeteRechercheGenerale($chaine_requete) {
386
	private function creerSousRequeteRechercheGenerale($chaine_requete) {
386
		$requete = '';
387
		$requete = '';
387
		if (trim($chaine_requete) != '') {
388
		if (trim($chaine_requete) != '') {
388
			$chaine_requete = strtolower($chaine_requete);
389
			$chaine_requete = strtolower($chaine_requete);
389
			$chaine_requete = str_replace(' ', '_', $chaine_requete);
390
			$chaine_requete = str_replace(' ', '_', $chaine_requete);
390
			$requete = ' ('.
391
			$requete = ' ('.
391
				'nom_ret LIKE "'.$chaine_requete.'%"'.
392
				'nom_ret LIKE "'.$chaine_requete.'%"'.
392
				' OR '.
393
				' OR '.
393
				'nom_sel LIKE "'.$chaine_requete.'%"'.
394
				'nom_sel LIKE "'.$chaine_requete.'%"'.
394
				' OR '.
395
				' OR '.
395
				'zone_geo LIKE "'.$chaine_requete.'%" '.
396
				'zone_geo LIKE "'.$chaine_requete.'%" '.
396
				' OR '.
397
				' OR '.
397
				'ce_zone_geo LIKE "'.$chaine_requete.'%" '.
398
				'ce_zone_geo LIKE "'.$chaine_requete.'%" '.
398
				' OR '.
399
				' OR '.
399
				'ce_zone_geo LIKE "INSEE-C:'.$chaine_requete.'%" '.
400
				'ce_zone_geo LIKE "INSEE-C:'.$chaine_requete.'%" '.
400
				' OR '.
401
				' OR '.
401
				'courriel_utilisateur LIKE "'.$chaine_requete.'%" '.
402
				'courriel_utilisateur LIKE "'.$chaine_requete.'%" '.
402
				' OR '.
403
				' OR '.
403
				'mots_cles_texte LIKE "'.$chaine_requete.'%" '.
404
				'mots_cles_texte LIKE "'.$chaine_requete.'%" '.
404
				') ';
405
				') ';
405
		}
406
		}
406
		return $requete;
407
		return $requete;
407
	}
408
	}
408
 
409
 
409
	private function estUneRechercheGenerale() {
410
	private function estUneRechercheGenerale() {
410
		return isset($_GET['recherche']);
411
		return isset($_GET['recherche']);
411
	}
412
	}
412
 
413
 
413
	private function executerService($elements) {
414
	private function executerService($elements) {
414
		$contenu = '';
415
		$contenu = '';
415
		if (is_array($elements)) {
416
		if (is_array($elements)) {
416
			// Prétraitement des données
417
			// Prétraitement des données
417
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
418
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
418
			$ids_observations = array();
419
			$ids_observations = array();
419
			foreach ($elements as $element) {
420
			foreach ($elements as $element) {
420
				$identifiants[$element['courriel_utilisateur']] = $element['courriel_utilisateur'];
421
				$identifiants[$element['courriel_utilisateur']] = $element['courriel_utilisateur'];
421
				$ids_observations[] = $element['id_observation'];
422
				$ids_observations[] = $element['id_observation'];
422
			}
423
			}
423
			$gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
424
			$gestion_champs_etendus = new GestionChampsEtendus($this->config, 'obs');
424
			$champs_etendus = $gestion_champs_etendus->consulterParLots($ids_observations);
425
			$champs_etendus = $gestion_champs_etendus->consulterParLots($ids_observations);
-
 
426
			if(!empty($champs_etendus)) {
-
 
427
				$this->catalogue_cles_labels_champs_etendus = $gestion_champs_etendus->consulterCatalogueChampsEtendusPredefinis(true);
-
 
428
			}
425
			$this->auteurs = $this->creerAuteurs($identifiants);
429
			$this->auteurs = $this->creerAuteurs($identifiants);
426
			foreach ($elements as $element) {
430
			foreach ($elements as $element) {
427
				$element['obs_etendue'] = isset($champs_etendus[$element['id_observation']]) ? $champs_etendus[$element['id_observation']] : array();
431
				$element['obs_etendue'] = isset($champs_etendus[$element['id_observation']]) ? $champs_etendus[$element['id_observation']] : array();
428
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
432
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
429
			}
433
			}
430
 
434
 
431
			// Création du contenu à partir d'un template PHP
435
			// Création du contenu à partir d'un template PHP
432
			if (isset($this->squelette)) {
436
			if (isset($this->squelette)) {
433
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
437
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
434
			}
438
			}
435
		}
439
		}
436
		return $contenu;
440
		return $contenu;
437
	}
441
	}
438
 
442
 
439
	private function construireDonneesCommunesAuFlux($observations) {
443
	private function construireDonneesCommunesAuFlux($observations) {
440
		$donnees = $this->getFlux($this->service);
444
		$donnees = $this->getFlux($this->service);
441
		$donnees['guid'] = $this->getUrlServiceBase();
445
		$donnees['guid'] = $this->getUrlServiceBase();
442
		$donnees['titre'] = 'Flux des observations du CEL';
446
		$donnees['titre'] = 'Flux des observations du CEL';
443
		$donnees['lien_service'] = $this->creerUrlService();
447
		$donnees['lien_service'] = $this->creerUrlService();
444
		$donnees['lien_cel'] = $this->config['settings']['baseURLAbsolu'];
448
		$donnees['lien_cel'] = $this->config['settings']['baseURLAbsolu'];
445
		$donnees['editeur'] = $this->config['settings']['editeur'];
449
		$donnees['editeur'] = $this->config['settings']['editeur'];
446
		$derniere_info_en_date = reset($observations);
450
		$derniere_info_en_date = reset($observations);
447
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
451
		$date_modification_timestamp = strtotime($derniere_info_en_date['date_modification']);
448
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
452
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
449
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
453
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
450
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
454
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
451
		$donnees['annee_courante'] = date('Y');
455
		$donnees['annee_courante'] = date('Y');
452
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
456
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
453
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
457
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
454
		return $donnees;
458
		return $donnees;
455
	}
459
	}
456
 
460
 
457
	private function construireDonneesCommunesAuxItems($observation) {
461
	private function construireDonneesCommunesAuxItems($observation) {
458
		$item = array();
462
		$item = array();
459
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
463
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
460
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
464
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
461
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
465
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
462
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
466
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
463
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
467
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
464
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['date_creation']));
468
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['date_creation']));
465
		$item['titre'] = $this->creerTitre($observation);
469
		$item['titre'] = $this->creerTitre($observation);
466
		$item['guid'] = $this->creerGuidItem($observation);
470
		$item['guid'] = $this->creerGuidItem($observation);
467
		$item['lien'] = $this->creerLienItem($observation);
471
		$item['lien'] = $this->creerLienItem($observation);
468
		$item['categorie'] = $this->creerCategorie($item);
472
		$item['categorie'] = $this->creerCategorie($item);
469
		$item['description'] = $this->creerDescription(Cel::protegerCaracteresHtmlDansChamps($observation), $item);
473
		$item['description'] = $this->creerDescription(Cel::protegerCaracteresHtmlDansChamps($observation), $item);
470
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
474
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
471
		$item['modifier_par'] = $observation['id_observation'];
475
		$item['modifier_par'] = $observation['id_observation'];
472
		return $item;
476
		return $item;
473
	}
477
	}
474
 
478
 
475
	private function creerTitre($obs) {
479
	private function creerTitre($obs) {
476
		$date = ($obs['date_observation'] != '0000-00-00 00:00:00') ? 'le '.date("d/m/Y", strtotime($obs['date_observation'])) : '' ;
480
		$date = ($obs['date_observation'] != '0000-00-00 00:00:00') ? 'le '.date("d/m/Y", strtotime($obs['date_observation'])) : '' ;
477
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['nom_sel_nn'].']';
481
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['nom_sel_nn'].']';
478
		$lieu = $obs['zone_geo'].' ('.$obs['ce_zone_geo'].')';
482
		$lieu = $obs['zone_geo'].' ('.$obs['ce_zone_geo'].')';
479
		$utilisateur = $this->getIntituleAuteur($obs['courriel_utilisateur']);
483
		$utilisateur = $this->getIntituleAuteur($obs['courriel_utilisateur']);
480
		$titre = "$nom_plante à $lieu par $utilisateur $date";
484
		$titre = "$nom_plante à $lieu par $utilisateur $date";
481
		$titre = $this->nettoyerTexte($titre);
485
		$titre = $this->nettoyerTexte($titre);
482
		return $titre;
486
		return $titre;
483
	}
487
	}
484
 
488
 
485
	private function creerGuidItem($element) {
489
	private function creerGuidItem($element) {
486
		$guid = sprintf($this->config['settings']['guidObsTpl'], $element['id_observation']);
490
		$guid = sprintf($this->config['settings']['guidObsTpl'], $element['id_observation']);
487
		return $guid;
491
		return $guid;
488
	}
492
	}
489
 
493
 
490
	private function creerLienItem($element) {
494
	private function creerLienItem($element) {
491
		$lien = null;
495
		$lien = null;
492
		if ($element['nom_sel_nn'] != 0) {
496
		if ($element['nom_sel_nn'] != 0) {
493
			$lien = $this->getUrlEflore($element['nom_referentiel'], $element['nom_sel_nn'], 'cel');
497
			$lien = $this->getUrlEflore($element['nom_referentiel'], $element['nom_sel_nn'], 'cel');
494
		}
498
		}
495
		return $lien;
499
		return $lien;
496
	}
500
	}
497
 
501
 
498
	private function creerDescription($obs, $item) {
502
	private function creerDescription($obs, $item) {
499
		$id_obs = $obs['id_observation'];
503
		$id_obs = $obs['id_observation'];
500
		$famille = $obs['famille'];
504
		$famille = $obs['famille'];
501
		$nom_saisi = $obs['nom_sel'];
505
		$nom_saisi = $obs['nom_sel'];
502
		$nom_retenu = $obs['nom_ret'];
506
		$nom_retenu = $obs['nom_ret'];
503
		$auteur = $this->getIntituleAuteur($obs['courriel_utilisateur']);
507
		$auteur = $this->getIntituleAuteur($obs['courriel_utilisateur']);
504
		$auteur_mail = $obs['courriel_utilisateur'];
508
		$auteur_mail = $obs['courriel_utilisateur'];
505
		$mots_cles_obs = $obs['mots_cles_texte'];
509
		$mots_cles_obs = $obs['mots_cles_texte'];
506
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id_observation']);
510
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id_observation']);
507
		$lieu = $obs['zone_geo'].' ('.$this->convertirCodeZoneGeoVersCodeInsee($obs['ce_zone_geo']).') > '.$obs['lieudit'].' > '.$obs['station'];
511
		$lieu = $obs['zone_geo'].' ('.$this->convertirCodeZoneGeoVersCodeInsee($obs['ce_zone_geo']).') > '.$obs['lieudit'].' > '.$obs['station'];
508
		$milieu = $obs['milieu'];
512
		$milieu = $obs['milieu'];
509
		$coordonnees = ($this->etreNull($obs['latitude']) && $this->etreNull($obs['longitude'])) ? '' : $obs['latitude'].'/'.$obs['longitude'];
513
		$coordonnees = ($this->etreNull($obs['latitude']) && $this->etreNull($obs['longitude'])) ? '' : $obs['latitude'].'/'.$obs['longitude'];
510
		$commentaire = $obs['commentaire'];
514
		$commentaire = $obs['commentaire'];
511
		$date_observation = ($obs['date_observation'] != '0000-00-00 00:00:00') ? $this->formaterDate($obs['date_observation'], '%A %d %B %Y') : '';
515
		$date_observation = ($obs['date_observation'] != '0000-00-00 00:00:00') ? $this->formaterDate($obs['date_observation'], '%A %d %B %Y') : '';
512
		$date_transmission = $this->formaterDate($obs['date_transmission']);
516
		$date_transmission = $this->formaterDate($obs['date_transmission']);
513
		$date_modification = $this->formaterDate($obs['date_modification']);
517
		$date_modification = $this->formaterDate($obs['date_modification']);
514
		$date_creation = $this->formaterDate($obs['date_creation']);
518
		$date_creation = $this->formaterDate($obs['date_creation']);
515
		$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
519
		$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
516
 
520
 
517
		$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
521
		$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
518
			'<ul>'.
522
			'<ul>'.
519
			'<li>'.'Famille : '.$famille.'</li>'.
523
			'<li>'.'Famille : '.$famille.'</li>'.
520
			'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
524
			'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
521
			'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
525
			'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
522
			'<li>'.'Observée le : '.$date_observation.'</li>'.
526
			'<li>'.'Observée le : '.$date_observation.'</li>'.
523
			'<li>'.'Lieu : '.$this->nePasInterpreterXml($lieu).'</li>'.
527
			'<li>'.'Lieu : '.$this->nePasInterpreterXml($lieu).'</li>'.
524
			'<li>'.'Milieu : '.$milieu.'</li>'.
528
			'<li>'.'Milieu : '.$milieu.'</li>'.
525
			(($this->etreFluxAdmin()) ? '<li>Coordonnées (Lat/Long) : '.$coordonnees.'</li>' : '').
529
			(($this->etreFluxAdmin()) ? '<li>Coordonnées (Lat/Long) : '.$coordonnees.'</li>' : '').
526
			'<li>'.'Commentaire : '.$this->nePasInterpreterXml($commentaire).'</li>'.
530
			'<li>'.'Commentaire : '.$this->nePasInterpreterXml($commentaire).'</li>'.
527
			'<li>'.'Mots-clés : '.$this->nePasInterpreterXml($mots_cles_obs).'</li>'.
531
			'<li>'.'Mots-clés : '.$this->nePasInterpreterXml($mots_cles_obs).'</li>'.
528
			(($this->etreFluxAdmin()) ? '<li>Transmis (= public) : '.$transmission.'</li>' : '').
532
			(($this->etreFluxAdmin()) ? '<li>Transmis (= public) : '.$transmission.'</li>' : '').
529
			'<li>Modifiée le : '.$date_modification.'</li>'.
533
			'<li>Modifiée le : '.$date_modification.'</li>'.
530
			'<li>Créée le : '.$date_creation.'</li>'.
534
			'<li>Créée le : '.$date_creation.'</li>'.
531
			'<li>'.'Par : '.
535
			'<li>'.'Par : '.
532
				(($this->etreFluxAdmin()) ? '<a href="mailto:'.$auteur_mail.'">'.$auteur.'</a>' : $auteur).
536
				(($this->etreFluxAdmin()) ? '<a href="mailto:'.$auteur_mail.'">'.$auteur.'</a>' : $auteur).
533
			'</li>'.
537
			'</li>'.
534
			$this->creerDescriptionChampsEtendus($obs, $item).
538
			$this->creerDescriptionChampsEtendus($obs, $item).
535
			(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
539
			(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
536
			'</ul>';
540
			'</ul>';
537
		$description = $this->nettoyerTexte($description);
541
		$description = $this->nettoyerTexte($description);
538
		return $description;
542
		return $description;
539
	}
543
	}
540
 
544
 
541
	private function creerDescriptionChampsEtendus($obs, $item) {
545
	private function creerDescriptionChampsEtendus($obs, $item) {
542
		$champs_etendus = '';
546
		$champs_etendus = '';
543
		foreach($obs['obs_etendue'] as $cle => &$champ) {
547
		foreach($obs['obs_etendue'] as $cle => &$champ) {
-
 
548
			if(isset($this->catalogue_cles_labels_champs_etendus[$champ->cle])) {
-
 
549
				$label = $this->catalogue_cles_labels_champs_etendus[$champ->cle]['label'];
-
 
550
			} else {
-
 
551
				$label = preg_replace("/(?<=\\w)(?=[A-Z])/"," $1", $champ->cle);
-
 
552
				$label = trim($label);
-
 
553
				$label = $label;
-
 
554
			}
544
			$champs_etendus .= '<li>'.$this->nePasInterpreterXml($champ->label.' : '.$champ->valeur).' </li>';
555
			$champs_etendus .= '<li>'.$this->nePasInterpreterXml($label.' : '.$champ->valeur).' </li>';
545
		}
556
		}
546
 
557
 
547
		if($champs_etendus != '') {
558
		if($champs_etendus != '') {
548
			$champs_etendus = '<li> Champs supplémentaires : <ul>'.$champs_etendus.'</ul></li>';
559
			$champs_etendus = '<li> Champs supplémentaires : <ul>'.$champs_etendus.'</ul></li>';
549
		}
560
		}
550
		return $champs_etendus;
561
		return $champs_etendus;
551
	}
562
	}
552
 
563
 
553
	private function creerCategorie($element) {
564
	private function creerCategorie($element) {
554
		$categorie = '';
565
		$categorie = '';
555
		$categorie = 'Observation';
566
		$categorie = 'Observation';
556
		$categorie = $this->nettoyerTexte($categorie);
567
		$categorie = $this->nettoyerTexte($categorie);
557
		return $categorie;
568
		return $categorie;
558
	}
569
	}
559
 
570
 
560
	private function etreFluxAdmin() {
571
	private function etreFluxAdmin() {
561
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
572
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
562
	}
573
	}
563
 
574
 
564
	private function creerUrlService() {
575
	private function creerUrlService() {
565
		$url_service = $this->getUrlServiceBase();
576
		$url_service = $this->getUrlServiceBase();
566
		if (count($_GET) > 0) {
577
		if (count($_GET) > 0) {
567
			$parametres_get = array();
578
			$parametres_get = array();
568
			foreach ($_GET as $cle => $valeur) {
579
			foreach ($_GET as $cle => $valeur) {
569
				$parametres_get[] = $cle.'='.$valeur;
580
				$parametres_get[] = $cle.'='.$valeur;
570
			}
581
			}
571
			$url_service .= '?'.implode('&amp;', $parametres_get);
582
			$url_service .= '?'.implode('&amp;', $parametres_get);
572
		}
583
		}
573
		return $url_service;
584
		return $url_service;
574
	}
585
	}
575
 
586
 
576
	private function getIntituleAuteur($courriel) {
587
	private function getIntituleAuteur($courriel) {
577
		$courriel = strtolower($courriel);
588
		$courriel = strtolower($courriel);
578
		if(isset($this->auteurs[$courriel])) {
589
		if(isset($this->auteurs[$courriel])) {
579
			$intitule = $this->auteurs[$courriel];
590
			$intitule = $this->auteurs[$courriel];
580
		} else {
591
		} else {
581
			$intitule = $courriel;
592
			$intitule = $courriel;
582
		}
593
		}
583
		return $intitule;
594
		return $intitule;
584
	}
595
	}
585
}
596
}