Subversion Repositories eFlore/Applications.cel

Rev

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

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