Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3037 Rev 3042
1
<?php
1
<?php
2
/**
2
/**
3
 * Widget fournissant des interfaces de saisie simplifiée pour différent projets
3
 * Widget fournissant des interfaces de saisie simplifiée pour différent projets
4
 *
4
 *
5
 * Cas d'utilisation et documentation :
5
 * Cas d'utilisation et documentation :
6
 * @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie
6
 * @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie
7
 *
7
 *
8
 * Paramètres :
8
 * Paramètres :
9
 * - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé
9
 * - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé
10
 * 		portant ce nom existe, il sera chargé
10
 * 		portant ce nom existe, il sera chargé
11
 * - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé
11
 * - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé
12
 * 		est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore")
12
 * 		est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore")
13
 *
13
 *
14
 * @author Mathias CHOUET <mathias@tela-botanica.org>
14
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
16
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
17
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @copyright 1999-2015 Tela Botanica <accueil@tela-botanica.org>
19
 * @copyright 1999-2015 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
	const EFLORE_API_VERSION = '0.1';
29
	const EFLORE_API_VERSION = '0.1';
30
	const REFERENTIEL_DEFAUT = 'bdtfxr';
30
	const REFERENTIEL_DEFAUT = 'bdtfxr';
31
 
31
 
32
	/** référentiel utilisé pour la complétion des noms scientifiques */
32
	/** référentiel utilisé pour la complétion des noms scientifiques */
33
	protected $ns_referentiel;
33
	protected $ns_referentiel;
34
	/** mot-clé associé aux saisies, et template personnalisé si appliquable */
34
	/** mot-clé associé aux saisies, et template personnalisé si appliquable */
35
	protected $projet = null;
35
	protected $projet = null;
36
	protected $configProjet = null;
36
	protected $configProjet = null;
37
	protected $configMission = null;
37
	protected $configMission = null;
38
	protected $mission = null;
38
	protected $mission = null;
39
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
39
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
40
	protected $langue = null;
40
	protected $langue = null;
41
 
41
 
42
	/**
42
	/**
43
	 * Amorçage du widget
43
	 * Amorçage du widget
44
	 */
44
	 */
45
	public function executer() {
45
	public function executer() {
46
		// paramètres par défaut
46
		// paramètres par défaut
47
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
47
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
48
		$this->projet = self::PROJET_DEFAUT;
48
		$this->projet = self::PROJET_DEFAUT;
49
 
49
 
50
		// définition du projet / mission
50
		// définition du projet / mission
51
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
51
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
52
			$projets = explode(',', $this->parametres['projet']);
52
			$projets = explode(',', $this->parametres['projet']);
53
			$this->projet = strtolower($projets[0]);
53
			$this->projet = strtolower($projets[0]);
54
		}
54
		}
55
		$this->chargerConfigProjet();
55
		$this->chargerConfigProjet();
-
 
56
 
-
 
57
		// définition de la langue, en mode souple
-
 
58
		if (isset($this->parametres['lang'])) {
-
 
59
			$this->langue = $this->parametres['lang'];
-
 
60
		}
56
 
61
 
57
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
62
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
58
		$retour = null;
63
		$retour = null;
59
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
64
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
60
		$methode = $this->traiterNomMethodeExecuter($service);
65
		$methode = $this->traiterNomMethodeExecuter($service);
61
		if (method_exists($this, $methode)) {
66
		if (method_exists($this, $methode)) {
62
			$retour = $this->$methode();
67
			$retour = $this->$methode();
63
		} else {
68
		} else {
64
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
69
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
65
		}
70
		}
66
 
-
 
67
		// définition de la langue, en mode souple
-
 
68
		if (isset($this->parametres['lang'])) {
-
 
69
			$this->langue = $this->parametres['lang'];
-
 
70
		}
-
 
71
 
71
 
72
		// injection des données dans le squelette
72
		// injection des données dans le squelette
73
		$contenu = null;
73
		$contenu = null;
74
		$mime = null;
74
		$mime = null;
75
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
75
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
76
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
76
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
77
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
77
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
78
			$suffixeLangue = "";
78
			$suffixeLangue = "";
-
 
79
			// Si "nolang" n'est pas vide, on ne cherchera pas de squelette spécifique à la langue en cours
