Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2906 Rev 2916
1
<?php
1
<?php
2
/**
2
/**
3
 * Widget fournissant des interfaces de saisie simplifiée pour différent projets
3
 * Widget fournissant des interfaces de saisie simplifiée pour différent projets
4
 *
4
 *
5
 * Cas d'utilisation et documentation :
5
 * Cas d'utilisation et documentation :
6
 * @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie
6
 * @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie
7
 *
7
 *
8
 * Paramètres :
8
 * Paramètres :
9
 * - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé
9
 * - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé
10
 * 		portant ce nom existe, il sera chargé
10
 * 		portant ce nom existe, il sera chargé
11
 * - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé
11
 * - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé
12
 * 		est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore")
12
 * 		est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore")
13
 *
13
 *
14
 * @author Mathias CHOUET <mathias@tela-botanica.org>
14
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
16
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
17
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @copyright 1999-2015 Tela Botanica <accueil@tela-botanica.org>
19
 * @copyright 1999-2015 Tela Botanica <accueil@tela-botanica.org>
20
 */
20
 */
21
class Saisie extends WidgetCommun {
21
class Saisie extends WidgetCommun {
22
 
22
 
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'defaut';
24
	const PROJET_DEFAUT = 'defaut';
25
	const WS_SAISIE = 'CelWidgetSaisie';
25
	const WS_SAISIE = 'CelWidgetSaisie';
26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
27
	const WS_OBS = 'CelObs';
27
	const WS_OBS = 'CelObs';
28
	const WS_NOM = 'noms';
28
	const WS_NOM = 'noms';
29
	const EFLORE_API_VERSION = '0.1';
29
	const EFLORE_API_VERSION = '0.1';
30
	const REFERENTIEL_DEFAUT = 'bdtfx';
30
	const REFERENTIEL_DEFAUT = 'bdtfx';
31
 
31
 
32
	/** référentiel utilisé pour la complétion des noms scientifiques */
32
	/** référentiel utilisé pour la complétion des noms scientifiques */
33
	protected $ns_referentiel;
33
	protected $ns_referentiel;
34
	/** mot-clé associé aux saisies, et template personnalisé si appliquable */
34
	/** mot-clé associé aux saisies, et template personnalisé si appliquable */
35
	protected $projet = null;
35
	protected $projet = null;
36
	protected $configProjet = null;
36
	protected $configProjet = null;
37
	protected $configMission = null;
37
	protected $configMission = null;
38
	protected $mission = null;
38
	protected $mission = null;
39
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
39
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
40
	protected $langue = null;
40
	protected $langue = null;
41
 
41
 
42
	/**
42
	/**
43
	 * Amorçage du widget
43
	 * Amorçage du widget
44
	 */
44
	 */
45
	public function executer() {
45
	public function executer() {
46
		// paramètres par défaut
46
		// paramètres par défaut
47
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
47
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
48
		$this->projet = self::PROJET_DEFAUT;
48
		$this->projet = self::PROJET_DEFAUT;
49
 
49
 
50
		// définition du projet / mission
50
		// définition du projet / mission
51
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
51
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
52
			$projets = explode(',', $this->parametres['projet']);
52
			$projets = explode(',', $this->parametres['projet']);
53
			$this->projet = strtolower($projets[0]);
53
			$this->projet = strtolower($projets[0]);
54
		}
54
		}
55
		$this->chargerConfigProjet();
55
		$this->chargerConfigProjet();
56
 
56
 
57
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
57
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
58
		$retour = null;
58
		$retour = null;
59
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
59
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
60
		$methode = $this->traiterNomMethodeExecuter($service);
60
		$methode = $this->traiterNomMethodeExecuter($service);
61
		if (method_exists($this, $methode)) {
61
		if (method_exists($this, $methode)) {
62
			$retour = $this->$methode();
62
			$retour = $this->$methode();
63
		} else {
63
		} else {
64
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
64
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
65
		}
65
		}
66
 
66
 
67
		// définition de la langue, en mode souple
67
		// définition de la langue, en mode souple
68
		if (isset($this->parametres['lang'])) {
68
		if (isset($this->parametres['lang'])) {
69
			$this->langue = $this->parametres['lang'];
69
			$this->langue = $this->parametres['lang'];
70
		}
70
		}
71
 
71
 
72
		// injection des données dans le squelette
72
		// injection des données dans le squelette
73
		$contenu = null;
73
		$contenu = null;
74
		$mime = null;
74
		$mime = null;
75
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
75
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
76
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
76
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
77
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
77
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
78
			$suffixeLangue = "";
78
			$suffixeLangue = "";
79
			if ($this->langue != null && $this->langue != "fr") {
79
			if ($this->langue != null && $this->langue != "fr") {
80
				$suffixeLangue = "_" . $this->langue;
80
				$suffixeLangue = "_" . $this->langue;
81
			}
81
			}
82
			// Template par défaut ou spécifique
82
			// Template par défaut ou spécifique
83
			if ($this->projetASquelette()) {
83
			if ($this->projetASquelette()) {
84
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
84
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
85
			} else {
85
			} else {
86
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
86
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
87
			}
87
			}
88
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
88
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
89
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
89
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
90
		} else {
90
		} else {
91
			if (count($this->messages) == 0) {
91
			if (count($this->messages) == 0) {
92
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
92
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
93
			}
93
			}
94
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
94
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
95
		}
95
		}
