Subversion Repositories eFlore/Applications.cel

Rev

Rev 1330 | Rev 1361 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1330 Rev 1338
Line 8... Line 8...
8
 * /CelSyndicationObservation/opml
8
 * /CelSyndicationObservation/opml
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
13
 * 
13
 *
14
 * Les paramêtres :
14
 * Les paramêtres :
15
 *  - "start" indique le numéro du premier item à afficher
15
 *  - "start" indique le numéro du premier item à afficher
16
 *  - "limit" nombre d'items à afficher
16
 *  - "limit" nombre d'items à afficher
17
 * 
17
 *
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright 2010
22
 * @copyright 2010
23
 */
23
 */
24
class CelSyndicationObservation extends Cel {
24
class CelSyndicationObservation extends Cel {
25
	
25
 
26
	private $parametres_origines = null;
26
	private $parametres_origines = null;
27
	private $format = null;
27
	private $format = null;
28
	private $service = null;
28
	private $service = null;
29
	private $squelette = null;
29
	private $squelette = null;
30
	private $squelette_dossier = null;
30
	private $squelette_dossier = null;
31
	private $auteurs = array();
31
	private $auteurs = array();
32
	private $flux = array();
32
	private $flux = array();
33
	private $criteres = array(
33
	private $criteres = array(
34
		'utilisateur' => 'courriel_utilisateur', 
34
		'utilisateur' => 'courriel_utilisateur',
35
		'commune' => 'zone_geo', 
35
		'commune' => 'zone_geo',
36
		'dept' => 'ce_zone_geo',
36
		'dept' => 'ce_zone_geo',
37
		'taxon' => 'nom_ret',
37
		'taxon' => 'nom_ret',
38
		'commentaire' => 'commentaire',
38
		'commentaire' => 'commentaire',
39
		'date' => 'date_observation',
39
		'date' => 'date_observation',
40
		'projet' => 'mots-cles');
40
		'projet' => 'mots-cles');
41
	
41
 
42
	/**
42
	/**
43
	 * Méthode appelée avec une requête de type GET.
43
	 * Méthode appelée avec une requête de type GET.
44
	 */
44
	 */
45
	public function getElement($params = array()) {
45
	public function getElement($params = array()) {
46
		// Initialisation des variables
46
		// Initialisation des variables
47
		$this->parametres_origines = $params;
47
		$this->parametres_origines = $params;
48
		$info = array();
48
		$info = array();
49
		$contenu = '';
49
		$contenu = '';
50
		
50
 
51
		if (! $this->etreFluxAdmin() || $this->authentifierAdmin()) {
51
		if (! $this->etreFluxAdmin() || $this->authentifierAdmin()) {
52
			// Pré traitement des paramêtres
52
			// Pré traitement des paramêtres
53
			$pour_bdd = false;
53
			$pour_bdd = false;
54
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
54
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
55
			extract($p);
55
			extract($p);
56
			$this->parametres = $params;
56
			$this->parametres = $params;
57
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
57
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
58
					
58
 
59
			// Récupération de la liste des flux
59
			// Récupération de la liste des flux
60
			$this->chargerListeDesFlux();
60
			$this->chargerListeDesFlux();
61
			
61
 
62
			// Chargement du bon type de service demandé
62
			// Chargement du bon type de service demandé
63
			if (isset($service)) {
63
			if (isset($service)) {
64
				$this->service = $this->traiterNomService($service);
64
				$this->service = $this->traiterNomService($service);
65
				$methode = $this->getNomMethodeService();
65
				$methode = $this->getNomMethodeService();
66
				if (method_exists($this, $methode)) {
66
				if (method_exists($this, $methode)) {
Line 71... Line 71...
71
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
71
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
72
					} else if (isset($this->flux[$this->service])) {
72
					} else if (isset($this->flux[$this->service])) {
73
						$this->format = '';
73
						$this->format = '';
74
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
74
						$this->messages[] = "Le service CEL Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
75
					}
75
					}
76
	
76
 
77
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
77
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
78
						// Suppression des paramêtres inutile pour le reste des méthodes
78
						// Suppression des paramêtres inutile pour le reste des méthodes
79
						array_shift($this->parametres);
79
						array_shift($this->parametres);
80
						array_shift($this->parametres);
80
						array_shift($this->parametres);
81
						
81
 
82
						// Récupération du contenu à renvoyer
82
						// Récupération du contenu à renvoyer
83
						$contenu = $this->$methode();
83
						$contenu = $this->$methode();
84
					}
84
					}
85
				} else {
85
				} else {
86
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
86
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
87
				}
87
				}
88
			} else {
88
			} else {
89
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
89
				$this->messages[] = "Le service CEL Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
90
			}
90
			}
91
		}
91
		}
