Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2870 Rev 2904
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 al complétion des noms scientifiques */
32
	/** référentiel utilisé pour al 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']['referentiel_impose'] = $this->getReferentielImpose();
150
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
151
		$widget['donnees']['espece_imposee'] = false;
151
		$widget['donnees']['espece_imposee'] = false;
152
		$widget['donnees']['nn_espece_defaut'] = '';
152
		$widget['donnees']['nn_espece_defaut'] = '';
153
		$widget['donnees']['nom_sci_espece_defaut'] = '';
153
		$widget['donnees']['nom_sci_espece_defaut'] = '';
154
		$widget['donnees']['infos_espece'] = '{}';
154
		$widget['donnees']['infos_espece'] = '{}';
155
 
155
 
156
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
156
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
157
		
157
		
158
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
158
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
159
 
159
 
160
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
160
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
161
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
161
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
162
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
162
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
163
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
163
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
164
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
164
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
165
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
165
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
166
		
166
		
167
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
167
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
168
		
168
		
169
		if ($this->especeEstImposee()) {
169
		if ($this->especeEstImposee()) {
170
			$nnEspeceImposee = $this->getNnEspeceImposee();
170
			$nnEspeceImposee = $this->getNnEspeceImposee();
171
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
171
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
172
			$widget['donnees']['espece_imposee'] = true;
172
			$widget['donnees']['espece_imposee'] = true;
173
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
173
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
174
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
174
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
175
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
175
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
176
		}
176
		}
177
 
177
 
178
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
178
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
179
		if (in_array($this->projet, $projetsAListeDeNoms)) {
179
		if (in_array($this->projet, $projetsAListeDeNoms)) {
180
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
180
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
181
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
181
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
182
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
182
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
183
			} else {
183
			} else {
184
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
184
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
185
			}
185
			}
186
		}
186
		}
187
 
187
 
188
		// Chargement de la liste des milieux issues du fichier .ini du projet
188
		// Chargement de la liste des milieux issues du fichier .ini du projet
189
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
189
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
190
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
190
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
191
			$widget['donnees']['milieux'] = $this->parserMilieux();
191
			$widget['donnees']['milieux'] = $this->parserMilieux();
192
		}
192
		}
193
 
193
 
194
		return $widget;
194
		return $widget;
195
	}
195
	}
196
 
196
 
197
	protected function getTitrePage() {
197
	protected function getTitrePage() {
198
		$titre = 'defaut';
198
		$titre = 'defaut';
199
		if (isset($this->configProjet['titre_page'])) {
199
		if (isset($this->configProjet['titre_page'])) {
200
			$titre = $this->configProjet['titre_page'];
200
			$titre = $this->configProjet['titre_page'];
201
		}
201
		}
202
		if (isset($this->configMission['titre_page'])) {
202
		if (isset($this->configMission['titre_page'])) {
203
			$titre = $this->configMission['titre_page'];
203
			$titre = $this->configMission['titre_page'];
204
		}
204
		}
205
		if (isset($_GET['titre'])) {
205
		if (isset($_GET['titre'])) {
206
			$titre = $_GET['titre'];
206
			$titre = $_GET['titre'];
207
		}
207
		}
208
		if ($titre === 0) { // wtf ?
208
		if ($titre === 0) { // wtf ?
209
			$titre = '';
209
			$titre = '';
210
		}
210
		}
211
		return $titre;
211
		return $titre;
212
	}
212
	}
213
 
-
 
214
 
213
 
215
	protected function getLogoPage() {
214
	protected function getLogoPage() {
216
		$logo = 'defaut';
215
		$logo = 'defaut';
217
		if (isset($this->configProjet['logo_page'])) {
216
		if (isset($this->configProjet['logo_page'])) {
218
			$logo = $this->configProjet['logo_page'];
217
			$logo = $this->configProjet['logo_page'];
219
		}
218
		}
220
		if (isset($this->configMission['logo_page'])) {
219
		if (isset($this->configMission['logo_page'])) {
221
			$logo = $this->configMission['logo_page'];
220
			$logo = $this->configMission['logo_page'];
222
		}
221
		}
223
		if (isset($_GET['logo'])) {
222
		if (isset($_GET['logo'])) {
224
			$logo = $_GET['logo'];
223
			$logo = $_GET['logo'];
225
		}
224
		}
226
		return $logo;
225
		return $logo;
227
	}
226
	}
228
 
227
 
229
	protected function getReferentielImpose() {
228
	protected function getReferentielImpose() {
-
 
229
		$referentiel_impose = false;
-
 
230
		if (isset($this->configProjet['referentiel'])) {
-
 
231
			$this->ns_referentiel = $this->configProjet['referentiel'];
230
		$referentiel_impose = true;
232
			$referentiel_impose = true;
-
 
233
		}
231
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
234
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
232
			$this->ns_referentiel = $_GET['referentiel'];
235
			$this->ns_referentiel = $_GET['referentiel'];
233
		} else if (isset($this->configProjet['referentiel'])) {
-
 
234
			$this->ns_referentiel = $this->configProjet['referentiel'];
-
 
235
		} else if (isset($this->configMission['referentiel'])) {
-
 
236
			$this->ns_referentiel = $this->configMission['referentiel'];
-
 
237
		} else {
-
 
238
			$referentiel_impose = false;
236
			$referentiel_impose = true;
239
		}
237
		}
240
		return $referentiel_impose;
238
		return $referentiel_impose;
241
	}
239
	}
242
 
240
 
243
	/**
241
	/**
244
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
242
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
245
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
243
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
246
	 */