79
			if ($this->langue != null && $this->langue != "fr") {
80
			if ($this->langue != null && $this->langue != "fr" && empty($retour['nolang'])) {
80
				$suffixeLangue = "_" . $this->langue;
81
				$suffixeLangue = "_" . $this->langue;
81
			}
82
			}
82
			// Template par défaut ou spécifique
83
			// Template par défaut ou spécifique
83
			if ($this->projetASquelette()) {
84
			if ($this->projetASquelette()) {
84
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
85
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
85
			} else {
86
			} else {
86
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
87
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
87
			}
88
			}
88
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
89
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
89
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
90
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
90
		} else {
91
		} else {
91
			if (count($this->messages) == 0) {
92
			if (count($this->messages) == 0) {
92
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
93
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
93
			}
94
			}
94
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
95
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
95
		}
96
		}
96
 
97
 
97
		// envoi de la page
98
		// envoi de la page
98
		$this->envoyer($contenu, $mime);
99
		$this->envoyer($contenu, $mime);
99
	}
100
	}
100
 
101
 
101
	/**
102
	/**
102
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
103
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
103
	 * Si une mission est définie, charge séparément la section de la configuration concernant
104
	 * Si une mission est définie, charge séparément la section de la configuration concernant
104
	 * cette mission : [nommission]
105
	 * cette mission : [nommission]
105
	 */
106
	 */
106
	protected function chargerConfigProjet() {
107
	protected function chargerConfigProjet() {
107
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
108
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
108
		if (file_exists($fichier_config)) {
109
		if (file_exists($fichier_config)) {
109
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
110
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
110
				if (isset($_GET['mission'])) {
111
				if (isset($_GET['mission'])) {
111
					$this->mission = strtolower(trim($_GET['mission']));
112
					$this->mission = strtolower(trim($_GET['mission']));
112
					if (isset($this->configProjet[$this->mission])) {
113
					if (isset($this->configProjet[$this->mission])) {
113
						$this->configMission = $this->configProjet[$this->mission];
114
						$this->configMission = $this->configProjet[$this->mission];
114
					}
115
					}
115
				}
116
				}
116
			} else {
117
			} else {
117
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
118
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
118
			}
119
			}
119
		} else {
120
		} else {
120
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
121
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
121
		}
122
		}
122
	}
123
	}
123
 
124
 
124
	/**
125
	/**
125
	 * Retourne true si le dossier du projet courant existe, false sinon
126
	 * Retourne true si le dossier du projet courant existe, false sinon
126
	 * @return boolean
127
	 * @return boolean
127
	 */
128
	 */
128
	protected function projetASquelette() {
129
	protected function projetASquelette() {
129
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
130
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
130
	}
131
	}
131
 
132
 
132
	/**
133
	/**
133
	 * Exécution du widget complet 
134
	 * Exécution du widget complet 
134
	 * @return Ambigous <string, unknown, multitype:string unknown >
135
	 * @return Ambigous <string, unknown, multitype:string unknown >
135
	 */
136
	 */
