Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2869 Rev 2906
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 = 'bdtfx';
30
	const REFERENTIEL_DEFAUT = 'bdtfx';
31
 
31
 
32
	/** référentiel utilisé pour al 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']['referentiel_impose'] = $this->getReferentielImpose();
151
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
151
		$widget['donnees']['espece_imposee'] = false;
152
		$widget['donnees']['espece_imposee'] = false;
152
		$widget['donnees']['nn_espece_defaut'] = '';
153
		$widget['donnees']['nn_espece_defaut'] = '';
153
		$widget['donnees']['nom_sci_espece_defaut'] = '';
154
		$widget['donnees']['nom_sci_espece_defaut'] = '';
154
		$widget['donnees']['infos_espece'] = '{}';
155
		$widget['donnees']['infos_espece'] = '{}';
155
 
156
 
156
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
157
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
157
		
158
		
158
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
159
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
159
 
160
 
160
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
161
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
161
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
162
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
162
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
163
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
163
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
164
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
164
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
165
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
165
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
166
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
166
		
167
		
167
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
168
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
168
		
169
		
169
		if ($this->especeEstImposee()) {
170
		if ($this->especeEstImposee()) {
170
			$nnEspeceImposee = $this->getNnEspeceImposee();
171
			$nnEspeceImposee = $this->getNnEspeceImposee();
171
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
172
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
172
			$widget['donnees']['espece_imposee'] = true;
173
			$widget['donnees']['espece_imposee'] = true;
173
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
174
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
174
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
175
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
175
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
176
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
176
		}
177
		}
177
 
178
 
178
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
179
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
179
		if (in_array($this->projet, $projetsAListeDeNoms)) {
180
		if (in_array($this->projet, $projetsAListeDeNoms)) {
180
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
181
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
181
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
182
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
182
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
183
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
183
			} else {
184
			} else {
184
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
185
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
185
			}
186
			}
186
		}
187
		}
187
 
188
 
188
		// Chargement de la liste des milieux issues du fichier .ini du projet
189
		// Chargement de la liste des milieux issues du fichier .ini du projet
189
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
190
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
190
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
191
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
191
			$widget['donnees']['milieux'] = $this->parserMilieux();
192
			$widget['donnees']['milieux'] = $this->parserMilieux();
192
		}
193
		}
193
 
194
 
194
		return $widget;
195
		return $widget;
195
	}
196
	}
196
 
197
 
197
	protected function getTitrePage() {
198
	protected function getTitrePage() {
198
		$titre = 'defaut';
199
		$titre = 'defaut';
199
		if (isset($this->configProjet['titre_page'])) {
200
		if (isset($this->configProjet['titre_page'])) {
200
			$titre = $this->configProjet['titre_page'];
201
			$titre = $this->configProjet['titre_page'];
201
		}
202
		}
202
		if (isset($this->configMission['titre_page'])) {
203
		if (isset($this->configMission['titre_page'])) {
203
			$titre = $this->configMission['titre_page'];
204
			$titre = $this->configMission['titre_page'];
204
		}
205
		}
205
		if (isset($_GET['titre'])) {
206
		if (isset($_GET['titre'])) {
206
			$titre = $_GET['titre'];
207
			$titre = $_GET['titre'];
207
		}
208
		}
208
		if ($titre === 0) { // wtf ?
209
		if ($titre === 0) { // wtf ?
209
			$titre = '';
210
			$titre = '';
210
		}
211
		}
211
		return $titre;
212
		return $titre;
212
	}
213
	}
213
 
214
 
214
	protected function getLogoPage() {
215
	protected function getLogoPage() {
215
		$logo = 'defaut';
216
		$logo = 'defaut';
216
		if (isset($this->configProjet['logo_page'])) {
217
		if (isset($this->configProjet['logo_page'])) {
217
			$logo = $this->configProjet['logo_page'];
218
			$logo = $this->configProjet['logo_page'];
218
		}
219
		}
219
		if (isset($this->configMission['logo_page'])) {
220
		if (isset($this->configMission['logo_page'])) {
220
			$logo = $this->configMission['logo_page'];
221
			$logo = $this->configMission['logo_page'];
221
		}
222
		}
222
		if (isset($_GET['logo'])) {
223
		if (isset($_GET['logo'])) {
223
			$logo = $_GET['logo'];
224
			$logo = $_GET['logo'];
224
		}
225
		}
225
		return $logo;
226
		return $logo;
226
	}
227
	}
-
 
228
	
-
 
229
	protected function getZoneGeo() {
-
 
230
		$zone_geo = null;
-
 
231
		if (isset($_GET['zone_geo'])) {
-
 
232
			$zone_geo = $_GET['zone_geo'];
-
 
233
		}
-
 
234
		return $zone_geo;
-
 
235
	}
227
 
236
 
228
	protected function getReferentielImpose() {
237
	protected function getReferentielImpose() {
229
		$referentiel_impose = true;
238
		$referentiel_impose = true;
230
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
239
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
231
			$this->ns_referentiel = $_GET['referentiel'];
240
			$this->ns_referentiel = $_GET['referentiel'];
232
		} else if (isset($this->configProjet['referentiel'])) {
241
		} else if (isset($this->configProjet['referentiel'])) {
233
			$this->ns_referentiel = $this->configProjet['referentiel'];
242
			$this->ns_referentiel = $this->configProjet['referentiel'];
234
		} else if (isset($this->configMission['referentiel'])) {
243
		} else if (isset($this->configMission['referentiel'])) {
235
			$this->ns_referentiel = $this->configMission['referentiel'];
244
			$this->ns_referentiel = $this->configMission['referentiel'];
236
		} else {
245
		} else {
237
			$referentiel_impose = false;
246
			$referentiel_impose = false;
238
		}
247
		}
239
		return $referentiel_impose;
248
		return $referentiel_impose;
240
	}
249
	}
241
 
250
 
242
	/**
251
	/**
243
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
252
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
244
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
253
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
245
	 */