244
	 */
247
	protected function getNomMissionFlore() {
245
	protected function getNomMissionFlore() {
248
		$nom = $this->mission;
246
		$nom = $this->mission;
249
		if (isset($this->configMission['nom_mission'])) {
247
		if (isset($this->configMission['nom_mission'])) {
250
			$nom = $this->configMission['nom_mission'];
248
			$nom = $this->configMission['nom_mission'];
251
		}
249
		}
252
		return $nom;
250
		return $nom;
253
	}
251
	}
254
 
252
 
255
	/**
253
	/**
256
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
254
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
257
	 * pour certains projets
255
	 * pour certains projets
258
	 * @return string
256
	 * @return string
259
	 */
257
	 */
260
	public function executerTaxons() {
258
	public function executerTaxons() {
261
		$widget['squelette'] = $this->projet.'_taxons';
259
		$widget['squelette'] = $this->projet.'_taxons';
262
		$widget['squelette_ext'] = '.tpl.js';
260
		$widget['squelette_ext'] = '.tpl.js';
263
		$widget['donnees'] = array();
261
		$widget['donnees'] = array();
264
		$nomsAAfficher = $this->recupererListeNomsSci();
262
		$nomsAAfficher = $this->recupererListeNomsSci();
265
		$taxons_tries = array();
263
		$taxons_tries = array();
266
		foreach ($nomsAAfficher as $taxon) {
264
		foreach ($nomsAAfficher as $taxon) {
267
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
265
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
268
		}
266
		}
269
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
267
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
270
		return $widget;
268
		return $widget;
271
	}
269
	}
272
 
270
 
273
	/**
271
	/**
274
	 * Trie par nom français les taxons lus dans le fichier tsv
272
	 * Trie par nom français les taxons lus dans le fichier tsv
275
	 */
273
	 */
276
	protected function recupererListeNomsSci() {
274
	protected function recupererListeNomsSci() {
277
		$taxons = $this->recupererListeTaxon();
275
		$taxons = $this->recupererListeTaxon();
278
		if (is_array($taxons)) {
276
		if (is_array($taxons)) {
279
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
277
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
280
		}
278
		}
281
		return $taxons;
279
		return $taxons;
282
	}
280
	}
283
 
281
 
284
	/**
282
	/**
285
	 * @TODO documenter
283
	 * @TODO documenter
286
	 * @return array
284
	 * @return array
287
	 */
285
	 */