136
	public function executerWidget() {
137
	public function executerWidget() {
137
		$widget['squelette'] = $this->projet;
138
		$widget['squelette'] = $this->projet;
138
		$widget['donnees'] = array();
139
		$widget['donnees'] = array();
139
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
140
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
140
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
141
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
141
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
142
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
142
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
143
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
143
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
144
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
144
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
145
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
145
 
146
 
146
		$widget['donnees']['logo'] = $this->getLogoPage();
147
		$widget['donnees']['logo'] = $this->getLogoPage();
147
		$widget['donnees']['titre'] = $this->getTitrePage();
148
		$widget['donnees']['titre'] = $this->getTitrePage();
148
		$widget['donnees']['nom_mission'] = $this->getNomMissionFlore();
149
		$widget['donnees']['nom_mission'] = $this->getNomMissionFlore();
149
 
150
 
150
		$widget['donnees']['zone_geo'] = $this->getZoneGeo();
151
		$widget['donnees']['zone_geo'] = $this->getZoneGeo();
151
		$widget['donnees']['groupe_zones_geo'] = $this->getGroupeZonesGeo();
152
		$widget['donnees']['groupe_zones_geo'] = $this->getGroupeZonesGeo();
152
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
153
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
153
		$widget['donnees']['espece_imposee'] = false;
154
		$widget['donnees']['espece_imposee'] = false;
154
		$widget['donnees']['nn_espece_defaut'] = '';
155
		$widget['donnees']['nn_espece_defaut'] = '';
155
		$widget['donnees']['nom_sci_espece_defaut'] = '';
156
		$widget['donnees']['nom_sci_espece_defaut'] = '';
156
		$widget['donnees']['infos_espece'] = '{}';
157
		$widget['donnees']['infos_espece'] = '{}';
157
 
158
 
158
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
159
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
159
 
160
 
160
		$widget['donnees']['cleGoogleMaps'] = $this->config['api']['cleGoogleMaps'];
161
		$widget['donnees']['cleGoogleMaps'] = $this->config['api']['cleGoogleMaps'];
161
		
162
		
162
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
163
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
163
 
164
 
164
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
165
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
165
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
166
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
166
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
167
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
167
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
168
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
168
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
169
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
169
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
170
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
170
		
171
		
171
		$widget['donnees']['url_ws_coord_search_tpl'] = $this->config['chemins']['serviceCoordSearchUrl'];
172
		$widget['donnees']['url_ws_coord_search_tpl'] = $this->config['chemins']['serviceCoordSearchUrl'];
172
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
173
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
173
		
174
		
174
		if ($this->especeEstImposee()) {
175
		if ($this->especeEstImposee()) {
175
			$nnEspeceImposee = $this->getNnEspeceImposee();
176
			$nnEspeceImposee = $this->getNnEspeceImposee();
176
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
177
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
177
			$widget['donnees']['espece_imposee'] = true;
178
			$widget['donnees']['espece_imposee'] = true;
178
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
179
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
179
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
180
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
180
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
181
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
181
		}
182
		}
182
 
183
 
183
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
184
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
184
		if (in_array($this->projet, $projetsAListeDeNoms) && !$this->especeEstImposee()) {
185
		if (in_array($this->projet, $projetsAListeDeNoms) && !$this->especeEstImposee()) {
185
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
186
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
186
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
187
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
187
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
188
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
188
			} else {
189
			} else {
189
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
190
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
190
			}
191
			}
191
		}
192
		}
192
 
193
 
193
		// Chargement de la liste des milieux issues du fichier .ini du projet
194
		// Chargement de la liste des milieux issues du fichier .ini du projet
194
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
195
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
195
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
196
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
196
			$widget['donnees']['milieux'] = $this->parserMilieux();
197
			$widget['donnees']['milieux'] = $this->parserMilieux();
197
		}
198
		}
198
 
199
 
199
		return $widget;
200
		return $widget;
200
	}
201
	}
201
 
202
 
202
	protected function getTitrePage() {
203
	protected function getTitrePage() {
203
		$titre = 'defaut';
204
		$titre = 'defaut';
204
		if (isset($this->configProjet['titre_page'])) {
205
		if (isset($this->configProjet['titre_page'])) {
205
			$titre = $this->configProjet['titre_page'];
206
			$titre = $this->configProjet['titre_page'];
206
		}
207
		}
207
		if (isset($this->configMission['titre_page'])) {
208
		if (isset($this->configMission['titre_page'])) {
208
			$titre = $this->configMission['titre_page'];
209
			$titre = $this->configMission['titre_page'];
209
		}
210
		}
210
		if (isset($_GET['titre'])) {
211
		if (isset($_GET['titre'])) {
211
			$titre = $_GET['titre'];
212
			$titre = $_GET['titre'];
212
		}
213
		}
213
		if ($titre === 0) { // wtf ?
214
		if ($titre === 0) { // wtf ?
214
			$titre = '';
215
			$titre = '';
215
		}
216
		}
216
		return $titre;
217
		return $titre;
217
	}
218
	}
218
 
219
 
219
	protected function getLogoPage() {
220
	protected function getLogoPage() {
220
		$logo = 'defaut';
221
		$logo = 'defaut';
221
		if (isset($this->configProjet['logo_page'])) {
222
		if (isset($this->configProjet['logo_page'])) {
222
			$logo = $this->configProjet['logo_page'];
223
			$logo = $this->configProjet['logo_page'];
223
		}
224
		}
224
		if (isset($this->configMission['logo_page'])) {
225
		if (isset($this->configMission['logo_page'])) {
225
			$logo = $this->configMission['logo_page'];
226
			$logo = $this->configMission['logo_page'];
226
		}
227
		}
227
		if (isset($_GET['logo'])) {
228
		if (isset($_GET['logo'])) {
228
			$logo = $_GET['logo'];
229
			$logo = $_GET['logo'];
229
		}
230
		}
230
		return $logo;
231
		return $logo;
231
	}
232
	}