254
	 */
246
	protected function getNomMissionFlore() {
255
	protected function getNomMissionFlore() {
247
		$nom = $this->mission;
256
		$nom = $this->mission;
248
		if (isset($this->configMission['nom_mission'])) {
257
		if (isset($this->configMission['nom_mission'])) {
249
			$nom = $this->configMission['nom_mission'];
258
			$nom = $this->configMission['nom_mission'];
250
		}
259
		}
251
		return $nom;
260
		return $nom;
252
	}
261
	}
253
 
262
 
254
	/**
263
	/**
255
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
264
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
256
	 * pour certains projets
265
	 * pour certains projets
257
	 * @return string
266
	 * @return string
258
	 */
267
	 */
259
	public function executerTaxons() {
268
	public function executerTaxons() {
260
		$widget['squelette'] = $this->projet.'_taxons';
269
		$widget['squelette'] = $this->projet.'_taxons';
261
		$widget['squelette_ext'] = '.tpl.js';
270
		$widget['squelette_ext'] = '.tpl.js';
262
		$widget['donnees'] = array();
271
		$widget['donnees'] = array();
263
		$nomsAAfficher = $this->recupererListeNomsSci();
272
		$nomsAAfficher = $this->recupererListeNomsSci();
264
		$taxons_tries = array();
273
		$taxons_tries = array();
265
		foreach ($nomsAAfficher as $taxon) {
274
		foreach ($nomsAAfficher as $taxon) {
266
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
275
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
267
		}
276
		}
268
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
277
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
269
		return $widget;
278
		return $widget;
270
	}
279
	}
271
 
280
 
272
	/**
281
	/**
273
	 * Trie par nom français les taxons lus dans le fichier tsv
282
	 * Trie par nom français les taxons lus dans le fichier tsv
274
	 */