96
 
96
 
97
		// envoi de la page
97
		// envoi de la page
98
		$this->envoyer($contenu, $mime);
98
		$this->envoyer($contenu, $mime);
99
	}
99
	}
100
 
100
 
101
	/**
101
	/**
102
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
102
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
103
	 * Si une mission est définie, charge séparément la section de la configuration concernant
103
	 * Si une mission est définie, charge séparément la section de la configuration concernant
104
	 * cette mission : [nommission]
104
	 * cette mission : [nommission]
105
	 */
105
	 */
106
	protected function chargerConfigProjet() {
106
	protected function chargerConfigProjet() {
107
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
107
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
108
		if (file_exists($fichier_config)) {
108
		if (file_exists($fichier_config)) {
109
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
109
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
110
				if (isset($_GET['mission'])) {
110
				if (isset($_GET['mission'])) {
111
					$this->mission = strtolower(trim($_GET['mission']));
111
					$this->mission = strtolower(trim($_GET['mission']));
112
					if (isset($this->configProjet[$this->mission])) {
112
					if (isset($this->configProjet[$this->mission])) {
113
						$this->configMission = $this->configProjet[$this->mission];
113
						$this->configMission = $this->configProjet[$this->mission];
114
					}
114
					}
115
				}
115
				}
116
			} else {
116
			} else {
117
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
117
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
118
			}
118
			}
119
		} else {
119
		} else {
120
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
120
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
121
		}
121
		}
122
	}
122
	}
123
 
123
 
124
	/**
124
	/**
125
	 * Retourne true si le dossier du projet courant existe, false sinon
125
	 * Retourne true si le dossier du projet courant existe, false sinon
126
	 * @return boolean
126
	 * @return boolean
127
	 */
127
	 */
128
	protected function projetASquelette() {
128
	protected function projetASquelette() {
129
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
129
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
130
	}
130
	}
131
 
131
 
132
	/**
132
	/**
133
	 * Exécution du widget complet 
133
	 * Exécution du widget complet 
134
	 * @return Ambigous <string, unknown, multitype:string unknown >
134
	 * @return Ambigous <string, unknown, multitype:string unknown >
135
	 */
135
	 */
