Subversion Repositories Sites.obs-saisons.fr

Rev

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

Rev 210 Rev 215
1
<?php
1
<?php
2
/**
2
/**
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
3
 * Service fournissant des informations concernant le CEL au format RSS1, RSS2 ou ATOM.
4
 * Encodage en entrée : utf8
4
 * Encodage en entrée : utf8
5
 * Encodage en sortie : utf8
5
 * Encodage en sortie : utf8
6
 * Format du service :
6
 * Format du service :
7
 * /CelSyndicationObservation/liste-des-flux
7
 * /CelSyndicationObservation/liste-des-flux
8
 * /CelSyndicationObservation/opml
8
 * /CelSyndicationObservation/opml
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
9
 * /CelSyndicationObservation/par-defaut/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
10
 * /CelSyndicationObservation/pour-admin/(rss1|rss2|atom)?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
11
 * /CelSyndicationObservation/par-mots-cles/(rss1|rss2|atom)/mot-cle?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
12
 * /CelSyndicationObservation/par-commune/(rss1|rss2|atom)/nom-commune?start=0&limit=150
13
 * 
13
 * 
14
 * Les paramêtres :
14
 * Les paramêtres :
15
 *  - "start" indique le numéro du premier item à afficher
15
 *  - "start" indique le numéro du premier item à afficher
16
 *  - "limit" nombre d'items à afficher
16
 *  - "limit" nombre d'items à afficher
17
 * 
17
 * 
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
21
 * @version $Id$
21
 * @version $Id$
22
 * @copyright 2010
22
 * @copyright 2010
23
 */
23
 */
24
class OdsSyndicationObservation extends OdsTriple {
24
class OdsSyndicationObservation extends OdsTriple {
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 $flux = array();
31
	private $flux = array();
32
	
32
	
33
	private $mode = 'normal';
33
	private $mode = 'normal';
34
	
34
	
35
	/**
35
	/**
36
	 * Méthode appelée avec une requête de type GET.
36
	 * Méthode appelée avec une requête de type GET.
37
	 */
37
	 */
38
	public function getElement($params = array()) {
38
	public function getElement($params = array()) {
39
		// Initialisation des variables
39
		// Initialisation des variables
40
		$this->parametres_origines = $params;
40
		$this->parametres_origines = $params;
41
		$info = array();
41
		$info = array();
42
		$contenu = '';
42
		$contenu = '';
43
		
43
		
44
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
44
		if (! $this->etreFluxAdmin() || $this->authentifier()) {
45
			// Pré traitement des paramêtres
45
			// Pré traitement des paramêtres
46
			$pour_bdd = false;
46
			$pour_bdd = false;
47
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
47
			$p = $this->traiterParametres(array('service', 'format'), $params, $pour_bdd);
48
			extract($p);
48
			extract($p);
49
			$this->parametres = $params;
49
			$this->parametres = $params;
50
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
50
			$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
51
					
51
					
52
			// Récupération de la liste des flux
52
			// Récupération de la liste des flux
53
			$this->chargerListeDesFlux();
53
			$this->chargerListeDesFlux();
54
			
54
			
55
			// Chargement du bon type de service demandé
55
			// Chargement du bon type de service demandé
56
			if (isset($service)) {
56
			if (isset($service)) {
57
				$this->service = $this->traiterNomService($service);
57
				$this->service = $this->traiterNomService($service);
58
				$methode = $this->getNomMethodeService();
58
				$methode = $this->getNomMethodeService();
59
				if (method_exists($this, $methode)) {
59
				if (method_exists($this, $methode)) {
60
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
60
					if (isset($format) && preg_match('/^(?:rss1|rss2|atom)$/i', $format)) {
61
						// Mise en minuscule de l'indication du format
61
						// Mise en minuscule de l'indication du format
62
						$this->format = strtolower($format);
62
						$this->format = strtolower($format);
63
						// Définition du fichier squelette demandé
63
						// Définition du fichier squelette demandé
64
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
64
						$this->squelette = $this->squelette_dossier.$this->format.'.tpl.xml';
65
					} else if (isset($this->flux[$this->service])) {
65
					} else if (isset($this->flux[$this->service])) {
66
						$this->format = '';
66
						$this->format = '';
67
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
67
						$this->messages[] = "Le service ODS Syndication nécessite d'indiquer en second paramètre le format : rss1, rss2 ou atom.";
68
					}
68
					}
69
	
69
	
70
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
70
					if (!isset($this->flux[$this->service]) || isset($this->format)) {
71
						// Suppression des paramêtres inutile pour le reste des méthodes
71
						// Suppression des paramêtres inutile pour le reste des méthodes
72
						array_shift($this->parametres);
72
						array_shift($this->parametres);
73
						array_shift($this->parametres);
73
						array_shift($this->parametres);
74
						
74
						
75
						// Récupération du contenu à renvoyer
75
						// Récupération du contenu à renvoyer
76
						$contenu = $this->$methode();
76
						$contenu = $this->$methode();
77
					}
77
					}
78
				} else {
78
				} else {
79
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
79
					$this->messages[] = "Le type d'information demandé '$this->service' n'est pas disponible.";
80
				}
80
				}
81
			} else {
81
			} else {
82
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
82
				$this->messages[] = "Le service ODS Syndication Observation nécessite d'indiquer en premier paramètre le type d'information demandé.";
83
			}
83
			}
84
		}
84
		}
85
		
85
		
86
		// Envoie sur la sortie standard
86
		// Envoie sur la sortie standard
87
		$encodage = 'utf-8';
87
		$encodage = 'utf-8';
88
		$mime = $this->getTypeMime();
88
		$mime = $this->getTypeMime();
89
		$formatage_json = $this->getFormatageJson();
89
		$formatage_json = $this->getFormatageJson();
90
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
90
		$this->envoyer($contenu, $mime, $encodage, $formatage_json);
91
	}