283
	 */
275
	protected function recupererListeNomsSci() {
284
	protected function recupererListeNomsSci() {
276
		$taxons = $this->recupererListeTaxon();
285
		$taxons = $this->recupererListeTaxon();
277
		if (is_array($taxons)) {
286
		if (is_array($taxons)) {
278
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
287
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
279
		}
288
		}
280
		return $taxons;
289
		return $taxons;
281
	}
290
	}
282
 
291
 
283
	/**
292
	/**
284
	 * @TODO documenter
293
	 * @TODO documenter
285
	 * @return array
294
	 * @return array
286
	 */
295
	 */
287
	protected function recupererListeNoms() {
296
	protected function recupererListeNoms() {
288
		$taxons = $this->recupererListeTaxon();
297
		$taxons = $this->recupererListeTaxon();
289
		$nomsAAfficher = array();
298
		$nomsAAfficher = array();
290
		$nomsSpeciaux = array();
299
		$nomsSpeciaux = array();
291
		if (is_array($taxons)) {
300
		if (is_array($taxons)) {
292
			foreach ($taxons as $taxon) {
301
			foreach ($taxons as $taxon) {
293
				$nomSciTitle = $taxon['nom_ret'].
302
				$nomSciTitle = $taxon['nom_ret'].
294
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
303
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
295
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
304
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
296
				$nomFrTitle = $taxon['nom_sel'].
305
				$nomFrTitle = $taxon['nom_sel'].
297
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
306
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
298
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
307
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
299
 
308
 
300
				if ($taxon['groupe'] == 'special') {
309
				if ($taxon['groupe'] == 'special') {
301
					$nomsSpeciaux[] = array(
310
					$nomsSpeciaux[] = array(
302
						'num_nom' => $taxon['num_nom_sel'],
311
						'num_nom' => $taxon['num_nom_sel'],
303
						'nom_a_afficher' => $taxon['nom_fr'],
312
						'nom_a_afficher' => $taxon['nom_fr'],
304
						'nom_a_sauver' => $taxon['nom_sel'],
313
						'nom_a_sauver' => $taxon['nom_sel'],
305
						'nom_title' => $nomSciTitle,
314
						'nom_title' => $nomSciTitle,
306
						'nom_type' => 'nom-special');
315
						'nom_type' => 'nom-special');
307
				} else {
316
				} else {
308
					$nomsAAfficher[] = array(
317
					$nomsAAfficher[] = array(
309
						'num_nom' => $taxon['num_nom_sel'],
318
						'num_nom' => $taxon['num_nom_sel'],
310
						'nom_a_afficher' => $taxon['nom_sel'],
319
						'nom_a_afficher' => $taxon['nom_sel'],
311
						'nom_a_sauver' => $taxon['nom_sel'],
320
						'nom_a_sauver' => $taxon['nom_sel'],
312
						'nom_title' => $nomSciTitle,
321
						'nom_title' => $nomSciTitle,
313
						'nom_type' => 'nom-sci');
322
						'nom_type' => 'nom-sci');
314
					$nomsAAfficher[] = array(
323
					$nomsAAfficher[] = array(
315
						'num_nom' => $taxon['num_nom_sel'],
324
						'num_nom' => $taxon['num_nom_sel'],
316
						'nom_a_afficher' => $taxon['nom_fr'],
325
						'nom_a_afficher' => $taxon['nom_fr'],
317
						'nom_a_sauver' => $taxon['nom_fr'],
326
						'nom_a_sauver' => $taxon['nom_fr'],
318
						'nom_title' => $nomFrTitle,
327
						'nom_title' => $nomFrTitle,
319
						'nom_type' => 'nom-fr');
328
						'nom_type' => 'nom-fr');
320
				}
329
				}
321
			}
330
			}
322
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
331
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
323
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
332
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
324
		}
333
		}
325
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
334
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
326
	}
335
	}
327
 
336
 
