Subversion Repositories eFlore/Applications.cel

Rev

Rev 3231 | Rev 3240 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3228 delphine 1
 <?php
3120 delphine 2
// declare(encoding='UTF-8');
3
/**
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
5
 * Encodage en entrée : utf8
6
 * Encodage en sortie : utf8
7
 *
8
 * Cas d'utilisation et documentation :
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
10
 *
11
 * Paramètres :
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
16
 *
3228 delphine 17
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @license	GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license	CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @version	$Id$
21
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
3120 delphine 22
 */
23
class Saisie2 extends WidgetCommun {
3239 idir 24
 
3228 delphine 25
	const DS = DIRECTORY_SEPARATOR;
26
	const SERVICE_DEFAUT = 'saisie';
27
	const LANGUE_DEFAUT = 'fr';
28
	const PROJET_DEFAUT = 'base';
29
	const WS_NOM = 'noms';
30
	const EFLORE_API_VERSION = '0.1';
3239 idir 31
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
3228 delphine 32
	private $cel_url_tpl = null;
33
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
34
	private $bar;
35
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
36
	private $parametres_autorises = array(
37
			'projet' => 'projet',
38
			'type' => 'type',
39
			'langue' => 'langue',
40
			'order' => 'order'
41
	);
42
	/**
43
	 * Méthode appelée par défaut pour charger ce widget.
44
	 */
45
	public function executer() {
46
		$retour = null;
47
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
48
		unset($this->parametres['callback']);
49
		extract($this->parametres);
50
		$this->bar = (isset($bar)) ? $bar : false;
51
		/* Le fichier Framework.php du Framework de Tela Botanica doit être appelé avant tout autre chose dans l'application.
52
		 Sinon, rien ne sera chargé.
53
		 L'emplacement du Framework peut varier en fonction de l'environnement (test, prod...). Afin de faciliter la configuration
54
		 de l'emplacement du Framework, un fichier framework.defaut.php doit être renommé en framework.php et configuré pour chaque installation de
55
		 l'application.
56
		 Chemin du fichier chargeant le framework requis */
57
		$framework = dirname(__FILE__).'/framework.php';
58
		if (!file_exists($framework)) {
59
			$e = "Veuillez paramêtrer l'emplacement et la version du Framework dans le fichier $framework";
60
			trigger_error($e, E_USER_ERROR);
61
		} else {
62
			// Inclusion du Framework
63
			require_once $framework;
64
			// Ajout d'information concernant cette application
65
			Framework::setCheminAppli(__FILE__);// Obligatoire
66
			Framework::setInfoAppli(Config::get('info'));// Optionnel
3239 idir 67
 
3228 delphine 68
		}
69
		$langue = (isset($langue)) ? $langue : self::LANGUE_DEFAUT;
70
		$this->langue = I18n::setLangue($langue);
71
		$this->parametres['langue'] = $langue;
3120 delphine 72
 
3228 delphine 73
		if (!isset($mode)) {
74
			$mode = self::SERVICE_DEFAUT;
75
		}
76
		if (!isset($projet)) {
77
			$this->parametres['projet'] = self::PROJET_DEFAUT;
78
		}
3239 idir 79
 
3228 delphine 80
		$methode = $this->traiterNomMethodeExecuter($mode);
3239 idir 81
		if (method_exists($this, $methode)) {
82
			$retour = $this->$methode();
3228 delphine 83
		} else {
84
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
85
		}
3239 idir 86
 
3228 delphine 87
		$contenu = '';
88
		if (is_null($retour)) {
89
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
90
		} else {
3239 idir 91
			if (isset($retour['donnees'])) {
3228 delphine 92
				$retour['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
93
				$retour['donnees']['bar'] = $this->bar;
94
				$retour['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
95
				$retour['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
3239 idir 96
				$retour['donnees']['url_ws_upload'] = $widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
3228 delphine 97
				$retour['donnees']['authTpl'] = $this->config['manager']['authTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
98
				$retour['donnees']['mode'] = $mode;
99
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
100
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
101
			} else {
102
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
103
			}
104
		}
105
		$this->envoyer($contenu);
106
	}
3120 delphine 107
 
3239 idir 108
 
3228 delphine 109
	private function executerSaisie() {
110
		$retour = array();
111
		$retour['squelette'] = 'saisie';
112
		$retour['donnees']['observateur'] = I18n::get('Observateur');
3239 idir 113
        $retour['donnees']['observation'] = I18n::get('Observation');
114
        $retour['donnees']['image'] = I18n::get('Image');
115
        $retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
116
        $retour['donnees']['resume'] = I18n::get('Resume');
3228 delphine 117
		$retour['donnees']['widget'] = $this->rechercherProjet();
118
		return $retour;
119
	}
3239 idir 120
 
3228 delphine 121
	/* Recherche si le projet existe sinon va chercher les infos de base */
122
	private function rechercherProjet() {
123
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
3239 idir 124
		$estProjetDefini = true;
125
		$tab = array();
3228 delphine 126
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
3239 idir 127
		$json = $this->getDao()->consulter($url);
128
 
129
		if ( $json ) {
130
			$tab = $this->rechercherChampsSupp();
131
		} else {
132
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
133
			$json = $this->getDao()->consulter($url);
3228 delphine 134
			$estProjetDefini = false;
135
		}
3239 idir 136
		$tableau = json_decode($json, true);
3228 delphine 137
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
138
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
3239 idir 139
		if ($tableau['milieux'] != "") {
140
			$tableau['milieux'] = explode(";", $tableau['milieux']);
3228 delphine 141
		} else {
142
			$tableau['milieux'] = array();
143
		}
3239 idir 144
		$tableau['chpSupp'] = $tab;
145
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['dossierTmp'] . $tableau["projet"] . '/' );
3228 delphine 146
		return $tableau;
147
	}
3239 idir 148
 
3228 delphine 149
	/* Recherche si un projet a des champs de saisie supplémentaire */
150
	private function rechercherChampsSupp() {
151
		$retour = array();
3239 idir 152
		$projet = $this->parametres['projet'];
153
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
3228 delphine 154
		$json = $this->getDao()->consulter($url);
155
		$retour = (array) json_decode($json, true);
3239 idir 156
		$patterns = array( '/\@apos\@/' , '/\@quot\@/' );
157
		$replacements = array( '&apos;' , '&quot;' );
158
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
159
 
160
 
161
			$retour[$projet]['champs-supp'][$key]['name'] = preg_replace( $patterns, $replacements, $chsup['name'] );
162
			$retour[$projet]['champs-supp'][$key]['description'] = preg_replace( $patterns, $replacements, $chsup['description']);
163
			$retour[$projet]['champs-supp'][$key]['unit'] = preg_replace( $patterns, $replacements, $chsup['unit'] );
164
 
165
			if ( isset( $chsup['fieldValues'] ) ) {
166
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
167
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
168
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = preg_replace( $patterns, $replacements, $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
169
				}
170
 
171
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
172
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value ) {
173
						$list_value = preg_replace( $patterns, $replacements, $list_value );
174
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key] = $list_value;
3228 delphine 175
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
3239 idir 176
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = 'val-' . preg_replace('/[^A-Za-z0-9_\-]/', '', $this->remove_accents($list_value));
3228 delphine 177
					}
178
				}
179
			}
3239 idir 180
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
3228 delphine 181
		}
182
		return $retour;
183
	}