136
	public function executerWidget() {
136
	public function executerWidget() {
137
		$widget['squelette'] = $this->projet;
137
		$widget['squelette'] = $this->projet;
138
		$widget['donnees'] = array();
138
		$widget['donnees'] = array();
139
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
139
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
140
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
140
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
141
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
141
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
142
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
142
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
143
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
143
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
144
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
144
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
145
 
145
 
146
		$widget['donnees']['logo'] = $this->getLogoPage();
146
		$widget['donnees']['logo'] = $this->getLogoPage();
147
		$widget['donnees']['titre'] = $this->getTitrePage();
147
		$widget['donnees']['titre'] = $this->getTitrePage();
148
		$widget['donnees']['nom_mission'] = $this->getNomMissionFlore();
148
		$widget['donnees']['nom_mission'] = $this->getNomMissionFlore();
149
 
149
 
150
		$widget['donnees']['zone_geo'] = $this->getZoneGeo();
150
		$widget['donnees']['zone_geo'] = $this->getZoneGeo();
-
 
151
		$widget['donnees']['groupe_zones_geo'] = $this->getGroupeZonesGeo();
151
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
152
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
152
		$widget['donnees']['espece_imposee'] = false;
153
		$widget['donnees']['espece_imposee'] = false;
153
		$widget['donnees']['nn_espece_defaut'] = '';
154
		$widget['donnees']['nn_espece_defaut'] = '';
154
		$widget['donnees']['nom_sci_espece_defaut'] = '';
155
		$widget['donnees']['nom_sci_espece_defaut'] = '';
155
		$widget['donnees']['infos_espece'] = '{}';
156
		$widget['donnees']['infos_espece'] = '{}';
156
 
157
 
157
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
158
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
158
		
159
		
159
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
160
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
160
 
161
 
161
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
162
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
162
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
163
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
163
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
164
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
164
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
165
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
165
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
166
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
166
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
167
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
-
 
168
		
167
		
169
		$widget['donnees']['url_ws_coord_search_tpl'] = $this->config['chemins']['serviceCoordSearchUrl'];
168
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
170
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
169
		
171
		
170
		if ($this->especeEstImposee()) {
172
		if ($this->especeEstImposee()) {
171
			$nnEspeceImposee = $this->getNnEspeceImposee();
173
			$nnEspeceImposee = $this->getNnEspeceImposee();
172
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
174
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
173
			$widget['donnees']['espece_imposee'] = true;
175
			$widget['donnees']['espece_imposee'] = true;
174
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
176
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
175
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
177
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
176
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
178
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
177
		}
179
		}
178
 
180
 
179
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
181
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
180
		if (in_array($this->projet, $projetsAListeDeNoms)) {
182
		if (in_array($this->projet, $projetsAListeDeNoms)) {
181
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
183
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
182
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
184
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
183
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
185
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
184
			} else {
186
			} else {
185
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
187
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
186
			}
188
			}
187
		}
189
		}
188
 
190
 
189
		// Chargement de la liste des milieux issues du fichier .ini du projet
191
		// Chargement de la liste des milieux issues du fichier .ini du projet
190
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
192
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
191
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
193
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
192
			$widget['donnees']['milieux'] = $this->parserMilieux();
194
			$widget['donnees']['milieux'] = $this->parserMilieux();
193
		}
195
		}
194
 
196
 
195
		return $widget;
197
		return $widget;
196
	}
198
	}
197
 
199
 
198
	protected function getTitrePage() {
200
	protected function getTitrePage() {
199
		$titre = 'defaut';
201
		$titre = 'defaut';
200
		if (isset($this->configProjet['titre_page'])) {
202
		if (isset($this->configProjet['titre_page'])) {
201
			$titre = $this->configProjet['titre_page'];
203
			$titre = $this->configProjet['titre_page'];
202
		}
204
		}
203
		if (isset($this->configMission['titre_page'])) {
205
		if (isset($this->configMission['titre_page'])) {
204
			$titre = $this->configMission['titre_page'];
206
			$titre = $this->configMission['titre_page'];
205
		}
207
		}
206
		if (isset($_GET['titre'])) {
208
		if (isset($_GET['titre'])) {
207
			$titre = $_GET['titre'];
209
			$titre = $_GET['titre'];
208
		}
210
		}
209
		if ($titre === 0) { // wtf ?
211
		if ($titre === 0) { // wtf ?
210
			$titre = '';
212
			$titre = '';
211
		}
213
		}
212
		return $titre;
214
		return $titre;
213
	}
215
	}
214
 
216
 