328
	/**
337
	/**
329
	 * Lit une liste de taxons depuis un fichier tsv fourni
338
	 * Lit une liste de taxons depuis un fichier tsv fourni
330
	 */
339
	 */
331
	protected function recupererListeTaxon() {
340
	protected function recupererListeTaxon() {
332
		$taxons = array();
341
		$taxons = array();
333
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
342
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
334
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
343
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
335
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
344
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
336
		} else {
345
		} else {
337
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
346
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
338
		}
347
		}
339
		return $taxons;
348
		return $taxons;
340
	}
349
	}
341
 
350
 
342
	/**
351
	/**
343
	 * Découpe un fihcier tsv
352
	 * Découpe un fihcier tsv
344
	 */
353
	 */
345
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
354
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
346
		$header = null;
355
		$header = null;
347
		$data = array();
356
		$data = array();
348
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
357
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
349
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
358
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
350
				if (!$header) {
359
				if (!$header) {
351
					$header = $row;
360
					$header = $row;
352
				} else {
361
				} else {
353
					$data[] = array_combine($header, $row);
362
					$data[] = array_combine($header, $row);
354
				}
363
				}
355
			}
364
			}
356
			fclose($handle);
365
			fclose($handle);
357
		}
366
		}
358
		return $data;
367
		return $data;
359
	}
368
	}
360
 
369
 
361
	/**
370
	/**
362
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
371
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
363
	 * du projet, si elle existe
372
	 * du projet, si elle existe
364
	 * @return array
373
	 * @return array
365
	 */
374
	 */
366
	protected function parserMilieux() {
375
	protected function parserMilieux() {
367
		$infosMilieux = array();
376
		$infosMilieux = array();
368
		if (isset($this->configProjet['milieux'])) {
377
		if (isset($this->configProjet['milieux'])) {
369
			$milieux = explode('|', $this->configProjet['milieux']);
378
			$milieux = explode('|', $this->configProjet['milieux']);
370
			foreach ($milieux as $milieu) {
379
			foreach ($milieux as $milieu) {
371
				$milieu = trim($milieu);
380
				$milieu = trim($milieu);
372
				$details = explode(';', $milieu);
381
				$details = explode(';', $milieu);
373
				if (isset($details[1])) {
382
				if (isset($details[1])) {
374
					$infosMilieux[$details[0]] = $details[1];
383
					$infosMilieux[$details[0]] = $details[1];
375
				} else {
384
				} else {
376
					$infosMilieux[$details[0]] = '';
385
					$infosMilieux[$details[0]] = '';
377
				}
386
				}
378
			}
387
			}
379
			ksort($infosMilieux);
388
			ksort($infosMilieux);
380
		}
389
		}
381
		return $infosMilieux;
390
		return $infosMilieux;
382
	}
391
	}
383
 
392
 
384
	/**
393
	/**
385
	 * Retourne true si le widget est restreint à une espèce, false sinon
394
	 * Retourne true si le widget est restreint à une espèce, false sinon
386
	 * @return boolean
395
	 * @return boolean
387
	 */
396
	 */
388
	protected function especeEstImposee() {
397
	protected function especeEstImposee() {
389
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
398
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
390
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
399
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
391
	}
400
	}
392
 
401
 
393
	/**
402
	/**
394
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
403
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
395
	 * le cas, null sinon
404
	 * le cas, null sinon
396
	 * @return string
405
	 * @return string
397
	 */
406
	 */
398
	protected function getNnEspeceImposee() {
407
	protected function getNnEspeceImposee() {
399
		$nn = null;
408
		$nn = null;
400
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
409
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
401
			$nn = $_GET['num_nom'];
410
			$nn = $_GET['num_nom'];
402
		} else if (isset($this->configProjet['sp_imposee'])) {
411
		} else if (isset($this->configProjet['sp_imposee'])) {
403
			$nn = $this->configProjet['sp_imposee'];
412
			$nn = $this->configProjet['sp_imposee'];
404
		} else if (isset($this->configMission['sp_imposee'])) {
413
		} else if (isset($this->configMission['sp_imposee'])) {
405
			$nn = $this->configMission['sp_imposee'];
414
			$nn = $this->configMission['sp_imposee'];
406
		}
415
		}