92
		
92
 
93
		// Envoie sur la sortie standard
93
		// Envoie sur la sortie standard
94
		$encodage = 'utf-8';
94
		$encodage = 'utf-8';
95
		$mime = $this->getTypeMime();
95
		$mime = $this->getTypeMime();
96
		$formatage_json = $this->getFormatageJson();
96
		$formatage_json = $this->getFormatageJson();
97
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
97
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
98
	}
98
	}
99
	
99
 
100
	private function getUrlBase() {
100
	private function getUrlBase() {
101
		$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
101
		$url_base = sprintf($this->config['settings']['baseURLAbsolu'], get_class($this).'/');
102
		return $url_base;
102
		return $url_base;
103
	}
103
	}
104
	
104
 
105
	private function getUrlServiceBase() {
105
	private function getUrlServiceBase() {
106
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
106
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
107
		return $url_service;
107
		return $url_service;
108
	}
108
	}
109
	
109
 
110
	private function traiterNomService($nom) {
110
	private function traiterNomService($nom) {
111
		$nom = strtolower($nom);
111
		$nom = strtolower($nom);
112
		return $nom;
112
		return $nom;
113
	}
113
	}
114
	
114
 
115
	private function getNomMethodeService() {
115
	private function getNomMethodeService() {
116
		$methode = '';
116
		$methode = '';
117
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
117
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
118
		$methode = 'getService'.$service_formate;
118
		$methode = 'getService'.$service_formate;
119
		return $methode;
119
		return $methode;
120
	}
120
	}
121
	
121
 
122
	private function getTypeMime() {
122
	private function getTypeMime() {
123
		$mime = '';
123
		$mime = '';
124
		$test = isset($this->format) ? $this->format : $this->service; 
124
		$test = isset($this->format) ? $this->format : $this->service;
125
		switch ($test) {
125
		switch ($test) {
126
			case 'atom' :
126
			case 'atom' :
127
				$mime = 'application/atom+xml';
127
				$mime = 'application/atom+xml';
128
				break;
128
				break;
129
			case 'rss1' :
129
			case 'rss1' :
Line 136... Line 136...
136
			default:
136
			default:
137
				$mime = 'text/html';
137
				$mime = 'text/html';
138
		}
138
		}
139
		return $mime;
139
		return $mime;
140
	}
140
	}
141
	
141
 
142
	private function getFormatageJson() {
142
	private function getFormatageJson() {
143
		$json = false;
143
		$json = false;
144
		switch ($this->service) {
144
		switch ($this->service) {
145
			case 'liste-des-flux' :
145
			case 'liste-des-flux' :
146
				$json = true;
146
				$json = true;
Line 148... Line 148...
148
			default:
148
			default:
149
				$json = false;
149
				$json = false;
150
		}
150
		}
151
		return $json;
151
		return $json;
152
	}
152
	}
153
	
153
 
154
	private function getFlux($nom) {
154
	private function getFlux($nom) {
155
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
155
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
156
	}
156
	}
Line 157... Line 157...
157
 
157
 
Line 163... Line 163...
163
			$url = $url_base.$nom.'/'.$format;
163
			$url = $url_base.$nom.'/'.$format;
164
			$flux[$format] = $url;
164
			$flux[$format] = $url;
165
		}
165
		}
166
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
166
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
167
	}
167
	}
168
	
168
 