3239 idir 184
 
185
	private function remove_accents($string) {
186
		if ( !preg_match('/[\x80-\xff]/', $string) )
187
			return $string;
188
 
189
		$chars = array(
190
			// Decompositions for Latin-1 Supplement
191
			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
192
			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
193
			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
194
			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
195
			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
196
			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
197
			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
198
			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
199
			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
200
			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
201
			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
202
			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
203
			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
204
			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
205
			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
206
			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
207
			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
208
			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
209
			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
210
			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
211
			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
212
			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
213
			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
214
			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
215
			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
216
			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
217
			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
218
			chr(195).chr(191) => 'y',
219
			// Decompositions for Latin Extended-A
220
			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
221
			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
222
			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
223
			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
224
			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
225
			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
226
			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
227
			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
228
			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
229
			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
230
			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
231
			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
232
			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
233
			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
234
			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
235
			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
236
			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
237
			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
238
			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
239
			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
240
			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
241
			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
242
			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
243
			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
244
			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
245
			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
246
			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
247
			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
248
			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
249
			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
250
			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
251
			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
252
			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
253
			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
254
			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
255
			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
256
			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
257
			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
258
			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
259
			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
260
			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
261
			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
262
			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
263
			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
264
			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
265
			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
266
			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
267
			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
268
			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
269
			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
270
			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
271
			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
272
			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
273
			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
274
			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
275
			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
276
			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
277
			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
278
			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
279
			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
280
			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
281
			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
282
			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
283
			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
284
		);
285
 
286
		$string = strtr($string, $chars);
287
 
288
		return $string;
289
	}
