Subversion Repositories eFlore/Applications.cel

Rev

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

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