Subversion Repositories eFlore/Applications.cel

Rev

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

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