Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2744 Rev 2786
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
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
-
 
39
	protected $langue = null;
38
 
40
 
39
	/**
41
	/**
40
	 * Amorçage du widget
42
	 * Amorçage du widget
41
	 */
43
	 */
42
	public function executer() {
44
	public function executer() {
43
		// paramètres par défaut
45
		// paramètres par défaut
44
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
46
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
45
		$this->projet = self::PROJET_DEFAUT;
47
		$this->projet = self::PROJET_DEFAUT;
46
 
48
 
47
		// définition du projet / mission
49
		// définition du projet / mission
48
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
50
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
49
			$projets = explode(',', $this->parametres['projet']);
51
			$projets = explode(',', $this->parametres['projet']);
50
			$this->projet = strtolower($projets[0]);
52
			$this->projet = strtolower($projets[0]);
51
		}
53
		}
52
		$this->chargerConfigProjet();
54
		$this->chargerConfigProjet();
53
 
55
 
54
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
56
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
55
		$retour = null;
57
		$retour = null;
56
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
58
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
57
		$methode = $this->traiterNomMethodeExecuter($service);
59
		$methode = $this->traiterNomMethodeExecuter($service);
58
		if (method_exists($this, $methode)) {
60
		if (method_exists($this, $methode)) {
59
			$retour = $this->$methode();
61
			$retour = $this->$methode();
60
		} else {
62
		} else {
61
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
63
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
62
		}
64
		}
-
 
65
 
-
 
66
		// définition de la langue, en mode souple
-
 
67
		if (isset($this->parametres['lang'])) {
-
 
68
			$this->langue = $this->parametres['lang'];
-
 
69
		}
63
 
70
 
64
		// injection des données dans le squelette
71
		// injection des données dans le squelette
65
		$contenu = null;
72
		$contenu = null;
66
		$mime = null;
73
		$mime = null;
67
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
74
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
68
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
75
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
-
 
76
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
-
 
77
			$suffixeLangue = "";
-
 
78
			if ($this->langue != null && $this->langue != "fr") {
-
 
79
				$suffixeLangue = "_" . $this->langue;
-
 
80
			}
-
 
81
			// Template par défaut ou spécifique
69
			if ($this->projetASquelette()) {
82
			if ($this->projetASquelette()) {
70
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
83
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
71
			} else {
84
			} else {
72
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
85
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
73
			}
86
			}
74
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
87
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
75
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
88
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
76
		} else {
89
		} else {
77
			if (count($this->messages) == 0) {
90
			if (count($this->messages) == 0) {
78
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
91
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
79
			}
92
			}
80
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
93
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
81
		}
94
		}
82
 
95
 
83
		// envoi de la page
96
		// envoi de la page
84
		$this->envoyer($contenu, $mime);
97
		$this->envoyer($contenu, $mime);
85
	}
98
	}
86
 
99
 
87
	/**
100
	/**
88
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
101
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
89
	 * Si une mission est définie, charge séparément la section de la configuration concernant
102
	 * Si une mission est définie, charge séparément la section de la configuration concernant
90
	 * cette mission : [nommission]
103
	 * cette mission : [nommission]
91
	 */
104
	 */
92
	protected function chargerConfigProjet() {
105
	protected function chargerConfigProjet() {
93
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
106
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
94
		if (file_exists($fichier_config)) {
107
		if (file_exists($fichier_config)) {
95
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
108
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
96
				if (isset($_GET['mission'])) {
109
				if (isset($_GET['mission'])) {
97
					$mission = strtolower(trim($_GET['mission']));
110
					$mission = strtolower(trim($_GET['mission']));
98
					if (isset($this->configProjet[$mission])) {
111
					if (isset($this->configProjet[$mission])) {
99
						$this->configMission = $this->configProjet[$mission];
112
						$this->configMission = $this->configProjet[$mission];
100
					}
113
					}
101
				}
114
				}
102
			} else {
115
			} else {
103
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
116
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
104
			}
117
			}
105
		} else {
118
		} else {
106
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
119
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
107
		}
120
		}
108
	}
121
	}
109
 
122
 
110
	/**
123
	/**
111
	 * Retourne true si le dossier du projet courant existe, false sinon
124
	 * Retourne true si le dossier du projet courant existe, false sinon
112
	 * @return boolean
125
	 * @return boolean
113
	 */
126
	 */
