Subversion Repositories eFlore/Applications.cel

Rev

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

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