232
 
233
 
233
	protected function getGroupeZonesGeo() {
234
	protected function getGroupeZonesGeo() {
234
		$groupe = null;
235
		$groupe = null;
235
		if (isset($_GET['groupe_zones_geo'])) {
236
		if (isset($_GET['groupe_zones_geo'])) {
236
			$groupe = $_GET['groupe_zones_geo'];
237
			$groupe = $_GET['groupe_zones_geo'];
237
		}
238
		}
238
		return $groupe;
239
		return $groupe;
239
	}
240
	}
240
 
241
 
241
	protected function getZoneGeo() {
242
	protected function getZoneGeo() {
242
		$zone_geo = null;
243
		$zone_geo = null;
243
		if (isset($_GET['zone_geo'])) {
244
		if (isset($_GET['zone_geo'])) {
244
			$zone_geo = $_GET['zone_geo'];
245
			$zone_geo = $_GET['zone_geo'];
245
		}
246
		}
246
		return $zone_geo;
247
		return $zone_geo;
247
	}
248
	}
248
 
249
 
249
	protected function getReferentielImpose() {
250
	protected function getReferentielImpose() {
250
		$referentiel_impose = true;
251
		$referentiel_impose = true;
251
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
252
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
252
			$this->ns_referentiel = $_GET['referentiel'];
253
			$this->ns_referentiel = $_GET['referentiel'];
253
		} else if (isset($this->configProjet['referentiel'])) {
254
		} else if (isset($this->configProjet['referentiel'])) {
254
			$this->ns_referentiel = $this->configProjet['referentiel'];
255
			$this->ns_referentiel = $this->configProjet['referentiel'];
255
		} else if (isset($this->configMission['referentiel'])) {
256
		} else if (isset($this->configMission['referentiel'])) {
256
			$this->ns_referentiel = $this->configMission['referentiel'];
257
			$this->ns_referentiel = $this->configMission['referentiel'];
257
		} else {
258
		} else {
258
			$referentiel_impose = false;
259
			$referentiel_impose = false;
259
		}
260
		}
260
		return $referentiel_impose;
261
		return $referentiel_impose;
261
	}
262
	}
262
 
263
 
263
	/**
264
	/**
264
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
265
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
265
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
266
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
266
	 */
267
	 */
267
	protected function getNomMissionFlore() {
268
	protected function getNomMissionFlore() {
268
		$nom = $this->mission;
269
		$nom = $this->mission;
269
		if (isset($this->configMission['nom_mission'])) {
270
		if (isset($this->configMission['nom_mission'])) {
270
			$nom = $this->configMission['nom_mission'];
271
			$nom = $this->configMission['nom_mission'];
271
		}
272
		}
272
		return $nom;
273
		return $nom;
273
	}
274
	}
274
 
275
 
275
	/**
276
	/**
276
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
277
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
277
	 * pour certains projets
278
	 * pour certains projets
278
	 * @return string
279
	 * @return string
279
	 */
280
	 */
280
	public function executerTaxons() {
281
	public function executerTaxons() {
281
		$widget['squelette'] = $this->projet.'_taxons';
282
		$widget['squelette'] = $this->projet.'_taxons';
282
		$widget['squelette_ext'] = '.tpl.js';
283
		$widget['squelette_ext'] = '.tpl.js';
283
		$widget['donnees'] = array();
284
		$widget['donnees'] = array();
284
		$nomsAAfficher = $this->recupererListeNomsSci();
285
		$nomsAAfficher = $this->recupererListeNomsSci();
285
		$taxons_tries = array();
286
		$taxons_tries = array();
286
		foreach ($nomsAAfficher as $taxon) {
287
		foreach ($nomsAAfficher as $taxon) {
287
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
288
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
288
		}
289
		}
289
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
290
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
-
 
291
		//echo "<pre>"; var_dump($widget); echo "</pre>";
-
 
292
		// Le squelette n'est pas traduit, seules les données de taxons le sont
-
 
293
		$widget['nolang'] = true;
-
 
294
 
290
		return $widget;
295
		return $widget;
291
	}
296
	}