114
	protected function projetASquelette() {
127
	protected function projetASquelette() {
115
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
128
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
116
	}
129
	}
117
 
130
 
118
	/**
131
	/**
119
	 * Exécution du widget complet 
132
	 * Exécution du widget complet 
120
	 * @return Ambigous <string, unknown, multitype:string unknown >
133
	 * @return Ambigous <string, unknown, multitype:string unknown >
121
	 */
134
	 */
122
	public function executerWidget() {
135
	public function executerWidget() {
123
		$referentiel_impose = false;
136
		$referentiel_impose = false;
124
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") {
137
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") {
125
			$this->ns_referentiel = $_GET['referentiel'];
138
			$this->ns_referentiel = $_GET['referentiel'];
126
			$referentiel_impose = true;
139
			$referentiel_impose = true;
127
		}
140
		}
128
 
141
 
129
		$widget['squelette'] = $this->projet;
142
		$widget['squelette'] = $this->projet;
130
		$widget['donnees'] = array();
143
		$widget['donnees'] = array();
131
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
144
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
132
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
145
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
133
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
146
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
134
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
147
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
135
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
148
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
136
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
149
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
137
 
150
 
138
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
151
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
139
		$widget['donnees']['titre'] = $this->getTitrePage();
152
		$widget['donnees']['titre'] = $this->getTitrePage();
140
 
153
 
141
		$widget['donnees']['referentiel_impose'] = $referentiel_impose;
154
		$widget['donnees']['referentiel_impose'] = $referentiel_impose;
142
		$widget['donnees']['espece_imposee'] = false;
155
		$widget['donnees']['espece_imposee'] = false;
143
		$widget['donnees']['nn_espece_defaut'] = '';
156
		$widget['donnees']['nn_espece_defaut'] = '';
144
		$widget['donnees']['nom_sci_espece_defaut'] = '';
157
		$widget['donnees']['nom_sci_espece_defaut'] = '';
145
		$widget['donnees']['infos_espece'] = '{}';
158
		$widget['donnees']['infos_espece'] = '{}';
146
		
159
		
147
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
160
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
148
 
161
 
149
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
162
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
150
		$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);
151
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
164
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
152
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
165
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
153
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
166
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
154
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
167
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
155
		
168
		
156
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
169
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
157
		
170
		
158
		if ($this->especeEstImposee()) {
171
		if ($this->especeEstImposee()) {
159
			$nnEspeceImposee = $this->getNnEspeceImposee();
172
			$nnEspeceImposee = $this->getNnEspeceImposee();
160
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
173
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
161
			$widget['donnees']['espece_imposee'] = true;
174
			$widget['donnees']['espece_imposee'] = true;
162
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
175
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
163
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
176
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
164
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
177
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
165
		}
178
		}
166
 
179
 
167
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
180
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
168
		if (in_array($this->projet, $projetsAListeDeNoms)) {
181
		if (in_array($this->projet, $projetsAListeDeNoms)) {
169
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
182
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
170
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
183
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
171
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
184
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
172
			} else {
185
			} else {
173
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
186
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
174
			}
187
			}
175
		}
188
		}
176
 
189
 
177
		// Chargement de la liste des milieux issues du fichier .ini du projet
190
		// Chargement de la liste des milieux issues du fichier .ini du projet
178
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
191
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
179
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
192
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
180
			$widget['donnees']['milieux'] = $this->parserMilieux();
193
			$widget['donnees']['milieux'] = $this->parserMilieux();
181
		}
194
		}
182
 
195
 
183
		return $widget;
196
		return $widget;
184
	}
197
	}
185
 
198
 
186
	protected function getTitrePage() {
199
	protected function getTitrePage() {
187
		$titre = 'defaut';
200
		$titre = 'defaut';
188
		if (isset($this->configProjet['titre_page'])) {
201
		if (isset($this->configProjet['titre_page'])) {
189
			$titre = $this->configProjet['titre_page'];
202
			$titre = $this->configProjet['titre_page'];
190
		}
203
		}
191
		if (isset($this->configMission['titre_page'])) {
204
		if (isset($this->configMission['titre_page'])) {
192
			$titre = $this->configMission['titre_page'];
205
			$titre = $this->configMission['titre_page'];
193
		}
206
		}
194
		if (isset($_GET['titre'])) {
207
		if (isset($_GET['titre'])) {
195
			$titre = $_GET['titre'];
208
			$titre = $_GET['titre'];
196
		}
209
		}
197
		if ($titre === 0) {
210
		if ($titre === 0) {
198
			$titre = '';
211
			$titre = '';
199
		}
212
		}
200
		return $titre;
213
		return $titre;
201
	}
214
	}