169
	private function chargerListeDesFlux() {
169
	private function chargerListeDesFlux() {
170
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL', 
170
		$this->setFlux('par-defaut', 'Flux de syndication des observations publiques du CEL',
171
			'Ce flux fournit des informations sur les observations du CEL.');
171
			'Ce flux fournit des informations sur les observations du CEL.');
172
		$this->setFlux('par-mots-cles', 'Flux de syndication obsolète',
172
		$this->setFlux('par-mots-cles', 'Flux de syndication obsolète',
173
			"Ce flux est désormais accessible via le flux multicriteres/atom/M?tag='mot-cle'.");
173
			"Ce flux est désormais accessible via le flux multicriteres/atom/M?tag='mot-cle'.");
174
		$this->setFlux('par-commune','Flux de syndication obsolète',
174
		$this->setFlux('par-commune','Flux de syndication obsolète',
175
			"Ce flux  est désormais accessible via le flux multicriteres/atom/M?commune='commune'.");
175
			"Ce flux  est désormais accessible via le flux multicriteres/atom/M?commune='commune'.");
Line 177... Line 177...
177
			'filtrées par un ou plusieurs critères',
177
			'filtrées par un ou plusieurs critères',
178
			"Ce flux fournit des informations sur les nouvelles observations du CEL filtrées par ".
178
			"Ce flux fournit des informations sur les nouvelles observations du CEL filtrées par ".
179
			"auteur (mail), commune (nom), departement (code postal), taxon (nom scientifique), commentaire, projet ".
179
			"auteur (mail), commune (nom), departement (code postal), taxon (nom scientifique), commentaire, projet ".
180
			"et/ou date.");
180
			"et/ou date.");
181
	}
181
	}
182
	
182
 
183
	private function getServiceListeDesFlux() {
183
	private function getServiceListeDesFlux() {
184
		return $this->flux;
184
		return $this->flux;
185
	}
185
	}
186
	
186
 
187
	private function getServiceOpml() {
187
	private function getServiceOpml() {
188
		$donnees = array();
188
		$donnees = array();
189
		$id = 1;
189
		$id = 1;
190
		foreach ($this->flux as $flux_nom => $flux){
190
		foreach ($this->flux as $flux_nom => $flux){
191
			$info = array();
191
			$info = array();
Line 195... Line 195...
195
			$info['description'] = $flux['description'];
195
			$info['description'] = $flux['description'];
196
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
196
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
197
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
197
			$info['url_html'] = $this->config['settings']['aideCelUrl'].'FluxSyndication';
198
			$donnees['liste_flux'][] = $info;
198
			$donnees['liste_flux'][] = $info;
199
		}
199
		}
200
		
200
 
201
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
201
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
202
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
202
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
203
		return $contenu;
203
		return $contenu;
204
	}
204
	}
205
	
205
 
