Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2406 Rev 2408
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 : Biodiversite34]
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
 * Indique quel projet nous voulons charger
14
 * Indique quel projet nous voulons charger
14
 *
15
 *
-
 
16
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @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>
16
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @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>
18
 * @version		$Id$
-
 
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
21
 * @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
20
 */
22
 */
21
class Saisie extends WidgetCommun {
23
class Saisie extends WidgetCommun {
22
 
24
 
23
	const DS = DIRECTORY_SEPARATOR;
25
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'defaut';
26
	const PROJET_DEFAUT = 'defaut';
25
	const WS_SAISIE = 'CelWidgetSaisie';
27
	const WS_SAISIE = 'CelWidgetSaisie';
26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
28
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
27
	const WS_OBS = 'CelObs';
29
	const WS_OBS = 'CelObs';
28
	const WS_NOM = 'noms';
30
	const WS_NOM = 'noms';
29
	private $NS_PROJET_VERSION = '1.01';
-
 
30
	const EFLORE_API_VERSION = '0.1';
31
	const EFLORE_API_VERSION = '0.1';
31
	private $NS_PROJET = 'bdtfx';
-
 
32
 
32
 
33
	private $projetsVersions = array();
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
 
37
 
37
	/**
38
	/**
38
	 * Méthode appelée par défaut pour charger ce widget.
39
	 * Méthode appelée par défaut pour charger ce widget.
39
	 */
40
	 */
40
	public function executer() {
41
	public function executer() {
41
		$retour = null;
42
		$retour = null;
42
		extract($this->parametres);
43
		extract($this->parametres);
43
 
44
 
44
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
45
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
45
		$this->chargerConfigProjet();
46
		$this->chargerConfigProjet();
46
		$this->chargerProjetsVersion();
-
 
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)) {
80
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
-
 
81
				if (isset($_GET['mission'])) {
-
 
82
					$mission = strtolower(trim($_GET['mission']));
-
 
83
					if (isset($this->configProjet[$mission])) {
-
 
84
						$this->configMission = $this->configProjet[$mission];
-
 
85
					}
-
 
86
			}
-
 
87
			} else {
81
				$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é.";
82
			}
89
			}
83
		} else {
90
		} else {
84
			$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.";
85
		}
92
		}
86
	}
93
	}
87
 
94
 
88
	private function chargerProjetsVersion() {
-
 
89
		if (isset($this->configProjet)) {
95
	private function projetASquelette() {
90
			foreach ($this->configProjet as $config => $valeur) {
96
		// fonction très simple qui ne teste que si le dossier du projet courant
91
				if(strstr($config,'.version')) {
97
		// existe, mais elle suffit pour le moment.
92
					$this->projetsVersions[str_replace('.version', '', $config)] = $valeur;
-
 
93
				}
-
 
94
			}
-
 
95
		}
98
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
96
	}
99
	}
97
 
100
 
98
	public function executerWidget() {
101
	public function executerWidget() {
99
		$referentiel_impose = false;
102
		$referentiel_impose = false;
100
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") {
103
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") {
101
			$this->NS_PROJET = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->NS_PROJET;
104
			$this->ns_referentiel = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->ns_referentiel;
102
			$this->NS_PROJET_VERSION = $this->projetsVersions[$this->NS_PROJET];
-
 
103
			$referentiel_impose = true;
105
			$referentiel_impose = true;
104
		}
106
		}
105
 
107
 
106
		$widget['squelette'] = $this->projet;
108
		$widget['squelette'] = $this->projet;
107
		$widget['donnees'] = array();
109
		$widget['donnees'] = array();
108
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
110
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
109
		$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);
110
		$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);
111
		$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);
112
		$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/');
113
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
115
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
114
 
116
 
115
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
117
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
116
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
118
		$widget['donnees']['titre'] = $this->getTitrePage();
117
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
-
 
118
 
119
 