202
 
215
 
203
	/**
216
	/**
204
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
217
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
205
	 * pour certains projets
218
	 * pour certains projets
206
	 * @return string
219
	 * @return string
207
	 */
220
	 */
208
	public function executerTaxons() {
221
	public function executerTaxons() {
209
		$widget['squelette'] = $this->projet.'_taxons';
222
		$widget['squelette'] = $this->projet.'_taxons';
210
		$widget['squelette_ext'] = '.tpl.js';
223
		$widget['squelette_ext'] = '.tpl.js';
211
		$widget['donnees'] = array();
224
		$widget['donnees'] = array();
212
		$nomsAAfficher = $this->recupererListeNomsSci();
225
		$nomsAAfficher = $this->recupererListeNomsSci();
213
		$taxons_tries = array();
226
		$taxons_tries = array();
214
		foreach ($nomsAAfficher as $taxon) {
227
		foreach ($nomsAAfficher as $taxon) {
215
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
228
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
216
		}
229
		}
217
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
230
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
218
		return $widget;
231
		return $widget;
219
	}
232
	}
220
 
233
 
221
	/**
234
	/**
222
	 * Trie par nom français les taxons lus dans le fichier tsv
235
	 * Trie par nom français les taxons lus dans le fichier tsv
223
	 */
236
	 */
224
	protected function recupererListeNomsSci() {
237
	protected function recupererListeNomsSci() {
225
		$taxons = $this->recupererListeTaxon();
238
		$taxons = $this->recupererListeTaxon();
226
		if (is_array($taxons)) {
239
		if (is_array($taxons)) {
227
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
240
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
228
		}
241
		}
229
		return $taxons;
242
		return $taxons;
230
	}
243
	}
231
 
244
 
232
	/**
245
	/**
233
	 * @TODO documenter
246
	 * @TODO documenter
234
	 * @return array
247
	 * @return array
235
	 */
248
	 */
236
	protected function recupererListeNoms() {
249
	protected function recupererListeNoms() {
237
		$taxons = $this->recupererListeTaxon();
250
		$taxons = $this->recupererListeTaxon();
238
		$nomsAAfficher = array();
251
		$nomsAAfficher = array();
239
		$nomsSpeciaux = array();
252
		$nomsSpeciaux = array();
240
		if (is_array($taxons)) {
253
		if (is_array($taxons)) {
241
			foreach ($taxons as $taxon) {
254
			foreach ($taxons as $taxon) {
242
				$nomSciTitle = $taxon['nom_ret'].
255
				$nomSciTitle = $taxon['nom_ret'].
243
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
256
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
244
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
257
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
245
				$nomFrTitle = $taxon['nom_sel'].
258
				$nomFrTitle = $taxon['nom_sel'].
246
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
259
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
247
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
260
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
248
 
261
 
249
				if ($taxon['groupe'] == 'special') {
262
				if ($taxon['groupe'] == 'special') {
250
					$nomsSpeciaux[] = array(
263
					$nomsSpeciaux[] = array(
251
						'num_nom' => $taxon['num_nom_sel'],
264
						'num_nom' => $taxon['num_nom_sel'],
252
						'nom_a_afficher' => $taxon['nom_fr'],
265
						'nom_a_afficher' => $taxon['nom_fr'],
253
						'nom_a_sauver' => $taxon['nom_sel'],
266
						'nom_a_sauver' => $taxon['nom_sel'],
254
						'nom_title' => $nomSciTitle,
267
						'nom_title' => $nomSciTitle,
255
						'nom_type' => 'nom-special');
268
						'nom_type' => 'nom-special');
256
				} else {
269
				} else {
257
					$nomsAAfficher[] = array(
270
					$nomsAAfficher[] = array(
258
						'num_nom' => $taxon['num_nom_sel'],
271
						'num_nom' => $taxon['num_nom_sel'],
259
						'nom_a_afficher' => $taxon['nom_sel'],
272
						'nom_a_afficher' => $taxon['nom_sel'],
260
						'nom_a_sauver' => $taxon['nom_sel'],
273
						'nom_a_sauver' => $taxon['nom_sel'],
261
						'nom_title' => $nomSciTitle,
274
						'nom_title' => $nomSciTitle,
262
						'nom_type' => 'nom-sci');
275
						'nom_type' => 'nom-sci');
263
					$nomsAAfficher[] = array(
276
					$nomsAAfficher[] = array(
264
						'num_nom' => $taxon['num_nom_sel'],
277
						'num_nom' => $taxon['num_nom_sel'],
265
						'nom_a_afficher' => $taxon['nom_fr'],
278
						'nom_a_afficher' => $taxon['nom_fr'],
266
						'nom_a_sauver' => $taxon['nom_fr'],
279
						'nom_a_sauver' => $taxon['nom_fr'],
267
						'nom_title' => $nomFrTitle,
280
						'nom_title' => $nomFrTitle,
268
						'nom_type' => 'nom-fr');
281
						'nom_type' => 'nom-fr');
269
				}
282
				}
270
			}
283
			}
271
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
284
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
272
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
285
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
273
		}
286
		}
274
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
287
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
275
	}
288
	}