215
	protected function getLogoPage() {
217
	protected function getLogoPage() {
216
		$logo = 'defaut';
218
		$logo = 'defaut';
217
		if (isset($this->configProjet['logo_page'])) {
219
		if (isset($this->configProjet['logo_page'])) {
218
			$logo = $this->configProjet['logo_page'];
220
			$logo = $this->configProjet['logo_page'];
219
		}
221
		}
220
		if (isset($this->configMission['logo_page'])) {
222
		if (isset($this->configMission['logo_page'])) {
221
			$logo = $this->configMission['logo_page'];
223
			$logo = $this->configMission['logo_page'];
222
		}
224
		}
223
		if (isset($_GET['logo'])) {
225
		if (isset($_GET['logo'])) {
224
			$logo = $_GET['logo'];
226
			$logo = $_GET['logo'];
225
		}
227
		}
226
		return $logo;
228
		return $logo;
227
	}
229
	}
228
	
230
 
-
 
231
	protected function getGroupeZonesGeo() {
-
 
232
		$groupe = null;
-
 
233
		if (isset($_GET['groupe_zones_geo'])) {
-
 
234
			$groupe = $_GET['groupe_zones_geo'];
-
 
235
		}
-
 
236
		return $groupe;
-
 
237
	}
-
 
238
 
229
	protected function getZoneGeo() {
239
	protected function getZoneGeo() {
230
		$zone_geo = null;
240
		$zone_geo = null;
231
		if (isset($_GET['zone_geo'])) {
241
		if (isset($_GET['zone_geo'])) {
232
			$zone_geo = $_GET['zone_geo'];
242
			$zone_geo = $_GET['zone_geo'];
233
		}
243
		}
234
		return $zone_geo;
244
		return $zone_geo;
235
	}
245
	}
236
 
246
 
237
	protected function getReferentielImpose() {
247
	protected function getReferentielImpose() {
238
		$referentiel_impose = true;
248
		$referentiel_impose = true;
239
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
249
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
240
			$this->ns_referentiel = $_GET['referentiel'];
250
			$this->ns_referentiel = $_GET['referentiel'];
241
		} else if (isset($this->configProjet['referentiel'])) {
251
		} else if (isset($this->configProjet['referentiel'])) {
242
			$this->ns_referentiel = $this->configProjet['referentiel'];
252
			$this->ns_referentiel = $this->configProjet['referentiel'];
243
		} else if (isset($this->configMission['referentiel'])) {
253
		} else if (isset($this->configMission['referentiel'])) {
244
			$this->ns_referentiel = $this->configMission['referentiel'];
254
			$this->ns_referentiel = $this->configMission['referentiel'];
245
		} else {
255
		} else {
246
			$referentiel_impose = false;
256
			$referentiel_impose = false;
247
		}
257
		}
248
		return $referentiel_impose;
258
		return $referentiel_impose;
249
	}
259
	}
250
 
260
 
251
	/**
261
	/**
252
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
262
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
253
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
263
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
254
	 */
264
	 */
255
	protected function getNomMissionFlore() {
265
	protected function getNomMissionFlore() {
256
		$nom = $this->mission;
266
		$nom = $this->mission;
257
		if (isset($this->configMission['nom_mission'])) {
267
		if (isset($this->configMission['nom_mission'])) {
258
			$nom = $this->configMission['nom_mission'];
268
			$nom = $this->configMission['nom_mission'];
259
		}
269
		}
260
		return $nom;
270
		return $nom;
261
	}
271
	}
262
 
272
 
263
	/**
273
	/**
264
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
274
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
265
	 * pour certains projets
275
	 * pour certains projets
266
	 * @return string
276
	 * @return string
267
	 */
277
	 */
268
	public function executerTaxons() {
278
	public function executerTaxons() {
269
		$widget['squelette'] = $this->projet.'_taxons';
279
		$widget['squelette'] = $this->projet.'_taxons';
270
		$widget['squelette_ext'] = '.tpl.js';
280
		$widget['squelette_ext'] = '.tpl.js';
271
		$widget['donnees'] = array();
281
		$widget['donnees'] = array();
272
		$nomsAAfficher = $this->recupererListeNomsSci();
282
		$nomsAAfficher = $this->recupererListeNomsSci();
273
		$taxons_tries = array();
283
		$taxons_tries = array();
274
		foreach ($nomsAAfficher as $taxon) {
284
		foreach ($nomsAAfficher as $taxon) {
275
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
285
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
276
		}
286
		}
277
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
287
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
278
		return $widget;
288
		return $widget;
279
	}
289
	}
