Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2343 Rev 2360
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'] != '' && $_GET['referentiel'] != "autre") {
100
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '' && $_GET['referentiel'] != "autre") {
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
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
114
 
114
 
115
 
115
 
116
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
116
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
117
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
117
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
118
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
118
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
119
 
119
 
120
		// 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
121
		$projetsAutorises = array('defaut', 'ambrosia', 'florileges', 'sauvages');
121
		$projetsAutorises = array('defaut', 'ambrosia', 'arbres-tetards', 'florileges', 'sauvages');
122
		if (in_array($this->projet, $projetsAutorises) || !$this->projetASquelette()) {
122
		if (in_array($this->projet, $projetsAutorises) || !$this->projetASquelette()) {
123
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
123
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
124
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
124
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
125
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
125
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
126
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
126
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
127
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
127
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
128
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
128
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
129
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
129
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
130
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
130
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
131
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
131
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
132
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
132
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
133
			$widget['donnees']['espece_imposee'] = false;
133
			$widget['donnees']['espece_imposee'] = false;
134
			$widget['donnees']['nn_espece_defaut'] = '';
134
			$widget['donnees']['nn_espece_defaut'] = '';
135
			$widget['donnees']['nom_sci_espece_defaut'] = '';
135
			$widget['donnees']['nom_sci_espece_defaut'] = '';
136
			$widget['donnees']['infos_espece'] = '{}';
136
			$widget['donnees']['infos_espece'] = '{}';
137
 
137
 
138
			if ($this->especeEstImposee()) {
138
			if ($this->especeEstImposee()) {
139
				$nnEspeceImposee = $this->getNnEspeceImposee();
139
				$nnEspeceImposee = $this->getNnEspeceImposee();
140
				$nom = $this->executerChargementInfosTaxon($nnEspeceImposee);
140
				$nom = $this->executerChargementInfosTaxon($nnEspeceImposee);
141
				$widget['donnees']['espece_imposee'] = true;
141
				$widget['donnees']['espece_imposee'] = true;
142
				$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
142
				$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
143
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
143
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
144
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
144
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
145
			}
145
			}
146
		}
146
		}
147
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
147
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
148
			if ($this->projet == 'florileges' || $this->projet == 'sauvages') {
148
			if ($this->projet == 'florileges' || $this->projet == 'sauvages') {
149
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
149
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
150
			} else {
150
			} else {
151
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
151
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
152
			}
152
			}
153
			$widget['donnees']['milieux'] = $this->parserMilieux();
153
			$widget['donnees']['milieux'] = $this->parserMilieux();
154
		}
154
		}
155
		return  $widget;
155
		return  $widget;
156
	}
156
	}
157
 
157
 
158
	private function projetASquelette() {
158
	private function projetASquelette() {
159
		// fonction très simple qui ne teste que si le dossier du projet courant
159
		// fonction très simple qui ne teste que si le dossier du projet courant
160
		// existe, mais elle suffit pour le moment.
160
		// existe, mais elle suffit pour le moment.
161
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
161
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
162
	}
162
	}
163
 
163
 
164
	public function executerTaxons() {
164
	public function executerTaxons() {
165
		$widget['squelette'] = $this->projet.'_taxons';
165
		$widget['squelette'] = $this->projet.'_taxons';
166
		$widget['squelette_ext'] = '.tpl.js';
166
		$widget['squelette_ext'] = '.tpl.js';
167
		$widget['donnees'] = array();
167
		$widget['donnees'] = array();
168
		$nomsAAfficher = $this->recupererListeNomsSci();
168
		$nomsAAfficher = $this->recupererListeNomsSci();
169
		$taxons_tries = array();
169
		$taxons_tries = array();
170
		foreach ($nomsAAfficher as $taxon) {
170
		foreach ($nomsAAfficher as $taxon) {
171
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
171
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
172
		}
172
		}
173
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
173
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
174
		return $widget;
174
		return $widget;
175
	}
175
	}
176
 
176
 
177
	private function recupererListeNomsSci() {
177
	private function recupererListeNomsSci() {
178
		$taxons = $this->recupererListeTaxon();
178
		$taxons = $this->recupererListeTaxon();
179
		if (is_array($taxons)) {
179
		if (is_array($taxons)) {
180
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
180
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
181
		}
181
		}
182
		return $taxons;
182
		return $taxons;
183
	}
183
	}
184
 
184
 