276
 
289
 
277
	/**
290
	/**
278
	 * Lit une liste de taxons depuis un fichier tsv fourni
291
	 * Lit une liste de taxons depuis un fichier tsv fourni
279
	 */
292
	 */
280
	protected function recupererListeTaxon() {
293
	protected function recupererListeTaxon() {
281
		$taxons = array();
294
		$taxons = array();
282
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
295
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
283
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
296
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
284
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
297
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
285
		} else {
298
		} else {
286
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
299
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
287
		}
300
		}
288
		return $taxons;
301
		return $taxons;
289
	}
302
	}
290
 
303
 
291
	/**
304
	/**
292
	 * Découpe un fihcier tsv
305
	 * Découpe un fihcier tsv
293
	 */
306
	 */
294
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
307
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
295
		$header = null;
308
		$header = null;
296
		$data = array();
309
		$data = array();
297
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
310
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
298
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
311
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
299
				if (!$header) {
312
				if (!$header) {
300
					$header = $row;
313
					$header = $row;
301
				} else {
314
				} else {
302
					$data[] = array_combine($header, $row);
315
					$data[] = array_combine($header, $row);
303
				}
316
				}
304
			}
317
			}
305
			fclose($handle);
318
			fclose($handle);
306
		}
319
		}
307
		return $data;
320
		return $data;
308
	}
321
	}
309
 
322
 
310
	/**
323
	/**
311
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
324
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
312
	 * du projet, si elle existe
325
	 * du projet, si elle existe
313
	 * @return array
326
	 * @return array
314
	 */
327
	 */
315
	protected function parserMilieux() {
328
	protected function parserMilieux() {
316
		$infosMilieux = array();
329
		$infosMilieux = array();
317
		if (isset($this->configProjet['milieux'])) {
330
		if (isset($this->configProjet['milieux'])) {
318
			$milieux = explode('|', $this->configProjet['milieux']);
331
			$milieux = explode('|', $this->configProjet['milieux']);
319
			foreach ($milieux as $milieu) {
332
			foreach ($milieux as $milieu) {
320
				$milieu = trim($milieu);
333
				$milieu = trim($milieu);
321
				$details = explode(';', $milieu);
334
				$details = explode(';', $milieu);
322
				if (isset($details[1])) {
335
				if (isset($details[1])) {
323
					$infosMilieux[$details[0]] = $details[1];
336
					$infosMilieux[$details[0]] = $details[1];
324
				} else {
337
				} else {
325
					$infosMilieux[$details[0]] = '';
338
					$infosMilieux[$details[0]] = '';
326
				}
339
				}
327
			}
340
			}
328
			ksort($infosMilieux);
341
			ksort($infosMilieux);
329
		}
342
		}
330
		return $infosMilieux;
343
		return $infosMilieux;
331
	}
344
	}
332
 
345
 
333
	/**
346
	/**
334
	 * Retourne true si le widget est restreint à une espèce, false sinon
347
	 * Retourne true si le widget est restreint à une espèce, false sinon
335
	 * @return boolean
348
	 * @return boolean
336
	 */
349
	 */
337
	protected function especeEstImposee() {
350
	protected function especeEstImposee() {
338
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
351
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
339
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
352
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
340
	}
353
	}
341
 
354
 
342
	/**
355
	/**
343
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
356
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
344
	 * le cas, null sinon
357
	 * le cas, null sinon
345
	 * @return string
358
	 * @return string
346
	 */