290
 
3228 delphine 291
	// remplace certains parametres définis en bd par les parametres définis dans l'url
292
	private function traiterParametres($estProjetDefini, $tableau) {
293
		$criteres = array('tag', 'motcle', 'projet', 'titre', 'logo');
294
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
295
		foreach($this->parametres as $nom_critere => $valeur_critere) {
296
			if (($estProjetDefini == false || $tableau['projet'] == "base") && in_array($nom_critere, $criteresProjetNonDefini)) {
297
				$tableau[$nom_critere] = $valeur_critere;
298
			} else if (in_array($nom_critere, $criteres)) {
299
				$tableau[$nom_critere] = $valeur_critere;
300
			}
301
		}
302
		return $tableau;
303
	}
3239 idir 304
 
305
 
306
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
307
		$retour = array();
308
		$referentiel = $infos_projets['referentiel'];
3228 delphine 309
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
3239 idir 310
		$urlWsNs = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );
311
		$urlWsNsSansRef = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
3228 delphine 312
		$retour['url_ws_autocompletion_ns'] = $urlWsNs;
313
		$retour['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
314
		$retour['ns_referentiel'] = $referentiel;
3239 idir 315
 
316
		if ( isset( $infos_projets['type_especes'] ) ) {
317
 
318
			switch ( $infos_projets['type_especes'] ) {
319
				case "fixe" :
320
					$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
3228 delphine 321
					break;
3239 idir 322
				case "referentiel" :
323
				case "liste" :
324
					$referentiel = $infos_projets['referentiel'];
325
					break;
3228 delphine 326
			}
3239 idir 327
		} else if ( isset( $infos_projets['referentiel'] ) ) {
3228 delphine 328
			$referentiel = $infos_projets['referentiel'];
3239 idir 329
			if ( isset($infos_projets['num_nom'] ) ) {
330
				$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
3228 delphine 331
			}
332
		}
3239 idir 333
 
334
		$projetsAListeDeNoms = $this->transformerEnTableau( $this->config['projets']['liste_noms'] ) ;
335
		if ( in_array( $this->projet, $projetsAListeDeNoms ) && !$this->especeEstImposee() ) {
336
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau( $this->config['projets']['liste_noms_sci_et_verna'] );
337
			if ( in_array( $this->projet, $projetsAListeDeNomsSciEtVerna ) ) {
3228 delphine 338
				$retour['taxons'] = $this->recupererListeNoms();
339
			} else {
340
				$retour['taxons'] = $this->recupererListeNomsSci();
341
			}
342
		}
343
		return $retour;
344
	}
3239 idir 345
 
3228 delphine 346
	/**
347
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
348
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
349
	 * et non le taxon?)
350
	 * @param string|int $num_nom
351
	 * @return array
352
	 */
3239 idir 353
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
354
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
355
		$infos = json_decode( file_get_contents( $url_service_infos ) );
3228 delphine 356
		// trop de champs injectés dans les infos espèces peuvent
357
		// faire planter javascript
3239 idir 358
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet',
359
				'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
3228 delphine 360
		$resultat = array();
361
		$retour = array();
3239 idir 362
		if ( isset( $infos ) && !empty( $infos ) ) {
363
			$infos = (array) $infos;
364
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] != '' ) {
365
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
366
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? "true" : "false";
3228 delphine 367
				$retour['espece_imposee'] = true;
368
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
369
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
3239 idir 370
				$retour['infos_espece'] = $this->array2js( $resultat, true );
3228 delphine 371
			}
372
		}
373
		return $retour;
374
	}
3120 delphine 375
 
3239 idir 376
	protected function getReferentielImpose() {
377
		$referentiel_impose = true;
378
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
379
			$this->ns_referentiel = $_GET['referentiel'];
380
		} else if (isset($this->configProjet['referentiel'])) {
381
			$this->ns_referentiel = $this->configProjet['referentiel'];
382
		} else if (isset($this->configMission['referentiel'])) {
383
			$this->ns_referentiel = $this->configMission['referentiel'];
384
		} else {
385
			$referentiel_impose = false;
386
		}
