Subversion Repositories eFlore/Applications.cel

Rev

Rev 2082 | Rev 2343 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2082 Rev 2328
Line 116... Line 116...
116
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
116
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
117
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
117
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
118
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
118
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
Line 119... Line 119...
119
 
119
 
-
 
120
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
120
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
121
		$projetsAutorises = array('defaut', 'ambrosia', 'florileges', 'sauvages');
121
		if ($this->projet == 'defaut' || $this->projet == 'florileges' || $this->projet == 'sauvages' || !$this->projetASquelette()) {
122
		if (in_array($this->projet, $projetsAutorises) || !$this->projetASquelette()) {
122
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
123
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
123
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
124
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
124
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
125
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
125
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
126
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
126
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
127
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
127
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
128
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
128
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
129
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
Line 133... Line 134...
133
			$widget['donnees']['nn_espece_defaut'] = '';
134
			$widget['donnees']['nn_espece_defaut'] = '';
134
			$widget['donnees']['nom_sci_espece_defaut'] = '';
135
			$widget['donnees']['nom_sci_espece_defaut'] = '';
135
			$widget['donnees']['infos_espece'] = '{}';
136
			$widget['donnees']['infos_espece'] = '{}';
Line 136... Line 137...
136
 
137
 
-
 
138
			if ($this->especeEstImposee()) {
137
			if ($this->especeEstImposee()) {
139
				$nnEspeceImposee = $this->getNnEspeceImposee();
138
				$nom = $this->executerChargementInfosTaxon($_GET['num_nom']);
140
				$nom = $this->executerChargementInfosTaxon($nnEspeceImposee);
139
				$widget['donnees']['espece_imposee'] = true;
141
				$widget['donnees']['espece_imposee'] = true;
140
				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
142
				$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
141
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
143
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
142
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
144
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
143
			}
145
			}
144
		}
146
		}
145
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
147
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
146
			if ($this->projet == 'florileges' || $this->projet == 'sauvages') {
148
			if ($this->projet == 'florileges' || $this->projet == 'sauvages') {
147
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
149
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
148
			} else {
150
			} else {
149
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
151
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
150
			}
152
			}
151
			$widget['donnees']['milieux'] = $this->parserMilieux();
153
			$widget['donnees']['milieux'] = $this->parserMilieux();
152
		}
154
		}
153
		return  $widget;
155
		return  $widget;
Line 157... Line 159...
157
		// fonction très simple qui ne teste que si le dossier du projet courant
159
		// fonction très simple qui ne teste que si le dossier du projet courant
158
		// existe, mais elle suffit pour le moment.
160
		// existe, mais elle suffit pour le moment.
159
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
161
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
160
	}
162
	}
Line 161... Line 163...
161
 
163
 
162
	public function executerTaxons() {
164
	public function executerTaxons() {
163
		$widget['squelette'] = $this->projet.'_taxons';
165
		$widget['squelette'] = $this->projet.'_taxons';
164
		$widget['squelette_ext'] = '.tpl.js';
166
		$widget['squelette_ext'] = '.tpl.js';
165
		$widget['donnees'] = array();
167
		$widget['donnees'] = array();
166
		$nomsAAfficher = $this->recupererListeNomsSci();
168
		$nomsAAfficher = $this->recupererListeNomsSci();
167
		$taxons_tries = array();
169
		$taxons_tries = array();
168
		foreach ($nomsAAfficher as $taxon) {
170
		foreach ($nomsAAfficher as $taxon) {
169
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
171
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
170
		}
172
		}
171
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
173
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
172
		return $widget;
174
		return $widget;
Line 173... Line 175...
173
	}
175
	}
174
 
176
 
175
	private function recupererListeNomsSci() {
177
	private function recupererListeNomsSci() {
176
		$taxons = $this->recupererListeTaxon();
178
		$taxons = $this->recupererListeTaxon();
Line 218... Line 220...
218
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
220
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
219
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
221
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
220
		}
222
		}
221
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
223
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
222
	}
224
	}
223
 
225
 
224
	private function recupererListeTaxon() {
226
	private function recupererListeTaxon() {
225
		$taxons = null;
227
		$taxons = null;
226
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
228
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
227
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
229
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
228
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
230
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
229
		} else {
231
		} else {
230
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
232
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
231
		}
233
		}
232
		return $taxons;
234
		return $taxons;
233
	}
235
	}
234
 
236
 
235
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
237
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
236
		$header = null;
238
		$header = null;
237
		$data = array();
239
		$data = array();
238
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
240
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
239
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
241
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
240
				if (!$header) {
242
				if (!$header) {
241
					$header = $row;
243
					$header = $row;
242
				} else {
244
				} else {
243
					$data[] = array_combine($header, $row);
245
					$data[] = array_combine($header, $row);
244
				}
246
				}
245
			}
247
			}
246
			fclose($handle);
248
			fclose($handle);
247
		}
249
		}
248
		return $data;
250
		return $data;
249
	}
251
	}
Line 250... Line 252...
250
 
252
 
251
	private function parserMilieux() {
253
	private function parserMilieux() {
252
		$infosMilieux = array();
254
		$infosMilieux = array();
253
		if (isset($this->configProjet['milieux'])) {
255
		if (isset($this->configProjet['milieux'])) {
254
			$milieux = explode('|', $this->configProjet['milieux']);
256
			$milieux = explode('|', $this->configProjet['milieux']);
-
 
257
			foreach ($milieux as $milieu) {
255
			foreach ($milieux as $milieu) {
258
				$milieu = trim($milieu);
256
				$details = explode(';', $milieu);
259
				$details = explode(';', $milieu);
257
				if (isset($details[1])) {
260
				if (isset($details[1])) {
258
					$infosMilieux[$details[0]] = $details[1];
261
					$infosMilieux[$details[0]] = $details[1];
259
				} else {
262
				} else {
Line 264... Line 267...
264
		}
267
		}
265
		return $infosMilieux;
268
		return $infosMilieux;
266
	}
269
	}
Line 267... Line 270...
267
 
270
 
268
	private function especeEstImposee() {
271
	private function especeEstImposee() {
-
 
272
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != ''
-
 
273
			|| isset($this->configProjet['sp_imposee']));
-
 
274
	}
-
 
275
 
-
 
276
	private function getNnEspeceImposee() {
-
 
277
		$nn = null;
-
 
278
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
-
 
279
			$nn = $_GET['num_nom'];
-
 
280
		} else if (isset($this->configProjet['sp_imposee'])) {
-
 
281
			$nn = $this->configProjet['sp_imposee'];
-
 
282
		}
269
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != '');
283
		return $nn;
Line 270... Line 284...
270
	}
284
	}
271
 
285
 
272
	private function executerChargementInfosTaxon($num_nom) {
286
	private function executerChargementInfosTaxon($num_nom) {