292
 
297
 
293
	/**
298
	/**
294
	 * Trie par nom français les taxons lus dans le fichier tsv
299
	 * Trie par nom français les taxons lus dans le fichier tsv
295
	 */
300
	 */
296
	protected function recupererListeNomsSci() {
301
	protected function recupererListeNomsSci() {
297
		$taxons = $this->recupererListeTaxon();
302
		$taxons = $this->recupererListeTaxon();
298
		if (is_array($taxons)) {
303
		if (is_array($taxons)) {
299
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
304
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
300
		}
305
		}
301
		return $taxons;
306
		return $taxons;
302
	}
307
	}
303
 
308
 
304
	/**
309
	/**
305
	 * @TODO documenter
310
	 * @TODO documenter
306
	 * @return array
311
	 * @return array
307
	 */
312
	 */
308
	protected function recupererListeNoms() {
313
	protected function recupererListeNoms() {
309
		$taxons = $this->recupererListeTaxon();
314
		$taxons = $this->recupererListeTaxon();
310
		$nomsAAfficher = array();
315
		$nomsAAfficher = array();
311
		$nomsSpeciaux = array();
316
		$nomsSpeciaux = array();
312
		if (is_array($taxons)) {
317
		if (is_array($taxons)) {
313
			foreach ($taxons as $taxon) {
318
			foreach ($taxons as $taxon) {
314
				$nomSciTitle = $taxon['nom_ret'].
319
				$nomSciTitle = $taxon['nom_ret'].
315
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
320
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
316
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
321
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
317
				$nomFrTitle = $taxon['nom_sel'].
322
				$nomFrTitle = $taxon['nom_sel'].
318
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
323
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
319
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
324
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
320
 
325
 
321
				if ($taxon['groupe'] == 'special') {
326
				if ($taxon['groupe'] == 'special') {
322
					$nomsSpeciaux[] = array(
327
					$nomsSpeciaux[] = array(
323
						'num_nom' => $taxon['num_nom_sel'],
328
						'num_nom' => $taxon['num_nom_sel'],
324
						'nom_a_afficher' => $taxon['nom_fr'],
329
						'nom_a_afficher' => $taxon['nom_fr'],
325
						'nom_a_sauver' => $taxon['nom_sel'],
330
						'nom_a_sauver' => $taxon['nom_sel'],
326
						'nom_title' => $nomSciTitle,
331
						'nom_title' => $nomSciTitle,
327
						'nom_type' => 'nom-special');
332
						'nom_type' => 'nom-special');
328
				} else {
333
				} else {
329
					$nomsAAfficher[] = array(
334
					$nomsAAfficher[] = array(
330
						'num_nom' => $taxon['num_nom_sel'],
335
						'num_nom' => $taxon['num_nom_sel'],
331
						'nom_a_afficher' => $taxon['nom_sel'],
336
						'nom_a_afficher' => $taxon['nom_sel'],
332
						'nom_a_sauver' => $taxon['nom_sel'],
337
						'nom_a_sauver' => $taxon['nom_sel'],
333
						'nom_title' => $nomSciTitle,
338
						'nom_title' => $nomSciTitle,
334
						'nom_type' => 'nom-sci');
339
						'nom_type' => 'nom-sci');
335
					$nomsAAfficher[] = array(
340
					$nomsAAfficher[] = array(
336
						'num_nom' => $taxon['num_nom_sel'],
341
						'num_nom' => $taxon['num_nom_sel'],
337
						'nom_a_afficher' => $taxon['nom_fr'],
342
						'nom_a_afficher' => $taxon['nom_fr'],
338
						'nom_a_sauver' => $taxon['nom_fr'],
343
						'nom_a_sauver' => $taxon['nom_fr'],
339
						'nom_title' => $nomFrTitle,
344
						'nom_title' => $nomFrTitle,
340
						'nom_type' => 'nom-fr');
345
						'nom_type' => 'nom-fr');
341
				}
346
				}
342
			}
347
			}
343
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
348
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
344
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
349
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
345
		}
350
		}
346
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
351
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
347
	}
352
	}
348
 
353
 
349
	/**
354
	/**
350
	 * Lit une liste de taxons depuis un fichier tsv fourni
355
	 * Lit une liste de taxons depuis un fichier tsv fourni
351
	 */