288
	protected function recupererListeNoms() {
286
	protected function recupererListeNoms() {
289
		$taxons = $this->recupererListeTaxon();
287
		$taxons = $this->recupererListeTaxon();
290
		$nomsAAfficher = array();
288
		$nomsAAfficher = array();
291
		$nomsSpeciaux = array();
289
		$nomsSpeciaux = array();
292
		if (is_array($taxons)) {
290
		if (is_array($taxons)) {
293
			foreach ($taxons as $taxon) {
291
			foreach ($taxons as $taxon) {
294
				$nomSciTitle = $taxon['nom_ret'].
292
				$nomSciTitle = $taxon['nom_ret'].
295
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
293
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
296
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
294
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
297
				$nomFrTitle = $taxon['nom_sel'].
295
				$nomFrTitle = $taxon['nom_sel'].
298
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
296
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
299
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
297
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
300
 
298
 
301
				if ($taxon['groupe'] == 'special') {
299
				if ($taxon['groupe'] == 'special') {
302
					$nomsSpeciaux[] = array(
300
					$nomsSpeciaux[] = array(
303
						'num_nom' => $taxon['num_nom_sel'],
301
						'num_nom' => $taxon['num_nom_sel'],
304
						'nom_a_afficher' => $taxon['nom_fr'],
302
						'nom_a_afficher' => $taxon['nom_fr'],
305
						'nom_a_sauver' => $taxon['nom_sel'],
303
						'nom_a_sauver' => $taxon['nom_sel'],
306
						'nom_title' => $nomSciTitle,
304
						'nom_title' => $nomSciTitle,
307
						'nom_type' => 'nom-special');
305
						'nom_type' => 'nom-special');
308
				} else {
306
				} else {
309
					$nomsAAfficher[] = array(
307
					$nomsAAfficher[] = array(
310
						'num_nom' => $taxon['num_nom_sel'],
308
						'num_nom' => $taxon['num_nom_sel'],
311
						'nom_a_afficher' => $taxon['nom_sel'],
309
						'nom_a_afficher' => $taxon['nom_sel'],
312
						'nom_a_sauver' => $taxon['nom_sel'],
310
						'nom_a_sauver' => $taxon['nom_sel'],
313
						'nom_title' => $nomSciTitle,
311
						'nom_title' => $nomSciTitle,
314
						'nom_type' => 'nom-sci');
312
						'nom_type' => 'nom-sci');
315
					$nomsAAfficher[] = array(
313
					$nomsAAfficher[] = array(
316
						'num_nom' => $taxon['num_nom_sel'],
314
						'num_nom' => $taxon['num_nom_sel'],
317
						'nom_a_afficher' => $taxon['nom_fr'],
315
						'nom_a_afficher' => $taxon['nom_fr'],
318
						'nom_a_sauver' => $taxon['nom_fr'],
316
						'nom_a_sauver' => $taxon['nom_fr'],
319
						'nom_title' => $nomFrTitle,
317
						'nom_title' => $nomFrTitle,
320
						'nom_type' => 'nom-fr');
318
						'nom_type' => 'nom-fr');
321
				}
319
				}
322
			}
320
			}
323
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
321
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
324
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
322
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
325
		}
323
		}
326
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
324
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
327
	}
325
	}
328
 
326
 
329
	/**
327
	/**
330
	 * Lit une liste de taxons depuis un fichier tsv fourni
328
	 * Lit une liste de taxons depuis un fichier tsv fourni
331
	 */
329
	 */
332
	protected function recupererListeTaxon() {
330
	protected function recupererListeTaxon() {
333
		$taxons = array();
331
		$taxons = array();
334
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
332
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
335
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
333
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
336
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
334
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
337
		} else {
335
		} else {
338
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
336
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
339
		}
337
		}
340
		return $taxons;
338
		return $taxons;
341
	}
339
	}
342
 
340
 
343
	/**
341
	/**
344
	 * Découpe un fihcier tsv
342
	 * Découpe un fihcier tsv
345
	 */
343
	 */
346
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
344
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
347
		$header = null;
345
		$header = null;
348
		$data = array();
346
		$data = array();
349
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
347
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
350
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
348
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
351
				if (!$header) {
349
				if (!$header) {
352
					$header = $row;
350
					$header = $row;
353
				} else {
351
				} else {
354
					$data[] = array_combine($header, $row);
352
					$data[] = array_combine($header, $row);
355
				}
353
				}
356
			}
354
			}
357
			fclose($handle);
355
			fclose($handle);
358
		}
356
		}
359
		return $data;
357
		return $data;
360
	}
358
	}
361
 
359
 
362
	/**
360
	/**
363
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
361
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
364
	 * du projet, si elle existe
362
	 * du projet, si elle existe
365
	 * @return array
363
	 * @return array
366
	 */
364
	 */
367
	protected function parserMilieux() {
365
	protected function parserMilieux() {
368
		$infosMilieux = array();
366
		$infosMilieux = array();
369
		if (isset($this->configProjet['milieux'])) {
367
		if (isset($this->configProjet['milieux'])) {
370
			$milieux = explode('|', $this->configProjet['milieux']);
368
			$milieux = explode('|', $this->configProjet['milieux']);
371
			foreach ($milieux as $milieu) {
369
			foreach ($milieux as $milieu) {
372
				$milieu = trim($milieu);
370
				$milieu = trim($milieu);
373
				$details = explode(';', $milieu);
371
				$details = explode(';', $milieu);
374
				if (isset($details[1])) {
372
				if (isset($details[1])) {
375
					$infosMilieux[$details[0]] = $details[1];
373
					$infosMilieux[$details[0]] = $details[1];
376
				} else {
374
				} else {
377
					$infosMilieux[$details[0]] = '';
375
					$infosMilieux[$details[0]] = '';
378
				}
376
				}
379
			}
377
			}
380
			ksort($infosMilieux);
378
			ksort($infosMilieux);
381
		}
379
		}
382
		return $infosMilieux;
380
		return $infosMilieux;
383
	}
381
	}
384
 
382
 
385
	/**
383
	/**
386
	 * Retourne true si le widget est restreint à une espèce, false sinon
384
	 * Retourne true si le widget est restreint à une espèce, false sinon
387
	 * @return boolean
385
	 * @return boolean
388
	 */