407
		return $nn;
416
		return $nn;
408
	}
417
	}
409
 
418
 
410
	/**
419
	/**
411
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
420
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
412
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
421
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
413
	 * et non le taxon?)
422
	 * et non le taxon?)
414
	 * @param string|int $num_nom
423
	 * @param string|int $num_nom
415
	 * @return array
424
	 * @return array
416
	 */
425
	 */
417
	protected function chargerInfosTaxon($num_nom) {
426
	protected function chargerInfosTaxon($num_nom) {
418
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
427
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
419
		$infos = json_decode(file_get_contents($url_service_infos));
428
		$infos = json_decode(file_get_contents($url_service_infos));
420
		// trop de champs injectés dans les infos espèces peuvent
429
		// trop de champs injectés dans les infos espèces peuvent
421
		// faire planter javascript
430
		// faire planter javascript
422
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
431
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
423
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
432
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
424
		$resultat = array();
433
		$resultat = array();
425
		if (isset($infos) && !empty($infos)) {
434
		if (isset($infos) && !empty($infos)) {
426
			$infos = (array)$infos;
435
			$infos = (array)$infos;
427
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
436
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
428
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
437
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
429
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
438
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
430
			}
439
			}
431
		}
440
		}
432
		return $resultat;
441
		return $resultat;
433
	}
442
	}
434
 
443
 
435
	/**
444
	/**
436
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
445
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
437
	 * @param array $array
446
	 * @param array $array
438
	 * @param boolean $show_keys
447
	 * @param boolean $show_keys
439
	 * @return une portion de JSON représentant le tableau
448
	 * @return une portion de JSON représentant le tableau
440
	 */
449
	 */
441
	protected function array2js($array,$show_keys) {
450
	protected function array2js($array,$show_keys) {
442
		$tableauJs = '{}';
451
		$tableauJs = '{}';
443
		if (!empty($array)) {
452
		if (!empty($array)) {
444
			$total = count($array) - 1;
453
			$total = count($array) - 1;
445
			$i = 0;
454
			$i = 0;
446
			$dimensions = array();
455
			$dimensions = array();
447
			foreach ($array as $key => $value) {
456
			foreach ($array as $key => $value) {
448
				if (is_array($value)) {
457
				if (is_array($value)) {
449
					$dimensions[$i] = array2js($value,$show_keys);
458
					$dimensions[$i] = array2js($value,$show_keys);
450
					if ($show_keys) {
459
					if ($show_keys) {
451
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
460
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
452
					}
461
					}
453
				} else {
462
				} else {
454
					$dimensions[$i] = '"'.addslashes($value).'"';
463
					$dimensions[$i] = '"'.addslashes($value).'"';
455
					if ($show_keys) {
464
					if ($show_keys) {
456
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
465
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
457
					}
466
					}
458
				}
467
				}
459
				if ($i == 0) {
468
				if ($i == 0) {
460
					$dimensions[$i] = '{'.$dimensions[$i];
469
					$dimensions[$i] = '{'.$dimensions[$i];
461
				}
470
				}
462
				if ($i == $total) {
471
				if ($i == $total) {
463
					$dimensions[$i].= '}';
472
					$dimensions[$i].= '}';
464
				}
473
				}
465
				$i++;
474
				$i++;
466
			}
475
			}
467
			$tableauJs = implode(',', $dimensions);
476
			$tableauJs = implode(',', $dimensions);
468
		}
477
		}
469
		return $tableauJs;
478
		return $tableauJs;
470
	}
479
	}
471
}
-
 
472
480
}
-
 
481