119
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
120
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
120
		if (in_array($this->projet, $projetsAutorises)) {
121
		if (in_array($this->projet, $projetsAutorises)) {
121
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
122
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
122
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
123
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
123
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
124
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
124
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
125
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
125
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
126
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
126
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
-
 
127
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
127
			$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
128
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
-
 
129
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
128
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
130
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
-
 
131
			$widget['donnees']['espece_imposee'] = false;
129
			$widget['donnees']['espece_imposee'] = false;
132
			$widget['donnees']['nn_espece_defaut'] = '';
130
			$widget['donnees']['nn_espece_defaut'] = '';
133
			$widget['donnees']['nom_sci_espece_defaut'] = '';
131
			$widget['donnees']['nom_sci_espece_defaut'] = '';
134
			$widget['donnees']['infos_espece'] = '{}';
132
			$widget['donnees']['infos_espece'] = '{}';
135
 
133
 
136
			if ($this->especeEstImposee()) {
134
			if ($this->especeEstImposee()) {
137
				$nnEspeceImposee = $this->getNnEspeceImposee();
135
				$nnEspeceImposee = $this->getNnEspeceImposee();
138
				$nom = $this->executerChargementInfosTaxon($nnEspeceImposee);
136
				$nom = $this->executerChargementInfosTaxon($nnEspeceImposee);
139
				$widget['donnees']['espece_imposee'] = true;
137
				$widget['donnees']['espece_imposee'] = true;
140
				$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
138
				$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
141
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
139
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
142
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
140
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
143
			}
141
			}
144
		}
142
		}
145
 
143
 
146
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
144
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
147
		if (in_array($this->projet, $projetsAListeDeNoms)) {
145
		if (in_array($this->projet, $projetsAListeDeNoms)) {
148
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
146
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
149
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
147
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
150
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
148
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
151
			} else {
149
			} else {
152
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
150
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
153
			}
151
			}
154
		}
152
		}
155
 
153
 
156
		// 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
157
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
155
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
158
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
156
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
159
			$widget['donnees']['milieux'] = $this->parserMilieux();
157
			$widget['donnees']['milieux'] = $this->parserMilieux();
160
		}
158
		}
161
 
159
 
162
		return $widget;
160
		return $widget;
163
	}
161
	}
164
 
162
 
-
 
163
	private function getTitrePage() {
-
 
164
		$titre = 'defaut';
165
	private function projetASquelette() {
165
		if (isset($this->configProjet['titre_page'])) {
-
 
166
			$titre = $this->configProjet['titre_page'];
166
		// fonction très simple qui ne teste que si le dossier du projet courant
167
		}
167
		// existe, mais elle suffit pour le moment.
168
		if (isset($this->configMission['titre_page'])) {
-
 
169
			$titre = $this->configMission['titre_page'];
-
 
170
		}
-
 
171
		if (isset($_GET['titre'])) {
-
 
172
			$titre = $_GET['titre'];
-
 
173
		}
-
 
174
		if ($titre === 0) {
-
 
175
			$titre = '';
-
 
176
		}
168
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
177
		return $titre;
169
	}
178
	}
170
 
179
 
171
	public function executerTaxons() {
180
	public function executerTaxons() {
172
		$widget['squelette'] = $this->projet.'_taxons';
181
		$widget['squelette'] = $this->projet.'_taxons';
173
		$widget['squelette_ext'] = '.tpl.js';
182
		$widget['squelette_ext'] = '.tpl.js';
174
		$widget['donnees'] = array();
183
		$widget['donnees'] = array();
175
		$nomsAAfficher = $this->recupererListeNomsSci();
184
		$nomsAAfficher = $this->recupererListeNomsSci();
176
		$taxons_tries = array();
185
		$taxons_tries = array();
177
		foreach ($nomsAAfficher as $taxon) {
186
		foreach ($nomsAAfficher as $taxon) {
178
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
187
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
179
		}
188
		}
180
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
189
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
181
		return $widget;
190
		return $widget;
182
	}
191
	}
183
 
192
 
184
	private function recupererListeNomsSci() {
193
	private function recupererListeNomsSci() {
185
		$taxons = $this->recupererListeTaxon();
194
		$taxons = $this->recupererListeTaxon();
186
		if (is_array($taxons)) {
195
		if (is_array($taxons)) {
187
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
196
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
188
		}
197
		}
189
		return $taxons;
198
		return $taxons;
190
	}
199
	}
191
 
200
 
