Subversion Repositories eFlore/Applications.cel

Rev

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

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