206
	private function getServiceParDefaut() {
206
	private function getServiceParDefaut() {
207
		// Construction de la requête
207
		// Construction de la requête
208
		$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
208
		$requete = 	(isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
209
			'FROM cel_obs '.
209
			'FROM cel_obs '.
210
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
210
			(($this->etreFluxAdmin()) ? '' : 'WHERE transmission = 1 ').
211
			'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
211
			'ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 'date_modification DESC').' '.
212
			"LIMIT $this->start,$this->limit ";
212
			"LIMIT $this->start,$this->limit ";
213
		
213
 
214
		$elements = $this->executerRequete($requete);
214
		$elements = $this->executerRequete($requete);
215
		
215
 
216
		// Création du contenu
216
		// Création du contenu
217
		$contenu = $this->executerService($elements);
217
		$contenu = $this->executerService($elements);
218
		return $contenu;
218
		return $contenu;
219
	}
219
	}
220
	
220
 
221
	private function getServiceParMotsCles() {
221
	private function getServiceParMotsCles() {
222
		$infos=array();
222
		$infos=array();
223
		$infos[0]['nom_sel_nn'] = '';
223
		$infos[0]['nom_sel_nn'] = '';
224
		$infos[0]['date_modification'] = '2011-06-28';
224
		$infos[0]['date_modification'] = '2011-06-28';
225
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
225
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
Line 227... Line 227...
227
		$donnees['items'][0]['description'] =  'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
227
		$donnees['items'][0]['description'] =  'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
228
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?projet=';
228
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?projet=';
229
		if (isset($this->parametres[0])) {
229
		if (isset($this->parametres[0])) {
230
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
230
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
231
		} else {
231
		} else {
232
			$donnees['items'][0]['description'] .= '</b>';	
232
			$donnees['items'][0]['description'] .= '</b>';
233
		}
233
		}
234
		$donnees['items'][0]['titre'] = '';
234
		$donnees['items'][0]['titre'] = '';
235
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
235
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
236
		return $contenu;
236
		return $contenu;
237
	}
237
	}
238
	
238
 
239
	private function getServiceParCommune() {
239
	private function getServiceParCommune() {
240
		$infos=array();
240
		$infos=array();
241
		$infos[0]['nom_sel_nn'] = '';
241
		$infos[0]['nom_sel_nn'] = '';
242
		$infos[0]['date_modification'] = '2011-06-28';
242
		$infos[0]['date_modification'] = '2011-06-28';
243
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
243
		$donnees = $this->construireDonneesCommunesAuFlux($infos);
Line 245... Line 245...
245
		$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
245
		$donnees['items'][0]['description'] = 'Ce flux est devenu obsolète. Veuillez utiliser le flux '.
246
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?commune=';
246
			'<b>http://www.tela-botanica.org/eflore/cel2/jrest/CelSyndicationObservation/multicriteres/atom?commune=';
247
		if (isset($this->parametres[0])) {
247
		if (isset($this->parametres[0])) {
248
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
248
			$donnees['items'][0]['description'] .= $this->parametres[0].'</b>';
249
		} else {
249
		} else {
250
			$donnees['items'][0]['description'] .= '</b>';	
250
			$donnees['items'][0]['description'] .= '</b>';
251
		}
251
		}
252
		$donnees['items'][0]['titre'] = '';
252
		$donnees['items'][0]['titre'] = '';
253
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
253
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
254
		return $contenu;
254
		return $contenu;
255
	}
255
	}
256
	
256
 
257
	private function getServiceMultiCriteres() {
257
	private function getServiceMultiCriteres() {
258
		$contenu = '';
258
		$contenu = '';
259
		if (isset($_GET['debut'])) $this->start = $_GET['debut'];		
259
		if (isset($_GET['debut'])) $this->start = $_GET['debut'];
260
		if (isset($_GET['limite'])) $this->limite = $_GET['limite'];
260
		if (isset($_GET['limite'])) $this->limite = $_GET['limite'];
261
		
261
 
262
		// Construction de la requête
262
		// Construction de la requête
263
		$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
263
		$requete = (isset($this->distinct) ? 'SELECT DISTINCT' : 'SELECT').' * '.
264
				'FROM cel_obs '.
264
				'FROM cel_obs '.
265
				'WHERE 1 AND '.(($this->etreFluxAdmin()) ? '' : ' transmission = 1 AND ');
265
				'WHERE 1 AND '.(($this->etreFluxAdmin()) ? '' : ' transmission = 1 AND ');
266
		
266
 
267
		if ($this->estUneRechercheGenerale()) {
267
		if ($this->estUneRechercheGenerale()) {
268
			$chaine_requete = $_GET['recherche'];
268
			$chaine_requete = $_GET['recherche'];
269
			$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
269
			$requete .= $this->creerSousRequeteRechercheGenerale($chaine_requete);
270
		} else {
270
		} else {
271
			$criteres = $this->traiterCriteresMultiples($_GET) ;
271
			$criteres = $this->traiterCriteresMultiples($_GET) ;
272
			if (!empty($criteres)) {
272
			if (!empty($criteres)) {
273
				$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
273
				$requete .= $this->creerSousRequeteRechercheParCriteres($criteres);
274
			}	
274
			}
275
		}
275
		}
276
		$requete = rtrim($requete, 'AND ');
276
		$requete = rtrim($requete, 'AND ');
277
		$requete .= ' ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  : 
277
		$requete .= ' ORDER BY '.(isset($this->orderby) && (!is_null($this->orderby)) ? $this->orderby  :
278
			'date_modification DESC, zone_geo ASC').' '.
278
			'date_modification DESC, zone_geo ASC').' '.
279
				"LIMIT $this->start,$this->limit ";
279
				"LIMIT $this->start,$this->limit ";
Line 280... Line 280...
280
 
280
 
Line 284... Line 284...
284
		if ($elements != false && count($elements) > 0) {
284
		if ($elements != false && count($elements) > 0) {
285
			$contenu = $this->executerService($elements);
285
			$contenu = $this->executerService($elements);
286
		} else {
286
		} else {
287
			$this->messages[] = "Aucune observation disponible.";
287
			$this->messages[] = "Aucune observation disponible.";
288
		}
288
		}
289
        
289
 
290
        return $contenu;
290
        return $contenu;
291
	}
291
	}