91
	}
92
	
92
	
93
	private function getUrlBase() {
93
	private function getUrlBase() {
94
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
94
		$url_base = sprintf($this->config['settings']['baseURLAbsoluDyn'], get_class($this).'/');
95
		return $url_base;
95
		return $url_base;
96
	}
96
	}
97
	
97
	
98
	private function getUrlServiceBase() {
98
	private function getUrlServiceBase() {
99
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
99
		$url_service = $this->getUrlBase().implode('/', $this->parametres_origines);
100
		return $url_service;
100
		return $url_service;
101
	}
101
	}
102
	
102
	
103
	private function traiterNomService($nom) {
103
	private function traiterNomService($nom) {
104
		$nom = strtolower($nom);
104
		$nom = strtolower($nom);
105
		return $nom;
105
		return $nom;
106
	}
106
	}
107
	
107
	
108
	private function getNomMethodeService() {
108
	private function getNomMethodeService() {
109
		$methode = '';
109
		$methode = '';
110
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
110
		$service_formate = str_replace(' ', '', ucwords(implode(' ', explode('-', $this->service))));
111
		$methode = 'getService'.$service_formate;
111
		$methode = 'getService'.$service_formate;
112
		return $methode;
112
		return $methode;
113
	}
113
	}
114
	
114
	
115
	private function getTypeMime() {
115
	private function getTypeMime() {
116
		$mime = '';
116
		$mime = '';
117
		$test = isset($this->format) ? $this->format : $this->service; 
117
		$test = isset($this->format) ? $this->format : $this->service; 
118
		switch ($test) {
118
		switch ($test) {
119
			case 'atom' :
119
			case 'atom' :
120
				$mime = 'application/atom+xml';
120
				$mime = 'application/atom+xml';
121
				break;
121
				break;
122
			case 'rss1' :
122
			case 'rss1' :
123
			case 'rss2' :
123
			case 'rss2' :
124
				$mime = 'application/rss+xml';
124
				$mime = 'application/rss+xml';
125
				break;
125
				break;
126
			case 'opml' :
126
			case 'opml' :
127
				$mime = 'text/x-opml';
127
				$mime = 'text/x-opml';
128
				break;
128
				break;
129
			default:
129
			default:
130
				$mime = 'text/html';
130
				$mime = 'text/html';
131
		}
131
		}
132
		return $mime;
132
		return $mime;
133
	}
133
	}