386
	 */
389
	protected function especeEstImposee() {
387
	protected function especeEstImposee() {
390
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
388
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
391
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
389
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
392
	}
390
	}
393
 
391
 
394
	/**
392
	/**
395
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
393
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
396
	 * le cas, null sinon
394
	 * le cas, null sinon
397
	 * @return string
395
	 * @return string
398
	 */
396
	 */
399
	protected function getNnEspeceImposee() {
397
	protected function getNnEspeceImposee() {
400
		$nn = null;
398
		$nn = null;
401
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
399
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
402
			$nn = $_GET['num_nom'];
400
			$nn = $_GET['num_nom'];
403
		} else if (isset($this->configProjet['sp_imposee'])) {
401
		} else if (isset($this->configProjet['sp_imposee'])) {
404
			$nn = $this->configProjet['sp_imposee'];
402
			$nn = $this->configProjet['sp_imposee'];
405
		} else if (isset($this->configMission['sp_imposee'])) {
403
		} else if (isset($this->configMission['sp_imposee'])) {
406
			$nn = $this->configMission['sp_imposee'];
404
			$nn = $this->configMission['sp_imposee'];
407
		}
405
		}
408
		return $nn;
406
		return $nn;
409
	}
407
	}
410
 
408
 
411
	/**
409
	/**
412
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
410
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
413
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
411
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
414
	 * et non le taxon?)
412
	 * et non le taxon?)
415
	 * @param string|int $num_nom
413
	 * @param string|int $num_nom
416
	 * @return array
414
	 * @return array
417
	 */
415
	 */
418
	protected function chargerInfosTaxon($num_nom) {
416
	protected function chargerInfosTaxon($num_nom) {
419
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
417
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
420
		$infos = json_decode(file_get_contents($url_service_infos));
418
		$infos = json_decode(file_get_contents($url_service_infos));
421
		// trop de champs injectés dans les infos espèces peuvent
419
		// trop de champs injectés dans les infos espèces peuvent
422
		// faire planter javascript
420
		// faire planter javascript
423
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
421
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
424
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
422
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
425
		$resultat = array();
423
		$resultat = array();
426
		if (isset($infos) && !empty($infos)) {
424
		if (isset($infos) && !empty($infos)) {
427
			$infos = (array)$infos;
425
			$infos = (array)$infos;
428
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
426
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
429
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
427
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
430
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
428
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
431
			}
429
			}
432
		}
430
		}
433
		return $resultat;
431
		return $resultat;
434
	}
432
	}
435
 
433
 
436
	/**
434
	/**
437
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
435
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
438
	 * @param array $array
436
	 * @param array $array
439
	 * @param boolean $show_keys
437
	 * @param boolean $show_keys
440
	 * @return une portion de JSON représentant le tableau
438
	 * @return une portion de JSON représentant le tableau
441
	 */
439
	 */
442
	protected function array2js($array,$show_keys) {
440
	protected function array2js($array,$show_keys) {
443
		$tableauJs = '{}';
441
		$tableauJs = '{}';
444
		if (!empty($array)) {
442
		if (!empty($array)) {
445
			$total = count($array) - 1;
443
			$total = count($array) - 1;
446
			$i = 0;
444
			$i = 0;
447
			$dimensions = array();
445
			$dimensions = array();
448
			foreach ($array as $key => $value) {
446
			foreach ($array as $key => $value) {
449
				if (is_array($value)) {
447
				if (is_array($value)) {
450
					$dimensions[$i] = array2js($value,$show_keys);
448
					$dimensions[$i] = array2js($value,$show_keys);
451
					if ($show_keys) {
449
					if ($show_keys) {
452
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
450
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
453
					}
451
					}
454
				} else {
452
				} else {
455
					$dimensions[$i] = '"'.addslashes($value).'"';
453
					$dimensions[$i] = '"'.addslashes($value).'"';
456
					if ($show_keys) {
454
					if ($show_keys) {
457
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
455
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
458
					}
456
					}
459
				}
457
				}
460
				if ($i == 0) {
458
				if ($i == 0) {
461
					$dimensions[$i] = '{'.$dimensions[$i];
459
					$dimensions[$i] = '{'.$dimensions[$i];
462
				}
460
				}
463
				if ($i == $total) {
461
				if ($i == $total) {
464
					$dimensions[$i].= '}';
462
					$dimensions[$i].= '}';
465
				}
463
				}
466
				$i++;
464
				$i++;
467
			}
465
			}
468
			$tableauJs = implode(',', $dimensions);
466
			$tableauJs = implode(',', $dimensions);
469
		}
467
		}
470
		return $tableauJs;
468
		return $tableauJs;
471
	}
469
	}
472
}
470
}