292
	
292
 
293
	private function creerSousRequeteRechercheParCriteres($criteres) {
293
	private function creerSousRequeteRechercheParCriteres($criteres) {
294
		$requete = '';
294
		$requete = '';
295
		foreach ($criteres as $pair) {
295
		foreach ($criteres as $pair) {
296
			$nom_valeur = explode("=",$pair);
296
			$nom_valeur = explode("=",$pair);
297
			if (sizeof($nom_valeur) != 0) {
297
			if (sizeof($nom_valeur) != 0) {
Line 301... Line 301...
301
						foreach($mots_comment_liste as $mot_comment) {
301
						foreach($mots_comment_liste as $mot_comment) {
302
							$mot_comment = trim($mot_comment) ;
302
							$mot_comment = trim($mot_comment) ;
303
							$requete .= $nom_valeur[0].' LIKE '.$this->bdd->quote('%'.$mot_comment.'%').' AND ';
303
							$requete .= $nom_valeur[0].' LIKE '.$this->bdd->quote('%'.$mot_comment.'%').' AND ';
304
						}
304
						}
305
						break;
305
						break;
306
					case "date_observation" : 
306
					case "date_observation" :
307
						$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
307
						$nom_valeur[1] = str_replace('/', '-', $nom_valeur[1]);
308
						if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
308
						if (preg_match('/(^[0-9]{2})-([0-9]{2})-([0-9]{4}$)/', $nom_valeur[1], $matches)) {
309
							$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
309
							$nom_valeur[1] = $matches[3].'-'.$matches[2].'-'.$matches[1];
310
						}
310
						}
311
						$requete .= $nom_valeur[0].'='.$this->bdd->quote($nom_valeur[1]).' AND '; break;
311
						$requete .= $nom_valeur[0].'='.$this->bdd->quote($nom_valeur[1]).' AND '; break;
312
					case "ce_zone_geo" :
312
					case "ce_zone_geo" :
313
						$requete .= ' ('.$nom_valeur[0].' LIKE "INSEE-C:'.$nom_valeur[1].'%") AND '; break;
313
						$requete .= ' ('.$nom_valeur[0].' LIKE "INSEE-C:'.$nom_valeur[1].'%") AND '; break;
314
					case "nom_ret" : 
314
					case "nom_ret" :
315
						if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';						
315
						if ($nom_valeur[1] == "indetermine") $nom_valeur[1] = 'null';
316
						$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
316
						$requete .= ' ('.$nom_valeur[0].' LIKE "%'.$nom_valeur[1].'%" OR nom_sel LIKE "%'.
317
							$nom_valeur[1].'%") AND '; break;
317
							$nom_valeur[1].'%") AND '; break;
318
					case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]).' AND '; break; 		
318
					case "mots-cles" : $requete .= $this->creerSousRequeteMotsCles($nom_valeur[1]).' AND '; break;
319
					default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
319
					default : $requete .= $nom_valeur[0].' = "'.$nom_valeur[1].'" AND '; break;
320
				}
320
				}
321
			}
321
			}
322
		}
322
		}
323
		$requete = rtrim($requete,' AND ');
323
		$requete = rtrim($requete,' AND ');
324
		return $requete;
324
		return $requete;
325
	}
325
	}
326
	
326
 