134
	
134
	
135
	private function getFormatageJson() {
135
	private function getFormatageJson() {
136
		$json = false;
136
		$json = false;
137
		switch ($this->service) {
137
		switch ($this->service) {
138
			case 'liste-des-flux' :
138
			case 'liste-des-flux' :
139
				$json = true;
139
				$json = true;
140
				break;
140
				break;
141
			default:
141
			default:
142
				$json = false;
142
				$json = false;
143
		}
143
		}
144
		return $json;
144
		return $json;
145
	}
145
	}
146
	
146
	
147
	private function getFlux($nom) {
147
	private function getFlux($nom) {
148
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
148
		return isset($this->flux[$nom]) ? $this->flux[$nom] : array();
149
	}
149
	}
150
 
150
 
151
	private function setFlux($nom, $titre, $description) {
151
	private function setFlux($nom, $titre, $description) {
152
		$url_base = $this->getUrlBase();
152
		$url_base = $this->getUrlBase();
153
		$formats = array('atom', 'rss2', 'rss1');
153
		$formats = array('atom', 'rss2', 'rss1');
154
		$flux = array();
154
		$flux = array();
155
		foreach ($formats as $format) {
155
		foreach ($formats as $format) {
156
			$url = $url_base.$nom.'/'.$format;
156
			$url = $url_base.$nom.'/'.$format;
157
			$flux[$format] = $url;
157
			$flux[$format] = $url;
158
		}
158
		}
159
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
159
		$this->flux[$nom] = array('titre' => $titre, 'description' => $description, 'urls' => $flux);
160
	}
160
	}
161
	
161
	
162
	private function chargerListeDesFlux() {
162
	private function chargerListeDesFlux() {
163
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
163
		$this->setFlux('par-defaut', 'Flux de syndication des observations d\'ODS', 
164
			'Ce flux fournit des informations sur les observations d\'ODS');
164
			'Ce flux fournit des informations sur les observations d\'ODS');
165
	}
165
	}
166
	
166
	
167
	private function getServiceListeDesFlux() {
167
	private function getServiceListeDesFlux() {
168
		return $this->flux;
168
		return $this->flux;
169
	}
169
	}
170
	
170
	
171
	private function getServiceOpml() {
171
	private function getServiceOpml() {
172
		$donnees = array();
172
		$donnees = array();
173
		$id = 1;
173
		$id = 1;
174
		foreach ($this->flux as $flux_nom => $flux){
174
		foreach ($this->flux as $flux_nom => $flux){
175
			$info = array();
175
			$info = array();
176
			$info['type'] = 'atom';
176
			$info['type'] = 'atom';
177
			$info['titre'] = $flux['titre'];
177
			$info['titre'] = $flux['titre'];
178
			$info['texte'] = "ODS - Obs - $flux_nom";
178
			$info['texte'] = "ODS - Obs - $flux_nom";
179
			$info['description'] = $flux['description'];
179
			$info['description'] = $flux['description'];
180
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
180
			$info['url_xml'] = $this->getUrlBase().$flux_nom.'/atom';
181
			$donnees['liste_flux'][] = $info;
181
			$donnees['liste_flux'][] = $info;
182
		}
182
		}
183
		
183
		
184
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
184
		$this->squelette = $this->squelette_dossier.'opml.tpl.xml';
185
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
185
		$contenu = Cel::traiterSquelettePhp($this->squelette, $donnees);
186
		return $contenu;
186
		return $contenu;
187
	}
187
	}
188
	
188
	
