Subversion Repositories eFlore/Applications.cel

Rev

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

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