280
 
290
 
281
	/**
291
	/**
282
	 * Trie par nom français les taxons lus dans le fichier tsv
292
	 * Trie par nom français les taxons lus dans le fichier tsv
283
	 */
293
	 */
284
	protected function recupererListeNomsSci() {
294
	protected function recupererListeNomsSci() {
285
		$taxons = $this->recupererListeTaxon();
295
		$taxons = $this->recupererListeTaxon();
286
		if (is_array($taxons)) {
296
		if (is_array($taxons)) {
287
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
297
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
288
		}
298
		}
289
		return $taxons;
299
		return $taxons;
290
	}
300
	}
291
 
301
 
292
	/**
302
	/**
293
	 * @TODO documenter
303
	 * @TODO documenter
294
	 * @return array
304
	 * @return array
295
	 */
305
	 */
296
	protected function recupererListeNoms() {
306
	protected function recupererListeNoms() {
297
		$taxons = $this->recupererListeTaxon();
307
		$taxons = $this->recupererListeTaxon();
298
		$nomsAAfficher = array();
308
		$nomsAAfficher = array();
299
		$nomsSpeciaux = array();
309
		$nomsSpeciaux = array();
300
		if (is_array($taxons)) {
310
		if (is_array($taxons)) {
301
			foreach ($taxons as $taxon) {
311
			foreach ($taxons as $taxon) {
302
				$nomSciTitle = $taxon['nom_ret'].
312
				$nomSciTitle = $taxon['nom_ret'].
303
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
313
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
304
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
314
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
305
				$nomFrTitle = $taxon['nom_sel'].
315
				$nomFrTitle = $taxon['nom_sel'].
306
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
316
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
307
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
317
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
308
 
318
 
309
				if ($taxon['groupe'] == 'special') {
319
				if ($taxon['groupe'] == 'special') {
310
					$nomsSpeciaux[] = array(
320
					$nomsSpeciaux[] = array(
311
						'num_nom' => $taxon['num_nom_sel'],
321
						'num_nom' => $taxon['num_nom_sel'],
312
						'nom_a_afficher' => $taxon['nom_fr'],
322
						'nom_a_afficher' => $taxon['nom_fr'],
313
						'nom_a_sauver' => $taxon['nom_sel'],
323
						'nom_a_sauver' => $taxon['nom_sel'],
314
						'nom_title' => $nomSciTitle,
324
						'nom_title' => $nomSciTitle,
315
						'nom_type' => 'nom-special');
325
						'nom_type' => 'nom-special');
316
				} else {
326
				} else {
317
					$nomsAAfficher[] = array(
327
					$nomsAAfficher[] = array(
318
						'num_nom' => $taxon['num_nom_sel'],
328
						'num_nom' => $taxon['num_nom_sel'],
319
						'nom_a_afficher' => $taxon['nom_sel'],
329
						'nom_a_afficher' => $taxon['nom_sel'],
320
						'nom_a_sauver' => $taxon['nom_sel'],
330
						'nom_a_sauver' => $taxon['nom_sel'],
321
						'nom_title' => $nomSciTitle,
331
						'nom_title' => $nomSciTitle,
322
						'nom_type' => 'nom-sci');
332
						'nom_type' => 'nom-sci');
323
					$nomsAAfficher[] = array(
333
					$nomsAAfficher[] = array(
324
						'num_nom' => $taxon['num_nom_sel'],
334
						'num_nom' => $taxon['num_nom_sel'],
325
						'nom_a_afficher' => $taxon['nom_fr'],
335
						'nom_a_afficher' => $taxon['nom_fr'],
326
						'nom_a_sauver' => $taxon['nom_fr'],
336
						'nom_a_sauver' => $taxon['nom_fr'],
327
						'nom_title' => $nomFrTitle,
337
						'nom_title' => $nomFrTitle,
328
						'nom_type' => 'nom-fr');
338
						'nom_type' => 'nom-fr');
329
				}
339
				}
330
			}
340
			}
331
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
341
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
332
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
342
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
333
		}
343
		}
334
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
344
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
335
	}
345
	}