189
	private function getServiceParDefaut() {
189
	private function getServiceParDefaut() {
190
		// Construction de la requête
190
		// Construction de la requête
191
		$requete = 	'SELECT * '.
191
		$requete = 	'SELECT * '.
192
			'FROM ods_observations '.
192
			'FROM ods_observations '.
193
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
193
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
194
			'ORDER BY oo_date_modification DESC '.
194
			'ORDER BY oo_date_modification DESC '.
195
			"LIMIT $this->start,$this->limit ";
195
			"LIMIT $this->start,$this->limit ";
196
		
196
		
197
		$elements = $this->executerRequete($requete);
197
		$elements = $this->executerRequete($requete);
198
		
198
		
199
		// Création du contenu
199
		// Création du contenu
200
		$contenu = $this->executerService($elements);
200
		$contenu = $this->executerService($elements);
201
		return $contenu;
201
		return $contenu;
202
	}
202
	}
203
	
203
	
204
	private function getServiceModificationObservations() {
204
	private function getServiceModificationObservations() {
205
		
205
		
206
		$this->mode = 'admin';
206
		$this->mode = 'admin';
207
		
207
		
208
		// Construction de la requête
208
		// Construction de la requête
209
		$requete = 	'SELECT * '.
209
		$requete = 	'SELECT * '.
210
			'FROM ods_observations '.
210
			'FROM ods_observations '.
211
			'LEFT JOIN ods_individus '.
211
			'LEFT JOIN ods_individus '.
212
			'ON ods_observations.oo_ce_individu = ods_individus.oi_id_individu '.
212
			'ON ods_observations.oo_ce_individu = ods_individus.oi_id_individu '.
213
			'LEFT JOIN ods_stations '.
213
			'LEFT JOIN ods_stations '.
214
			'ON ods_individus.oi_ce_station = ods_stations.os_id_station '.
214
			'ON ods_individus.oi_ce_station = ods_stations.os_id_station '.
215
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
215
			'WHERE oo_ce_participant != '.$this->config['appli']['id_participant_demo'].' '.
216
			'AND oo_date_saisie != oo_date_modification '.
216
			'AND oo_date_saisie != oo_date_modification '.
217
			'ORDER BY oo_date_modification DESC '.
217
			'ORDER BY oo_date_modification DESC '.
218
			"LIMIT $this->start,$this->limit ";
218
			"LIMIT $this->start,$this->limit ";
219
		
219
		
220
		$elements = $this->executerRequete($requete);
220
		$elements = $this->executerRequete($requete);
221
		
221
		
222
		// Création du contenu
222
		// Création du contenu
223
		$contenu = $this->executerService($elements);
223
		$contenu = $this->executerService($elements);
224
		return $contenu;
224
		return $contenu;
225
	}
225
	}
226
	
226
	
227
	private function executerService($elements) {
227
	private function executerService($elements) {
228
		$contenu = '';
228
		$contenu = '';
229
		if (is_array($elements)) {
229
		if (is_array($elements)) {
230
			// Prétraitement des données
230
			// Prétraitement des données
231
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
231
			$donnees = $this->construireDonneesCommunesAuFlux($elements);
232
			
232
			
233
			foreach ($elements as $element) {
233
			foreach ($elements as $element) {
234
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
234
				$donnees['items'][] = $this->construireDonneesCommunesAuxItems($element);
235
			}
235
			}
236
			
236
			
237
			// Création du contenu à partir d'un template PHP
237
			// Création du contenu à partir d'un template PHP
238
			if (isset($this->squelette)) {
238
			if (isset($this->squelette)) {
239
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
239
				$contenu = JrestService::traiterSquelettePhp($this->squelette, $donnees);
240
			}
240
			}
241
		}		
241
		}		
242
		return $contenu;
242
		return $contenu;
243
	}
243
	}
244
	
244
	
