Subversion Repositories eFlore/Applications.cel

Rev

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

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