Subversion Repositories eFlore/Applications.cel

Rev

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

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