185
	private function recupererListeNoms() {
185
	private function recupererListeNoms() {
186
		$taxons = $this->recupererListeTaxon();
186
		$taxons = $this->recupererListeTaxon();
187
		$nomsAAfficher = array();
187
		$nomsAAfficher = array();
188
		$nomsSpeciaux = array();
188
		$nomsSpeciaux = array();
189
		if (is_array($taxons)) {
189
		if (is_array($taxons)) {
190
			foreach ($taxons as $taxon) {
190
			foreach ($taxons as $taxon) {
191
				$nomSciTitle = $taxon['nom_ret'].
191
				$nomSciTitle = $taxon['nom_ret'].
192
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
192
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
193
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
193
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
194
				$nomFrTitle = $taxon['nom_sel'].
194
				$nomFrTitle = $taxon['nom_sel'].
195
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
195
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
196
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
196
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
197
 
197
 
198
				if ($taxon['groupe'] == 'special') {
198
				if ($taxon['groupe'] == 'special') {
199
					$nomsSpeciaux[] = array(
199
					$nomsSpeciaux[] = array(
200
						'num_nom' => $taxon['num_nom_sel'],
200
						'num_nom' => $taxon['num_nom_sel'],
201
						'nom_a_afficher' => $taxon['nom_fr'],
201
						'nom_a_afficher' => $taxon['nom_fr'],
202
						'nom_a_sauver' => $taxon['nom_sel'],
202
						'nom_a_sauver' => $taxon['nom_sel'],
203
						'nom_title' => $nomSciTitle,
203
						'nom_title' => $nomSciTitle,
204
						'nom_type' => 'nom-special');
204
						'nom_type' => 'nom-special');
205
				} else {
205
				} else {
206
					$nomsAAfficher[] = array(
206
					$nomsAAfficher[] = array(
207
						'num_nom' => $taxon['num_nom_sel'],
207
						'num_nom' => $taxon['num_nom_sel'],
208
						'nom_a_afficher' => $taxon['nom_sel'],
208
						'nom_a_afficher' => $taxon['nom_sel'],
209
						'nom_a_sauver' => $taxon['nom_sel'],
209
						'nom_a_sauver' => $taxon['nom_sel'],
210
						'nom_title' => $nomSciTitle,
210
						'nom_title' => $nomSciTitle,
211
						'nom_type' => 'nom-sci');
211
						'nom_type' => 'nom-sci');
212
					$nomsAAfficher[] = array(
212
					$nomsAAfficher[] = array(
213
						'num_nom' => $taxon['num_nom_sel'],
213
						'num_nom' => $taxon['num_nom_sel'],
214
						'nom_a_afficher' => $taxon['nom_fr'],
214
						'nom_a_afficher' => $taxon['nom_fr'],
215
						'nom_a_sauver' => $taxon['nom_fr'],
215
						'nom_a_sauver' => $taxon['nom_fr'],
216
						'nom_title' => $nomFrTitle,
216
						'nom_title' => $nomFrTitle,
217
						'nom_type' => 'nom-fr');
217
						'nom_type' => 'nom-fr');
218
				}
218
				}
219
			}
219
			}
220
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
220
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
221
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
221
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
222
		}
222
		}
223
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
223
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
224
	}
224
	}
225
 
225
 
226
	private function recupererListeTaxon() {
226
	private function recupererListeTaxon() {
227
		$taxons = null;
227
		$taxons = null;
228
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
228
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
229
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
229
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
230
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
230
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
231
		} else {
231
		} else {
232
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
232
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
233
		}
233
		}
234
		return $taxons;
234
		return $taxons;
235
	}
235
	}
236
 
236
 
237
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
237
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
238
		$header = null;
238
		$header = null;
239
		$data = array();
239
		$data = array();
240
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
240
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
241
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
241
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
242
				if (!$header) {
242
				if (!$header) {
243
					$header = $row;
243
					$header = $row;
244
				} else {
244
				} else {
245
					$data[] = array_combine($header, $row);
245
					$data[] = array_combine($header, $row);
246
				}
246
				}
247
			}
247
			}
248
			fclose($handle);
248
			fclose($handle);
249
		}
249
		}
250
		return $data;
250
		return $data;
251
	}
251
	}
252
 
252
 