359
	 */
347
	protected function getNnEspeceImposee() {
360
	protected function getNnEspeceImposee() {
348
		$nn = null;
361
		$nn = null;
349
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
362
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
350
			$nn = $_GET['num_nom'];
363
			$nn = $_GET['num_nom'];
351
		} else if (isset($this->configProjet['sp_imposee'])) {
364
		} else if (isset($this->configProjet['sp_imposee'])) {
352
			$nn = $this->configProjet['sp_imposee'];
365
			$nn = $this->configProjet['sp_imposee'];
353
		} else if (isset($this->configMission['sp_imposee'])) {
366
		} else if (isset($this->configMission['sp_imposee'])) {
354
			$nn = $this->configMission['sp_imposee'];
367
			$nn = $this->configMission['sp_imposee'];
355
		}
368
		}
356
		return $nn;
369
		return $nn;
357
	}
370
	}
358
 
371
 
359
	/**
372
	/**
360
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
373
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
361
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
374
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
362
	 * et non le taxon?)
375
	 * et non le taxon?)
363
	 * @param string|int $num_nom
376
	 * @param string|int $num_nom
364
	 * @return array
377
	 * @return array
365
	 */
378
	 */
366
	protected function chargerInfosTaxon($num_nom) {
379
	protected function chargerInfosTaxon($num_nom) {
367
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
380
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
368
		$infos = json_decode(file_get_contents($url_service_infos));
381
		$infos = json_decode(file_get_contents($url_service_infos));
369
		// trop de champs injectés dans les infos espèces peuvent
382
		// trop de champs injectés dans les infos espèces peuvent
370
		// faire planter javascript
383
		// faire planter javascript
371
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
384
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
372
			'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
385
			'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
373
		$resultat = array();
386
		$resultat = array();
374
		if (isset($infos) && !empty($infos)) {
387
		if (isset($infos) && !empty($infos)) {
375
			$infos = (array)$infos;
388
			$infos = (array)$infos;
376
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
389
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
377
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
390
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
378
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
391
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
379
			}
392
			}
380
		}
393
		}
381
		return $resultat;
394
		return $resultat;
382
	}
395
	}
383
 
396
 
384
	/**
397
	/**
385
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
398
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
386
	 * @param array $array
399
	 * @param array $array
387
	 * @param boolean $show_keys
400
	 * @param boolean $show_keys
388
	 * @return une portion de JSON représentant le tableau
401
	 * @return une portion de JSON représentant le tableau
389
	 */
402
	 */
390
	protected function array2js($array,$show_keys) {
403
	protected function array2js($array,$show_keys) {
391
		$tableauJs = '{}';
404
		$tableauJs = '{}';
392
		if (!empty($array)) {
405
		if (!empty($array)) {
393
			$total = count($array) - 1;
406
			$total = count($array) - 1;
394
			$i = 0;
407
			$i = 0;
395
			$dimensions = array();
408
			$dimensions = array();
396
			foreach ($array as $key => $value) {
409
			foreach ($array as $key => $value) {
397
				if (is_array($value)) {
410
				if (is_array($value)) {
398
					$dimensions[$i] = array2js($value,$show_keys);
411
					$dimensions[$i] = array2js($value,$show_keys);
399
					if ($show_keys) {
412
					if ($show_keys) {
400
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
413
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
401
					}
414
					}
402
				} else {
415
				} else {
403
					$dimensions[$i] = '"'.addslashes($value).'"';
416
					$dimensions[$i] = '"'.addslashes($value).'"';
404
					if ($show_keys) {
417
					if ($show_keys) {
405
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
418
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
406
					}
419
					}
407
				}
420
				}
408
				if ($i == 0) {
421
				if ($i == 0) {
409
					$dimensions[$i] = '{'.$dimensions[$i];
422
					$dimensions[$i] = '{'.$dimensions[$i];
410
				}
423
				}
411
				if ($i == $total) {
424
				if ($i == $total) {
412
					$dimensions[$i].= '}';
425
					$dimensions[$i].= '}';
413
				}
426
				}
414
				$i++;
427
				$i++;
415
			}
428
			}
416
			$tableauJs = implode(',', $dimensions);
429
			$tableauJs = implode(',', $dimensions);
417
		}
430
		}
418
		return $tableauJs;
431
		return $tableauJs;
419
	}
432
	}
420
}
433
}