336
 
346
 
337
	/**
347
	/**
338
	 * Lit une liste de taxons depuis un fichier tsv fourni
348
	 * Lit une liste de taxons depuis un fichier tsv fourni
339
	 */
349
	 */
340
	protected function recupererListeTaxon() {
350
	protected function recupererListeTaxon() {
341
		$taxons = array();
351
		$taxons = array();
342
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
352
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
343
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
353
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
344
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
354
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
345
		} else {
355
		} else {
346
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
356
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
347
		}
357
		}
348
		return $taxons;
358
		return $taxons;
349
	}
359
	}
350
 
360
 
351
	/**
361
	/**
352
	 * Découpe un fihcier tsv
362
	 * Découpe un fihcier tsv
353
	 */
363
	 */
354
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
364
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
355
		$header = null;
365
		$header = null;
356
		$data = array();
366
		$data = array();
357
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
367
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
358
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
368
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
359
				if (!$header) {
369
				if (!$header) {
360
					$header = $row;
370
					$header = $row;
361
				} else {
371
				} else {
362
					$data[] = array_combine($header, $row);
372
					$data[] = array_combine($header, $row);
363
				}
373
				}
364
			}
374
			}
365
			fclose($handle);
375
			fclose($handle);
366
		}
376
		}
367
		return $data;
377
		return $data;
368
	}
378
	}
369
 
379
 
370
	/**
380
	/**
371
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
381
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
372
	 * du projet, si elle existe
382
	 * du projet, si elle existe
373
	 * @return array
383
	 * @return array
374
	 */
384
	 */
375
	protected function parserMilieux() {
385
	protected function parserMilieux() {
376
		$infosMilieux = array();
386
		$infosMilieux = array();
377
		if (isset($this->configProjet['milieux'])) {
387
		if (isset($this->configProjet['milieux'])) {
378
			$milieux = explode('|', $this->configProjet['milieux']);
388
			$milieux = explode('|', $this->configProjet['milieux']);
379
			foreach ($milieux as $milieu) {
389
			foreach ($milieux as $milieu) {
380
				$milieu = trim($milieu);
390
				$milieu = trim($milieu);
381
				$details = explode(';', $milieu);
391
				$details = explode(';', $milieu);
382
				if (isset($details[1])) {
392
				if (isset($details[1])) {
383
					$infosMilieux[$details[0]] = $details[1];
393
					$infosMilieux[$details[0]] = $details[1];
384
				} else {
394
				} else {
385
					$infosMilieux[$details[0]] = '';
395
					$infosMilieux[$details[0]] = '';
386
				}
396
				}
387
			}
397
			}
388
			ksort($infosMilieux);
398
			ksort($infosMilieux);
389
		}
399
		}
390
		return $infosMilieux;
400
		return $infosMilieux;
391
	}
401
	}
392
 
402
 
393
	/**
403
	/**
394
	 * Retourne true si le widget est restreint à une espèce, false sinon
404
	 * Retourne true si le widget est restreint à une espèce, false sinon
395
	 * @return boolean
405
	 * @return boolean
396
	 */
406
	 */
397
	protected function especeEstImposee() {
407
	protected function especeEstImposee() {
398
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
408
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
399
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
409
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
400
	}
410
	}
401
 
411
 
402
	/**
412
	/**
403
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
413
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
404
	 * le cas, null sinon
414
	 * le cas, null sinon
405
	 * @return string
415
	 * @return string
406
	 */
416
	 */