327
	private function creerSousRequeteMotsCles($mot_cle) {
327
	private function creerSousRequeteMotsCles($mot_cle) {
328
		$requete = '';
328
		$requete = '';
329
		if (preg_match('/.*OU.*/', $mot_cle)) {
329
		if (preg_match('/.*OU.*/', $mot_cle)) {
330
			$mots_cles_tab = explode('OU',$mot_cle);
330
			$mots_cles_tab = explode('OU',$mot_cle);
331
			foreach($mots_cles_tab as $mot_cle_item) {
331
			foreach($mots_cles_tab as $mot_cle_item) {
Line 341... Line 341...
341
		} else {
341
		} else {
342
			$requete = "(mots_cles_texte LIKE ".$this->proteger('%'.$mot_cle.'%').') ';
342
			$requete = "(mots_cles_texte LIKE ".$this->proteger('%'.$mot_cle.'%').') ';
343
		}
343
		}
344
		return $requete;
344
		return $requete;
345
	}
345
	}
346
	
346
 
347
	private function traiterCriteresMultiples($tableau_criteres) {
347
	private function traiterCriteresMultiples($tableau_criteres) {
348
		$tableau_criteres_pour_bdd = array();
348
		$tableau_criteres_pour_bdd = array();
349
				
349
 
350
		foreach($tableau_criteres as $nom_critere => $valeur_critere) {
350
		foreach($tableau_criteres as $nom_critere => $valeur_critere) {
351
			if (isset($this->criteres[$nom_critere])) {
351
			if (isset($this->criteres[$nom_critere])) {
352
				$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
352
				$tableau_criteres_pour_bdd[] = $this->criteres[$nom_critere].'='.$valeur_critere;
353
			}
353
			}
354
		}
354
		}
355
		return $tableau_criteres_pour_bdd;
355
		return $tableau_criteres_pour_bdd;
356
	}
356
	}
357
	
357
 
358
	private function creerSousRequeteRechercheGenerale($chaine_requete) {
358
	private function creerSousRequeteRechercheGenerale($chaine_requete) {
359
		$requete = '';
359
		$requete = '';
360
		if (trim($chaine_requete) != '') {	
360
		if (trim($chaine_requete) != '') {
361
			$chaine_requete = strtolower($chaine_requete);
361
			$chaine_requete = strtolower($chaine_requete);
362
			$chaine_requete = str_replace(' ', '_', $chaine_requete);
362
			$chaine_requete = str_replace(' ', '_', $chaine_requete);
363
			$requete = ' ('.
363
			$requete = ' ('.
364
				'nom_ret LIKE "'.$chaine_requete.'%"'.
364
				'nom_ret LIKE "'.$chaine_requete.'%"'.
365
				' OR '.
365
				' OR '.
Line 376... Line 376...
376
				'mots_cles_texte LIKE "'.$chaine_requete.'%" '.
376
				'mots_cles_texte LIKE "'.$chaine_requete.'%" '.
377
				') ';
377
				') ';
378
		}
378
		}
379
		return $requete;
379
		return $requete;
380
	}
380
	}
381
	
381
 
382
	private function estUneRechercheGenerale() {
382
	private function estUneRechercheGenerale() {
383
		return isset($_GET['recherche']);
383
		return isset($_GET['recherche']);
384
	}
384
	}
385
	
385
 
386
	private function executerService($elements) {
386
	private function executerService($elements) {
387
		$contenu = '';
387
		$contenu = '';
388
		if (is_array($elements)) {
388
		if (is_array($elements)) {
389
			// Prétraitement des données
389
			// Prétraitement des données
390
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
390
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
391
			foreach ($elements as $element) {
391
			foreach ($elements as $element) {
392
				$identifiants[$element['ce_utilisateur']] = $element['ce_utilisateur'];
392
				$identifiants[$element['courriel_utilisateur']] = $element['courriel_utilisateur'];
393
			}
393
			}
394
			$this->auteurs = $this->creerAuteurs($identifiants);
394
			$this->auteurs = $this->creerAuteurs($identifiants);
395
			foreach ($elements as $element) {
395
			foreach ($elements as $element) {
396
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
396
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
397
			}
397
			}
398
			
398
 
399
			// Création du contenu à partir d'un template PHP
399
			// Création du contenu à partir d'un template PHP
400
			if (isset($this->squelette)) {
400
			if (isset($this->squelette)) {
401
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
401
				$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
402
			}
402
			}
403
		}		
403
		}
404
		return $contenu;
404
		return $contenu;
405
	}
405
	}
406
	
406
 
407
	private function construireDonneesCommunesAuFlux($observations) {
407
	private function construireDonneesCommunesAuFlux($observations) {
408
		$donnees = $this->getFlux($this->service);
408
		$donnees = $this->getFlux($this->service);
409
		$donnees['guid'] = $this->getUrlServiceBase();
409
		$donnees['guid'] = $this->getUrlServiceBase();
410
		$donnees['titre'] = 'Flux des observations du CEL';
410
		$donnees['titre'] = 'Flux des observations du CEL';
411
		$donnees['lien_service'] = $this->creerUrlService();
411
		$donnees['lien_service'] = $this->creerUrlService();
Line 417... Line 417...
417
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
417
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
418
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
418
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
419
		$donnees['annee_courante'] = date('Y');
419
		$donnees['annee_courante'] = date('Y');
420
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
420
		$donnees['generateur'] = 'CEL - Jrest - CelSyndicationObservation';
421
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
421
		$donnees['generateur_version'] = (preg_match('/([0-9]+)/', '$Revision$', $match)) ?  $match[1] : '0';
422
		return $donnees; 
422
		return $donnees;
423
	}
423
	}
424
	
424
 
425
	private function construireDonneesCommunesAuxItems($observation) {
425
	private function construireDonneesCommunesAuxItems($observation) {
426
		$item = array();
426
		$item = array();
427
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
427
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['date_modification']);
428
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
428
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
429
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
429
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
Line 437... Line 437...
437
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
437
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
438
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
438
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
439
		$item['modifier_par'] = $observation['id_observation'];
439
		$item['modifier_par'] = $observation['id_observation'];
440
		return $item;
440
		return $item;
441
	}
441
	}
442
	
442
 
443
	private function creerTitre($obs) {
443
	private function creerTitre($obs) {
444
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['nom_sel_nn'].']';
444
		$nom_plante = $obs['nom_sel'].' [nn'.$obs['nom_sel_nn'].']';
445
		$lieu = $obs['zone_geo'].' ('.$obs['ce_zone_geo'].')';
445
		$lieu = $obs['zone_geo'].' ('.$obs['ce_zone_geo'].')';
446
		$utilisateur = $obs['prenom_utilisateur'].' '.$obs['nom_utilisateur'];
446
		$utilisateur = $this->getIntituleAuteur($obs['courriel_utilisateur']);;
447
		$titre = "$nom_plante à $lieu par $utilisateur";
447
		$titre = "$nom_plante à $lieu par $utilisateur";
448
		$titre = $this->nettoyerTexte($titre);
448
		$titre = $this->nettoyerTexte($titre);
449
		return $titre;
449
		return $titre;
450
	}
450
	}
451
	
451
 
452
	private function creerGuidItem($element) {
452
	private function creerGuidItem($element) {
453
		$guid = sprintf($this->config['settings']['guidObsTpl'], $element['id_observation']);
453
		$guid = sprintf($this->config['settings']['guidObsTpl'], $element['id_observation']);
454
		return $guid;
454
		return $guid;
455
	}
455
	}
456
	
456
 
457
	private function creerLienItem($element) {
457
	private function creerLienItem($element) {
458
		$lien = null;
458
		$lien = null;
459
		if ($element['nom_sel_nn'] != 0) {
459
		if ($element['nom_sel_nn'] != 0) {
460
			$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['nom_sel_nn']), 'cel');
460
			$lien = sprintf($this->config['settings']['efloreUrlTpl'], urlencode($element['nom_sel_nn']), 'cel');
461
		}
461
		}
462
		return $lien;
462
		return $lien;
463
	}