192
	private function recupererListeNoms() {
201
	private function recupererListeNoms() {
193
		$taxons = $this->recupererListeTaxon();
202
		$taxons = $this->recupererListeTaxon();
194
		$nomsAAfficher = array();
203
		$nomsAAfficher = array();
195
		$nomsSpeciaux = array();
204
		$nomsSpeciaux = array();
196
		if (is_array($taxons)) {
205
		if (is_array($taxons)) {
197
			foreach ($taxons as $taxon) {
206
			foreach ($taxons as $taxon) {
198
				$nomSciTitle = $taxon['nom_ret'].
207
				$nomSciTitle = $taxon['nom_ret'].
199
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
208
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
200
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
209
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
201
				$nomFrTitle = $taxon['nom_sel'].
210
				$nomFrTitle = $taxon['nom_sel'].
202
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
211
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
203
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
212
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
204
 
213
 
205
				if ($taxon['groupe'] == 'special') {
214
				if ($taxon['groupe'] == 'special') {
206
					$nomsSpeciaux[] = array(
215
					$nomsSpeciaux[] = array(
207
						'num_nom' => $taxon['num_nom_sel'],
216
						'num_nom' => $taxon['num_nom_sel'],
208
						'nom_a_afficher' => $taxon['nom_fr'],
217
						'nom_a_afficher' => $taxon['nom_fr'],
209
						'nom_a_sauver' => $taxon['nom_sel'],
218
						'nom_a_sauver' => $taxon['nom_sel'],
210
						'nom_title' => $nomSciTitle,
219
						'nom_title' => $nomSciTitle,
211
						'nom_type' => 'nom-special');
220
						'nom_type' => 'nom-special');
212
				} else {
221
				} else {
213
					$nomsAAfficher[] = array(
222
					$nomsAAfficher[] = array(
214
						'num_nom' => $taxon['num_nom_sel'],
223
						'num_nom' => $taxon['num_nom_sel'],
215
						'nom_a_afficher' => $taxon['nom_sel'],
224
						'nom_a_afficher' => $taxon['nom_sel'],
216
						'nom_a_sauver' => $taxon['nom_sel'],
225
						'nom_a_sauver' => $taxon['nom_sel'],
217
						'nom_title' => $nomSciTitle,
226
						'nom_title' => $nomSciTitle,
218
						'nom_type' => 'nom-sci');
227
						'nom_type' => 'nom-sci');
219
					$nomsAAfficher[] = array(
228
					$nomsAAfficher[] = array(
220
						'num_nom' => $taxon['num_nom_sel'],
229
						'num_nom' => $taxon['num_nom_sel'],
221
						'nom_a_afficher' => $taxon['nom_fr'],
230
						'nom_a_afficher' => $taxon['nom_fr'],
222
						'nom_a_sauver' => $taxon['nom_fr'],
231
						'nom_a_sauver' => $taxon['nom_fr'],
223
						'nom_title' => $nomFrTitle,
232
						'nom_title' => $nomFrTitle,
224
						'nom_type' => 'nom-fr');
233
						'nom_type' => 'nom-fr');
225
				}
234
				}
226
			}
235
			}
227
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
236
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
228
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
237
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
229
		}
238
		}
230
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
239
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
231
	}
240
	}
232
 
241
 
233
	private function recupererListeTaxon() {
242
	private function recupererListeTaxon() {
234
		$taxons = null;
243
		$taxons = null;
235
		$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';
236
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
245
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
237
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
246
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
238
		} else {
247
		} else {
239
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
248
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
240
		}
249
		}
241
		return $taxons;
250
		return $taxons;
242
	}
251
	}
243
 
252
 
244
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
253
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
245
		$header = null;
254
		$header = null;
246
		$data = array();
255
		$data = array();
247
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
256
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
248
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
257
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
249
				if (!$header) {
258
				if (!$header) {
250
					$header = $row;
259
					$header = $row;
251
				} else {
260
				} else {
252
					$data[] = array_combine($header, $row);
261
					$data[] = array_combine($header, $row);
253
				}
262
				}
254
			}
263
			}
255
			fclose($handle);
264
			fclose($handle);
256
		}
265
		}
257
		return $data;
266
		return $data;
258
	}
267
	}
259
 
268
 
260
	private function parserMilieux() {
269
	private function parserMilieux() {
261
		$infosMilieux = array();
270
		$infosMilieux = array();
262
		if (isset($this->configProjet['milieux'])) {
271
		if (isset($this->configProjet['milieux'])) {
263
			$milieux = explode('|', $this->configProjet['milieux']);
272
			$milieux = explode('|', $this->configProjet['milieux']);
264
			foreach ($milieux as $milieu) {
273
			foreach ($milieux as $milieu) {
265
				$milieu = trim($milieu);
274
				$milieu = trim($milieu);
266
				$details = explode(';', $milieu);
275
				$details = explode(';', $milieu);
267
				if (isset($details[1])) {
276
				if (isset($details[1])) {
268
					$infosMilieux[$details[0]] = $details[1];
277
					$infosMilieux[$details[0]] = $details[1];
269
				} else {
278
				} else {
270
					$infosMilieux[$details[0]] = '';
279
					$infosMilieux[$details[0]] = '';
271
				}
280
				}
272
			}
281
			}
273
			ksort($infosMilieux);
282
			ksort($infosMilieux);
274
		}
283
		}
275
		return $infosMilieux;
284
		return $infosMilieux;
276
	}
285
	}