356
	 */
352
	protected function recupererListeTaxon() {
357
	protected function recupererListeTaxon() {
353
		$taxons = array();
358
		$taxons = array();
-
 
359
		$fichier_tsv = null;
354
		if ($this->projet == 'missions-flore') {
360
		if ($this->projet == 'missions-flore') {
355
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_'.$this->mission.'_taxons.tsv';
361
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_'.$this->mission.'_taxons.tsv';
356
		} else {
362
		} else {
-
 
363
			// recherche d'un fichier traduit (pour les noms vernaculaires)
-
 
364
			$suffixeLangue = "";
-
 
365
			if ($this->langue != null && $this->langue != "fr") {
-
 
366
				$suffixeLangue = "_" . $this->langue;
-
 
367
				$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons'.$suffixeLangue.'.tsv';
-
 
368
			}
-
 
369
			// si le fichier de taxons traduit n'est pas disponible ou qu'on n'a
-
 
370
			// pas demandé de langue particulière, on se rabat sur celui par défaut
-
 
371
			if (! file_exists($fichier_tsv)) {
357
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
372
				$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
-
 
373
			}
358
		}
374
		}
359
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
375
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
360
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
376
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
361
		} else {
377
		} else {
362
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
378
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
363
		}
379
		}
364
		return $taxons;
380
		return $taxons;
365
	}
381
	}
366
 
382
 
367
	/**
383
	/**
368
	 * Découpe un fihcier tsv
384
	 * Découpe un fihcier tsv
369
	 */
385
	 */
370
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
386
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
371
		$header = null;
387
		$header = null;
372
		$data = array();
388
		$data = array();
373
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
389
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
374
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
390
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
375
				if (!$header) {
391
				if (!$header) {
376
					$header = $row;
392
					$header = $row;
377
				} else {
393
				} else {
378
					$data[] = array_combine($header, $row);
394
					$data[] = array_combine($header, $row);
379
				}
395
				}
380
			}
396
			}
381
			fclose($handle);
397
			fclose($handle);
382
		}
398
		}
383
		return $data;
399
		return $data;
384
	}
400
	}
385
 
401
 
386
	/**
402
	/**
387
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
403
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
388
	 * du projet, si elle existe
404
	 * du projet, si elle existe
389
	 * @return array
405
	 * @return array
390
	 */
406
	 */
391
	protected function parserMilieux() {
407
	protected function parserMilieux() {
392
		$infosMilieux = array();
408
		$infosMilieux = array();
393
		if (isset($this->configProjet['milieux'])) {
409
		if (isset($this->configProjet['milieux'])) {
394
			$milieux = explode('|', $this->configProjet['milieux']);
410
			$milieux = explode('|', $this->configProjet['milieux']);
395
			foreach ($milieux as $milieu) {
411
			foreach ($milieux as $milieu) {
396
				$milieu = trim($milieu);
412
				$milieu = trim($milieu);
397
				$details = explode(';', $milieu);
413
				$details = explode(';', $milieu);
398
				if (isset($details[1])) {
414
				if (isset($details[1])) {
399
					$infosMilieux[$details[0]] = $details[1];
415
					$infosMilieux[$details[0]] = $details[1];
400
				} else {
416
				} else {
401
					$infosMilieux[$details[0]] = '';
417
					$infosMilieux[$details[0]] = '';
402
				}
418
				}
403
			}
419
			}
404
			ksort($infosMilieux);
420
			ksort($infosMilieux);
405
		}
421
		}
406
		return $infosMilieux;
422
		return $infosMilieux;
407
	}
423
	}
408
 
424
 
409
	/**
425
	/**
410
	 * Retourne true si le widget est restreint à une espèce, false sinon
426
	 * Retourne true si le widget est restreint à une espèce, false sinon
411
	 * @return boolean
427
	 * @return boolean
412
	 */
428
	 */
413
	protected function especeEstImposee() {
429
	protected function especeEstImposee() {
414
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
430
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
415
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
431
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
416
	}
432
	}
417
 
433
 
418
	/**
434
	/**
419
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
435
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
420
	 * le cas, null sinon
436
	 * le cas, null sinon
421
	 * @return string
437
	 * @return string
422
	 */
438
	 */
