Subversion Repositories eFlore/Applications.cel

Rev

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

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