387
		return $referentiel_impose;
388
	}
3231 delphine 389
 
3228 delphine 390
	/**
391
	 * Trie par nom français les taxons lus dans le fichier tsv
392
	 */
393
	protected function recupererListeNomsSci() {
394
		$taxons = $this->recupererListeTaxon();
395
		if (is_array($taxons)) {
396
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
397
		}
398
		return $taxons;
399
	}
3239 idir 400
 
3228 delphine 401
	/**
402
	 * @TODO documenter
403
	 * @return array
404
	 */
405
	protected function recupererListeNoms() {
406
		$taxons = $this->recupererListeTaxon();
407
		$nomsAAfficher = array();
408
		$nomsSpeciaux = array();
409
		if (is_array($taxons)) {
410
			foreach ($taxons as $taxon) {
411
				$nomSciTitle = $taxon['nom_ret'].
412
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
413
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
414
				$nomFrTitle = $taxon['nom_sel'].
415
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
416
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
3239 idir 417
 
3228 delphine 418
				if ($taxon['groupe'] == 'special') {
419
					$nomsSpeciaux[] = array(
420
							'num_nom' => $taxon['num_nom_sel'],
421
							'nom_a_afficher' => $taxon['nom_fr'],
422
							'nom_a_sauver' => $taxon['nom_sel'],
423
							'nom_title' => $nomSciTitle,
424
							'nom_type' => 'nom-special');
425
				} else {
426
					$nomsAAfficher[] = array(
427
							'num_nom' => $taxon['num_nom_sel'],
428
							'nom_a_afficher' => $taxon['nom_sel'],
429
							'nom_a_sauver' => $taxon['nom_sel'],
430
							'nom_title' => $nomSciTitle,
431
							'nom_type' => 'nom-sci');
432
					$nomsAAfficher[] = array(
433
							'num_nom' => $taxon['num_nom_sel'],
434
							'nom_a_afficher' => $taxon['nom_fr'],
435
							'nom_a_sauver' => $taxon['nom_fr'],
436
							'nom_title' => $nomFrTitle,
437
							'nom_type' => 'nom-fr');
438
				}
439
			}
440
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
441
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
442
		}
443
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
444
	}
3239 idir 445
 
3228 delphine 446
	/**
447
	 * Lit une liste de taxons depuis un fichier tsv fourni
448
	 */
449
	protected function recupererListeTaxon() {
450
		$taxons = array();
451
		if ($this->projet == 'missions-flore') {
452
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_'.$this->mission.'_taxons.tsv';
453
		} else {
454
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
455
		}
456
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
457
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
458
		} else {
459
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
460
		}
461
		return $taxons;
462
	}
3239 idir 463
 
3228 delphine 464
	/**
465
	 * Découpe un fihcier tsv
466
	 */
467
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
468
		$header = null;
469
		$data = array();
470
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
471
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
472
				if (!$header) {
473
					$header = $row;
474
				} else {
475
					$data[] = array_combine($header, $row);
476
				}
477
			}
478
			fclose($handle);
479
		}
480
		return $data;
481
	}
3239 idir 482
 
3228 delphine 483
	/**
484
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
485
	 * @param array $array
486
	 * @param boolean $show_keys
487
	 * @return une portion de JSON représentant le tableau
488
	 */
489
	protected function array2js($array,$show_keys) {
490
		$tableauJs = '{}';
491
		if (!empty($array)) {
492
			$total = count($array) - 1;
493
			$i = 0;
494
			$dimensions = array();
495
			foreach ($array as $key => $value) {
496
				if (is_array($value)) {
497
					$dimensions[$i] = array2js($value,$show_keys);
498
					if ($show_keys) {
499
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
500
					}
501
				} else {
502
					$dimensions[$i] = '"'.addslashes($value).'"';
503
					if ($show_keys) {
504
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
505
					}
506
				}
507
				if ($i == 0) {
508
					$dimensions[$i] = '{'.$dimensions[$i];
509
				}
510
				if ($i == $total) {
511
					$dimensions[$i].= '}';
512
				}
513
				$i++;
514
			}
515
			$tableauJs = implode(',', $dimensions);
516
		}
517
		return $tableauJs;
518
	}
3120 delphine 519
 
520
}
3239 idir 521
?>