423
	protected function getNnEspeceImposee() {
439
	protected function getNnEspeceImposee() {
424
		$nn = null;
440
		$nn = null;
425
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
441
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
426
			$nn = $_GET['num_nom'];
442
			$nn = $_GET['num_nom'];
427
		} else if (isset($this->configProjet['sp_imposee'])) {
443
		} else if (isset($this->configProjet['sp_imposee'])) {
428
			$nn = $this->configProjet['sp_imposee'];
444
			$nn = $this->configProjet['sp_imposee'];
429
		} else if (isset($this->configMission['sp_imposee'])) {
445
		} else if (isset($this->configMission['sp_imposee'])) {
430
			$nn = $this->configMission['sp_imposee'];
446
			$nn = $this->configMission['sp_imposee'];
431
		}
447
		}
432
		return $nn;
448
		return $nn;
433
	}
449
	}
434
 
450
 
435
	/**
451
	/**
436
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
452
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
437
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
453
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
438
	 * et non le taxon?)
454
	 * et non le taxon?)
439
	 * @param string|int $num_nom
455
	 * @param string|int $num_nom
440
	 * @return array
456
	 * @return array
441
	 */
457
	 */
442
	protected function chargerInfosTaxon($num_nom) {
458
	protected function chargerInfosTaxon($num_nom) {
443
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
459
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
444
		$infos = json_decode(file_get_contents($url_service_infos));
460
		$infos = json_decode(file_get_contents($url_service_infos));
445
		// trop de champs injectés dans les infos espèces peuvent
461
		// trop de champs injectés dans les infos espèces peuvent
446
		// faire planter javascript
462
		// faire planter javascript
447
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
463
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
448
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
464
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
449
		$resultat = array();
465
		$resultat = array();
450
		if (isset($infos) && !empty($infos)) {
466
		if (isset($infos) && !empty($infos)) {
451
			$infos = (array)$infos;
467
			$infos = (array)$infos;
452
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
468
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
453
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
469
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
454
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
470
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
455
			}
471
			}
456
		}
472
		}
457
		return $resultat;
473
		return $resultat;
458
	}
474
	}
459
 
475
 
460
	/**
476
	/**
461
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
477
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
462
	 * @param array $array
478
	 * @param array $array
463
	 * @param boolean $show_keys
479
	 * @param boolean $show_keys
464
	 * @return une portion de JSON représentant le tableau
480
	 * @return une portion de JSON représentant le tableau
465
	 */
481
	 */
466
	protected function array2js($array,$show_keys) {
482
	protected function array2js($array,$show_keys) {
467
		$tableauJs = '{}';
483
		$tableauJs = '{}';
468
		if (!empty($array)) {
484
		if (!empty($array)) {
469
			$total = count($array) - 1;
485
			$total = count($array) - 1;
470
			$i = 0;
486
			$i = 0;
471
			$dimensions = array();
487
			$dimensions = array();
472
			foreach ($array as $key => $value) {
488
			foreach ($array as $key => $value) {
473
				if (is_array($value)) {
489
				if (is_array($value)) {
474
					$dimensions[$i] = array2js($value,$show_keys);
490
					$dimensions[$i] = array2js($value,$show_keys);
475
					if ($show_keys) {
491
					if ($show_keys) {
476
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
492
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
477
					}
493
					}
478
				} else {
494
				} else {
479
					$dimensions[$i] = '"'.addslashes($value).'"';
495
					$dimensions[$i] = '"'.addslashes($value).'"';
480
					if ($show_keys) {
496
					if ($show_keys) {
481
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
497
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
482
					}
498
					}
483
				}
499
				}
484
				if ($i == 0) {
500
				if ($i == 0) {
485
					$dimensions[$i] = '{'.$dimensions[$i];
501
					$dimensions[$i] = '{'.$dimensions[$i];
486
				}
502
				}
487
				if ($i == $total) {
503
				if ($i == $total) {
488
					$dimensions[$i].= '}';
504
					$dimensions[$i].= '}';
489
				}
505
				}
490
				$i++;
506
				$i++;
491
			}
507
			}
492
			$tableauJs = implode(',', $dimensions);
508
			$tableauJs = implode(',', $dimensions);
493
		}
509
		}
494
		return $tableauJs;
510
		return $tableauJs;
495
	}
511
	}
496
}
512
}