253
	private function parserMilieux() {
253
	private function parserMilieux() {
254
		$infosMilieux = array();
254
		$infosMilieux = array();
255
		if (isset($this->configProjet['milieux'])) {
255
		if (isset($this->configProjet['milieux'])) {
256
			$milieux = explode('|', $this->configProjet['milieux']);
256
			$milieux = explode('|', $this->configProjet['milieux']);
257
			foreach ($milieux as $milieu) {
257
			foreach ($milieux as $milieu) {
258
				$milieu = trim($milieu);
258
				$milieu = trim($milieu);
259
				$details = explode(';', $milieu);
259
				$details = explode(';', $milieu);
260
				if (isset($details[1])) {
260
				if (isset($details[1])) {
261
					$infosMilieux[$details[0]] = $details[1];
261
					$infosMilieux[$details[0]] = $details[1];
262
				} else {
262
				} else {
263
					$infosMilieux[$details[0]] = '';
263
					$infosMilieux[$details[0]] = '';
264
				}
264
				}
265
			}
265
			}
266
			ksort($infosMilieux);
266
			ksort($infosMilieux);
267
		}
267
		}
268
		return $infosMilieux;
268
		return $infosMilieux;
269
	}
269
	}
270
 
270
 
271
	private function especeEstImposee() {
271
	private function especeEstImposee() {
272
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != ''
272
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != ''
273
			|| isset($this->configProjet['sp_imposee']));
273
			|| isset($this->configProjet['sp_imposee']));
274
	}
274
	}
275
 
275
 
276
	private function getNnEspeceImposee() {
276
	private function getNnEspeceImposee() {
277
		$nn = null;
277
		$nn = null;
278
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
278
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
279
			$nn = $_GET['num_nom'];
279
			$nn = $_GET['num_nom'];
280
		} else if (isset($this->configProjet['sp_imposee'])) {
280
		} else if (isset($this->configProjet['sp_imposee'])) {
281
			$nn = $this->configProjet['sp_imposee'];
281
			$nn = $this->configProjet['sp_imposee'];
282
		}
282
		}
283
		return $nn;
283
		return $nn;
284
	}
284
	}
285
 
285
 
286
	private function executerChargementInfosTaxon($num_nom) {
286
	private function executerChargementInfosTaxon($num_nom) {
287
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
287
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
288
		$infos = json_decode(file_get_contents($url_service_infos));
288
		$infos = json_decode(file_get_contents($url_service_infos));
289
		// trop de champs injectés dans les infos espèces peut
289
		// trop de champs injectés dans les infos espèces peut
290
		// faire planter javascript
290
		// faire planter javascript
291
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
291
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
292
		'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
292
		'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
293
		$resultat = array();
293
		$resultat = array();
294
		if (isset($infos) && !empty($infos)) {
294
		if (isset($infos) && !empty($infos)) {
295
			$infos = (array)$infos;
295
			$infos = (array)$infos;
296
			if(isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
296
			if(isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
297
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
297
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
298
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
298
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
299
			}
299
			}
300
		}
300
		}
301
		return $resultat;
301
		return $resultat;
302
	}
302
	}
303
 
303
 
304
	private function array2js($array,$show_keys) {
304
	private function array2js($array,$show_keys) {
305
		$tableauJs = '{}';
305
		$tableauJs = '{}';
306
		if (!empty($array)) {
306
		if (!empty($array)) {
307
			$total = count($array) - 1;
307
			$total = count($array) - 1;
308
			$i = 0;
308
			$i = 0;
309
			$dimensions = array();
309
			$dimensions = array();
310
			foreach ($array as $key => $value) {
310
			foreach ($array as $key => $value) {
311
				if (is_array($value)) {
311
				if (is_array($value)) {
312
					$dimensions[$i] = array2js($value,$show_keys);
312
					$dimensions[$i] = array2js($value,$show_keys);
313
					if ($show_keys) {
313
					if ($show_keys) {
314
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
314
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
315
					}
315
					}
316
				} else {
316
				} else {
317
					$dimensions[$i] = '"'.addslashes($value).'"';
317
					$dimensions[$i] = '"'.addslashes($value).'"';
318
					if ($show_keys) {
318
					if ($show_keys) {
319
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
319
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
320
					}
320
					}
321
				}
321
				}
322
				if ($i == 0) {
322
				if ($i == 0) {
323
					$dimensions[$i] = '{'.$dimensions[$i];
323
					$dimensions[$i] = '{'.$dimensions[$i];
324
				}
324
				}
325
				if ($i == $total) {
325
				if ($i == $total) {
326
					$dimensions[$i].= '}';
326
					$dimensions[$i].= '}';
327
				}
327
				}
328
				$i++;
328
				$i++;
329
			}
329
			}
330
			$tableauJs = implode(',', $dimensions);
330
			$tableauJs = implode(',', $dimensions);
331
		}
331
		}
332
		return $tableauJs;
332
		return $tableauJs;
333
	}
333
	}
334
}
-
 
335
?>
-
 
336
334
}
-
 
335
337
336