245
	private function construireDonneesCommunesAuFlux($observations) {
245
	private function construireDonneesCommunesAuFlux($observations) {
246
		$donnees = $this->getFlux($this->service);
246
		$donnees = $this->getFlux($this->service);
247
		$donnees['guid'] = $this->getUrlServiceBase();
247
		$donnees['guid'] = $this->getUrlServiceBase();
248
		$donnees['lien_service'] = $this->creerUrlService();
248
		$donnees['lien_service'] = $this->creerUrlService();
249
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
249
		$donnees['lien_ods'] = $this->config['settings']['odsSaisieUrlAbsolu'];
250
		$donnees['editeur'] = $this->config['settings']['editeur'];
250
		$donnees['editeur'] = $this->config['settings']['editeur'];
251
		$derniere_info_en_date = reset($observations);
251
		$derniere_info_en_date = reset($observations);
252
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
252
		$date_modification_timestamp = strtotime($derniere_info_en_date['oo_date_modification']);
253
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
253
		$donnees['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
254
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
254
		$donnees['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
255
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
255
		$donnees['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
256
		$donnees['annee_courante'] = date('Y');
256
		$donnees['annee_courante'] = date('Y');
257
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
257
		$donnees['generateur'] = 'ODS - Jrest - OdsSyndicationObservation';
258
		preg_match('/([0-9]+)/', '$Revision$', $match);
258
		preg_match('/([0-9]+)/', '$Revision$', $match);
259
		$donnees['generateur_version'] = $match[1];
259
		$donnees['generateur_version'] = $match[1];
260
		return $donnees; 
260
		return $donnees; 
261
	}
261
	}
262
	
262
	
263
	private function construireDonneesCommunesAuxItems($observation) {
263
	private function construireDonneesCommunesAuxItems($observation) {
264
		$item = array();
264
		$item = array();
265
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
265
		$date_modification_timestamp = $this->convertirDateHeureMysqlEnTimestamp($observation['oo_date_modification']);
266
		$item['date_maj_simple'] = strftime('%A %d %B %Y à %H:%M', $date_modification_timestamp);
266
		$item['date_maj_simple'] = strftime('%A %d %B %Y', $date_modification_timestamp);
267
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
267
		$item['date_maj_RSS'] = date(DATE_RSS, $date_modification_timestamp);
268
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
268
		$item['date_maj_ATOM'] = date(DATE_ATOM, $date_modification_timestamp);
269
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
269
		$item['date_maj_W3C'] = date(DATE_W3C, $date_modification_timestamp);
270
		$item['date_creation_simple'] = strftime('%A %d %B %Y à %H:%M', strtotime($observation['oo_date_saisie']));
270
		$item['date_creation_simple'] = strftime('%A %d %B %Y', strtotime($observation['oo_date_saisie']));
271
		$item['titre'] = $this->creerTitre($observation);
271
		$item['titre'] = $this->creerTitre($observation);
272
		$item['guid'] = $this->creerGuidItem($observation);
272
		$item['guid'] = $this->creerGuidItem($observation);
273
		$item['lien'] = $this->creerUrlService();
273
		$item['lien'] = $this->creerUrlService();
274
		$item['categorie'] = $this->creerCategorie($item);
274
		$item['categorie'] = $this->creerCategorie($item);
275
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
275
		$item['description'] = $this->creerDescription($this->protegerCaracteresHtmlDansChamps($observation), $item);
276
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
276
		$item['description_encodee'] = htmlspecialchars($this->creerDescription($observation, $item));
277
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
277
		$item['modifier_par'] = $this->creerAuteur($observation['oo_ce_participant'], $this->etreFluxAdmin());
278
		return $item;
278
		return $item;
279
	}
279
	}
280
	
280
	
281
	private function creerTitre($obs) {
281
	private function creerTitre($obs) {
282
		
282
		
283
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
283
		$stade_obs = $this->obtenirValeurTripleParId($obs['oo_ce_evenement']);
284
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
284
		$nom_plante = $this->obtenirNomEspecePourIdIndividu($obs['oo_ce_individu']);
285
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
285
		$utilisateur = $this->creerAuteur($obs['oo_ce_participant'], $this->etreFluxAdmin());
286
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
286
		$titre = "$stade_obs pour $nom_plante par $utilisateur";
287
		$titre = $this->nettoyerTexte($titre);
287
		$titre = $this->nettoyerTexte($titre);
288
		return $titre;
288
		return $titre;
289
	}
289
	}
290
	
290
	
291
	private function obtenirNomEspecePourIdIndividu($id_individu) {
291
	private function obtenirNomEspecePourIdIndividu($id_individu) {
292
		
292
		
293
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
293
		$requete_id_espece_individu = 'SELECT oi_ce_espece FROM ods_individus '.
294
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
294
									  'WHERE oi_id_individu = '.$this->proteger($id_individu);
295
		
295
		
296
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
296
		$resultat_id_espece = $this->executerRequete($requete_id_espece_individu);
297
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
297
		$id_espece = $resultat_id_espece[0]['oi_ce_espece'];
298
		
298
		
299
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
299
		$requete_nom_espece_individu = 'SELECT oe_nom_vernaculaire FROM ods_especes '.
300
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
300
									  'WHERE oe_id_espece = '.$this->proteger($id_espece);
301
		
301
		
302
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
302
		$resultat_nom_espece = $this->executerRequete($requete_nom_espece_individu);
303
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
303
		$nom_espece = $resultat_nom_espece[0]['oe_nom_vernaculaire'];
304
		
304
		
305
		return $nom_espece;
305
		return $nom_espece;
306
	}
306
	}
307
	
307
	
308
	private function creerGuidItem($element) {
308
	private function creerGuidItem($element) {
309
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
309
		$guid = sprintf($this->config['settings']['guidObsTpl'], 'obs'.$element['oo_id_observation']);
310
		return $guid;
310
		return $guid;
311
	}
311
	}
312
	
312
	
313
	private function creerLienItem($element) {
313
	private function creerLienItem($element) {
314
		return $this->config['settings']['odsSaisieUrlAbsolu'];
314
		return $this->config['settings']['odsSaisieUrlAbsolu'];
315
	}
315
	}
316
	
316
	
317
	private function creerAuteur($element) {
317
	private function creerAuteur($element) {
318
		
318
		
319
		//TODO externaliser les champs dans le fichier de config
319
		//TODO externaliser les champs dans le fichier de config
320
		$requete_selection_auteur = 'SELECT name FROM ods_redesign.drupal_users '.
320
		$requete_selection_auteur = 'SELECT name FROM ods_redesign.drupal_users '.
321
									'WHERE uid = '.$this->proteger($element);
321
									'WHERE uid = '.$this->proteger($element);
322
		
322
		
323
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
323
		$resultat_auteur = $this->executerRequete($requete_selection_auteur);
324
		$nom_auteur = $resultat_auteur[0]['name'];
324
		$nom_auteur = $resultat_auteur[0]['name'];
325
 
325
 
326
		return $nom_auteur;
326
		return $nom_auteur;
327
	}
327
	}
328
	
328
	
329
	private function creerDescription($obs, $item) {
329
	private function creerDescription($obs, $item) {
330
		
330
		
331
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
331
		$requete_commune_pour_station = 'SELECT os_ce_commune FROM ods_stations '.
332
										'WHERE os_id_station = '.
332
										'WHERE os_id_station = '.
333
											'(SELECT oi_ce_station FROM ods_individus '. 
333
											'(SELECT oi_ce_station FROM ods_individus '. 
334
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
334
											'WHERE oi_id_individu = '.$this->proteger($obs['oo_ce_individu']).')';
335
		
335
		
336
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
336
		$resultat_commune = $this->executerRequete($requete_commune_pour_station);
337
		$commune = $resultat_commune[0]['os_ce_commune'];
337
		$commune = $resultat_commune[0]['os_ce_commune'];
338
		
338
		
339
		if(is_numeric($commune)) {
339
		if(is_numeric($commune)) {
340
			$requete_lieu = 'SELECT * FROM ods_communes '.
340
			$requete_lieu = 'SELECT * FROM ods_communes '.
341
						'WHERE oc_code_insee = '.$this->proteger($commune);
341
						'WHERE oc_code_insee = '.$this->proteger($commune);
342
		
342
		
343
			$resultat_lieu = $this->executerRequete($requete_lieu);	
343
			$resultat_lieu = $this->executerRequete($requete_lieu);	
344
			$lieu = $resultat_lieu[0]['oc_nom']. ' ('.substr($commune,0,2).')';
344
			$lieu = $resultat_lieu[0]['oc_nom']. ' ('.substr($commune,0,2).')';
345
		} else {
345
		} else {
346
			$lieu = $commune;
346
			$lieu = $commune;
347
		}
347
		}
348
		
348
		
349
		$description = "Observé à $lieu".'<br />';
349
		$description = "Observé à $lieu".'<br />';
350
		
350
		
351
		if($this->mode == 'admin') {
351
		if($this->mode == 'admin') {
352
			
-
 
353
			$description .= ' Individu : '.$obs['oi_nom'].'<br />';	
352
			$description .= ' Individu : '.$obs['oi_nom'].'<br />';	
354
			$description .= 'Station : '.$obs['os_nom'].'<br />';		
353
			$description .= 'Station : '.$obs['os_nom'].'<br />';
-
 
354
			if($this->estUneDateSqlInvalide($obs['oo_date'])) {
-
 
355
				$description .= ' Date d\'observation supprimée <br />';	
-
 
356
			} else {
-
 
357
				$description .= ' Date de l\'observation changée en : '.strftime('%A %d %B %Y', strtotime($obs['oo_date'])).'<br />';	
-
 
358
			}		
355
			$description .= 'Saisi le : '.$item['date_creation_simple'].'<br />';
359
			$description .= 'Saisi le : '.$item['date_creation_simple'].'<br />';
356
			$description .= 'Modifié le : '.$item['date_maj_simple'].'<br />';
360
			$description .= 'Modifié le : '.$item['date_maj_simple'].'<br />';
357
		}
361
		}
358
		
362
		
359
		$description = $this->nettoyerTexte($description);
363
		$description = $this->nettoyerTexte($description);
360
		
364
		
361
		return $description;
365
		return $description;
362
	}
366
	}
-
 
367
	
-
 
368
	private function estUneDateSqlInvalide($date) {
-
 
369
		
-
 
370
		$date_tab = split('-', $date);
-
 
371
		return ($date_tab[2] == '00' || $date_tab[1] == '00' || $date_tab[0] == '0000');
-
 
372
	}
363
	
373
	
364
	private function creerCategorie($element) {
374
	private function creerCategorie($element) {
365
		$categorie = '';
375
		$categorie = '';
366
		$categorie = 'Observation';
376
		$categorie = 'Observation';
367
		$categorie = $this->nettoyerTexte($categorie);
377
		$categorie = $this->nettoyerTexte($categorie);
368
		return $categorie;
378
		return $categorie;
369
	}
379
	}
370
	
380
	
371
	private function etreFluxAdmin() {
381
	private function etreFluxAdmin() {
372
		return ($_GET['admin'] == '1') ? true : false;
382
		return ($_GET['admin'] == '1') ? true : false;
373
	}
383
	}
374
	
384
	
375
	private function creerUrlService() {
385
	private function creerUrlService() {
376
		$url_service = $this->getUrlServiceBase();
386
		$url_service = $this->getUrlServiceBase();
377
		if (count($_GET) > 0) {
387
		if (count($_GET) > 0) {
378
			
388
			
379
			$url_service .= '?';
389
			$url_service .= '?';
380
			$requete = '';
390
			$requete = '';
381
			
391
			
382
			foreach($_GET as $cle => $valeur) {
392
			foreach($_GET as $cle => $valeur) {
383
				if($cle != '' && trim($valeur) != '') {
393
				if($cle != '' && trim($valeur) != '') {
384
					$requete .= '&'.$cle.'='.$valeur;
394
					$requete .= '&'.$cle.'='.$valeur;
385
				}
395
				}
386
			}
396
			}
387
 
397
 
388
			$url_service = $url_service.ltrim($requete, '&');
398
			$url_service = $url_service.ltrim($requete, '&');
389
		}
399
		}
390
		
400
		
391
		return $url_service;
401
		return $url_service;
392
	}
402
	}
393
}	
403
}	
394
 
404
 
395
?>
405
?>