463
	}
464
	
464
 
465
	private function creerDescription($obs, $item) {
465
	private function creerDescription($obs, $item) {
466
		$id_obs = $obs['id_observation'];
466
		$id_obs = $obs['id_observation'];
467
		$famille = $obs['famille'];
467
		$famille = $obs['famille'];
468
		$nom_saisi = $obs['nom_sel'];
468
		$nom_saisi = $obs['nom_sel'];
469
		$nom_retenu = $obs['nom_ret'];
469
		$nom_retenu = $obs['nom_ret'];
470
		$auteur = $obs['prenom_utilisateur'].' '.$obs['nom_utilisateur'];
470
		$auteur = $this->getIntituleAuteur($obs['courriel_utilisateur']);
471
		$auteur_mail = $obs['courriel_utilisateur'];
471
		$auteur_mail = $obs['courriel_utilisateur'];
472
		$mots_cles_obs = $obs['mots_cles_texte'];
472
		$mots_cles_obs = $obs['mots_cles_texte'];
473
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id_observation']);
473
		$lien_correction = sprintf($this->config['settings']['phpEditUrlTpl'], $obs['id_observation']);
474
		$lieu = $obs['zone_geo'].' ('.$this->convertirCodeZoneGeoVersCodeInsee($obs['ce_zone_geo']).') > '.$obs['lieudit'].' > '.$obs['station'];
474
		$lieu = $obs['zone_geo'].' ('.$this->convertirCodeZoneGeoVersCodeInsee($obs['ce_zone_geo']).') > '.$obs['lieudit'].' > '.$obs['station'];
475
		$milieu = $obs['milieu'];
475
		$milieu = $obs['milieu'];
Line 478... Line 478...
478
		$date_observation = $this->formaterDate($obs['date_observation'], '%A %d %B %Y');
478
		$date_observation = $this->formaterDate($obs['date_observation'], '%A %d %B %Y');
479
		$date_transmission = $this->formaterDate($obs['date_transmission']);
479
		$date_transmission = $this->formaterDate($obs['date_transmission']);
480
		$date_modification = $this->formaterDate($obs['date_modification']);
480
		$date_modification = $this->formaterDate($obs['date_modification']);
481
		$date_creation = $this->formaterDate($obs['date_creation']);
481
		$date_creation = $this->formaterDate($obs['date_creation']);
482
		$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
482
		$transmission = $obs['transmission'] == 1 ? "oui ($date_transmission)" : 'non';
483
		
483
 
484
		$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
484
		$description = '<h2>'."Observation #$id_obs de $nom_saisi".'</h2>'.
485
			'<ul>'.
485
			'<ul>'.
486
			'<li>'.'Famille : '.$famille.'</li>'.
486
			'<li>'.'Famille : '.$famille.'</li>'.
487
			'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
487
			'<li>'.'Nom saisi : '.$nom_saisi.'</li>'.
488
			'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
488
			'<li>'.'Nom retenu : '.$nom_retenu.'</li>'.
Line 501... Line 501...
501
			(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
501
			(($this->etreFluxAdmin()) ? '<li><a href="'.$lien_correction.'">Corriger cette observation</a></li>' : '').
502
			'</ul>';
502
			'</ul>';
503
		$description = $this->nettoyerTexte($description);
503
		$description = $this->nettoyerTexte($description);
504
		return $description;
504
		return $description;
505
	}
505
	}
506
	
506
 
507
	private function creerCategorie($element) {
507
	private function creerCategorie($element) {
508
		$categorie = '';
508
		$categorie = '';
509
		$categorie = 'Observation';
509
		$categorie = 'Observation';
510
		$categorie = $this->nettoyerTexte($categorie);
510
		$categorie = $this->nettoyerTexte($categorie);
511
		return $categorie;
511
		return $categorie;
512
	}
512
	}
513
	
513
 
514
	private function etreFluxAdmin() {
514
	private function etreFluxAdmin() {
515
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
515
		return (isset($_GET['admin']) && $_GET['admin'] == '1') ? true : false;
516
	}
516
	}
517
	
517
 
518
	private function creerUrlService() {
518
	private function creerUrlService() {
519
		$url_service = $this->getUrlServiceBase();
519
		$url_service = $this->getUrlServiceBase();
520
		if (count($_GET) > 0) {
520
		if (count($_GET) > 0) {
521
			$parametres_get = array();
521
			$parametres_get = array();
522
			foreach ($_GET as $cle => $valeur) {
522
			foreach ($_GET as $cle => $valeur) {
Line 524... Line 524...
524
			}
524
			}
525
			$url_service .= '?'.implode('&amp;', $parametres_get);
525
			$url_service .= '?'.implode('&amp;', $parametres_get);
526
		}
526
		}
527
		return $url_service;
527
		return $url_service;
528
	}
528
	}
529
}	
-
 
530
529
 
-
 
530
	private function getIntituleAuteur($courriel) {
-
 
531
		$courriel = strtolower($courriel);
-
 
532
		$intitule = $this->auteurs[$courriel];
-
 
533
		return $intitule;
-
 
534
	}
-
 
535
}
-
 
536
531
537