Subversion Repositories eFlore/Applications.cel

Rev

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

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