407
	protected function getNnEspeceImposee() {
417
	protected function getNnEspeceImposee() {
408
		$nn = null;
418
		$nn = null;
409
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
419
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
410
			$nn = $_GET['num_nom'];
420
			$nn = $_GET['num_nom'];
411
		} else if (isset($this->configProjet['sp_imposee'])) {
421
		} else if (isset($this->configProjet['sp_imposee'])) {
412
			$nn = $this->configProjet['sp_imposee'];
422
			$nn = $this->configProjet['sp_imposee'];
413
		} else if (isset($this->configMission['sp_imposee'])) {
423
		} else if (isset($this->configMission['sp_imposee'])) {
414
			$nn = $this->configMission['sp_imposee'];
424
			$nn = $this->configMission['sp_imposee'];
415
		}
425
		}
416
		return $nn;
426
		return $nn;
417
	}
427
	}
418
 
428
 
419
	/**
429
	/**
420
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
430
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
421
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
431
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
422
	 * et non le taxon?)
432
	 * et non le taxon?)
423
	 * @param string|int $num_nom
433
	 * @param string|int $num_nom
424
	 * @return array
434
	 * @return array
425
	 */
435
	 */
426
	protected function chargerInfosTaxon($num_nom) {
436
	protected function chargerInfosTaxon($num_nom) {
427
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
437
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
428
		$infos = json_decode(file_get_contents($url_service_infos));
438
		$infos = json_decode(file_get_contents($url_service_infos));
429
		// trop de champs injectés dans les infos espèces peuvent
439
		// trop de champs injectés dans les infos espèces peuvent
430
		// faire planter javascript
440
		// faire planter javascript
431
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
441
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
432
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
442
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
433
		$resultat = array();
443
		$resultat = array();
434
		if (isset($infos) && !empty($infos)) {
444
		if (isset($infos) && !empty($infos)) {
435
			$infos = (array)$infos;
445
			$infos = (array)$infos;
436
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
446
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
437
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
447
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
438
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
448
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
439
			}
449
			}
440
		}
450
		}
441
		return $resultat;
451
		return $resultat;
442
	}
452
	}
443
 
453
 
444
	/**
454
	/**
445
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
455
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
446
	 * @param array $array
456
	 * @param array $array
447
	 * @param boolean $show_keys
457
	 * @param boolean $show_keys
448
	 * @return une portion de JSON représentant le tableau
458
	 * @return une portion de JSON représentant le tableau
449
	 */
459
	 */
450
	protected function array2js($array,$show_keys) {
460
	protected function array2js($array,$show_keys) {
451
		$tableauJs = '{}';
461
		$tableauJs = '{}';
452
		if (!empty($array)) {
462
		if (!empty($array)) {
453
			$total = count($array) - 1;
463
			$total = count($array) - 1;
454
			$i = 0;
464
			$i = 0;
455
			$dimensions = array();
465
			$dimensions = array();
456
			foreach ($array as $key => $value) {
466
			foreach ($array as $key => $value) {
457
				if (is_array($value)) {
467
				if (is_array($value)) {
458
					$dimensions[$i] = array2js($value,$show_keys);
468
					$dimensions[$i] = array2js($value,$show_keys);
459
					if ($show_keys) {
469
					if ($show_keys) {
460
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
470
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
461
					}
471
					}
462
				} else {
472
				} else {
463
					$dimensions[$i] = '"'.addslashes($value).'"';
473
					$dimensions[$i] = '"'.addslashes($value).'"';
464
					if ($show_keys) {
474
					if ($show_keys) {
465
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
475
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
466
					}
476
					}
467
				}
477
				}
468
				if ($i == 0) {
478
				if ($i == 0) {
469
					$dimensions[$i] = '{'.$dimensions[$i];
479
					$dimensions[$i] = '{'.$dimensions[$i];
470
				}
480
				}
471
				if ($i == $total) {
481
				if ($i == $total) {
472
					$dimensions[$i].= '}';
482
					$dimensions[$i].= '}';
473
				}
483
				}
474
				$i++;
484
				$i++;
475
			}
485
			}
476
			$tableauJs = implode(',', $dimensions);
486
			$tableauJs = implode(',', $dimensions);
477
		}
487
		}
478
		return $tableauJs;
488
		return $tableauJs;
479
	}
489
	}
480
}
490
}