277
 
286
 
278
	private function especeEstImposee() {
287
	private function especeEstImposee() {
279
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != ''
288
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != ''
280
			|| isset($this->configProjet['sp_imposee']));
289
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
281
	}
290
	}
282
 
291
 
283
	private function getNnEspeceImposee() {
292
	private function getNnEspeceImposee() {
284
		$nn = null;
293
		$nn = null;
285
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
294
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
286
			$nn = $_GET['num_nom'];
295
			$nn = $_GET['num_nom'];
287
		} else if (isset($this->configProjet['sp_imposee'])) {
296
		} else if (isset($this->configProjet['sp_imposee'])) {
288
			$nn = $this->configProjet['sp_imposee'];
297
			$nn = $this->configProjet['sp_imposee'];
-
 
298
		} else if (isset($this->configMission['sp_imposee'])) {
-
 
299
			$nn = $this->configMission['sp_imposee'];
289
		}
300
		}
290
		return $nn;
301
		return $nn;
291
	}
302
	}
292
 
303
 
293
	private function executerChargementInfosTaxon($num_nom) {
304
	private function executerChargementInfosTaxon($num_nom) {
294
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
305
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
295
		$infos = json_decode(file_get_contents($url_service_infos));
306
		$infos = json_decode(file_get_contents($url_service_infos));
296
		// trop de champs injectés dans les infos espèces peut
307
		// trop de champs injectés dans les infos espèces peut
297
		// faire planter javascript
308
		// faire planter javascript
298
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
309
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
299
			'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
310
			'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
300
		$resultat = array();
311
		$resultat = array();
301
		if (isset($infos) && !empty($infos)) {
312
		if (isset($infos) && !empty($infos)) {
302
			$infos = (array)$infos;
313
			$infos = (array)$infos;
303
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
314
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
304
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
315
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
305
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
316
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
306
			}
317
			}
307
		}
318
		}
308
		return $resultat;
319
		return $resultat;
309
	}
320
	}
310
 
321
 
311
	private function array2js($array,$show_keys) {
322
	private function array2js($array,$show_keys) {
312
		$tableauJs = '{}';
323
		$tableauJs = '{}';
313
		if (!empty($array)) {
324
		if (!empty($array)) {
314
			$total = count($array) - 1;
325
			$total = count($array) - 1;
315
			$i = 0;
326
			$i = 0;
316
			$dimensions = array();
327
			$dimensions = array();
317
			foreach ($array as $key => $value) {
328
			foreach ($array as $key => $value) {
318
				if (is_array($value)) {
329
				if (is_array($value)) {
319
					$dimensions[$i] = array2js($value,$show_keys);
330
					$dimensions[$i] = array2js($value,$show_keys);
320
					if ($show_keys) {
331
					if ($show_keys) {
321
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
332
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
322
					}
333
					}
323
				} else {
334
				} else {
324
					$dimensions[$i] = '"'.addslashes($value).'"';
335
					$dimensions[$i] = '"'.addslashes($value).'"';
325
					if ($show_keys) {
336
					if ($show_keys) {
326
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
337
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
327
					}
338
					}
328
				}
339
				}
329
				if ($i == 0) {
340
				if ($i == 0) {
330
					$dimensions[$i] = '{'.$dimensions[$i];
341
					$dimensions[$i] = '{'.$dimensions[$i];
331
				}
342
				}
332
				if ($i == $total) {
343
				if ($i == $total) {
333
					$dimensions[$i].= '}';
344
					$dimensions[$i].= '}';
334
				}
345
				}
335
				$i++;
346
				$i++;
336
			}
347
			}
337
			$tableauJs = implode(',', $dimensions);
348
			$tableauJs = implode(',', $dimensions);
338
		}
349
		}
339
		return $tableauJs;
350
		return $tableauJs;
340
	}
351
	}
341
}
352
}