Subversion Repositories eFlore/Applications.cel

Rev

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

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