Subversion Repositories eFlore/Applications.cel

Rev

Rev 3278 | Rev 3330 | 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';
3240 idir 27
	const WS_SAISIE = 'CelWidgetSaisie';
28
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
29
	const WS_OBS = 'CelObs';
3228 delphine 30
	const LANGUE_DEFAUT = 'fr';
31
	const PROJET_DEFAUT = 'base';
32
	const WS_NOM = 'noms';
33
	const EFLORE_API_VERSION = '0.1';
34
	private $cel_url_tpl = null;
35
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
36
	private $bar;
37
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
38
	private $parametres_autorises = array(
39
			'projet' => 'projet',
40
			'type' => 'type',
41
			'langue' => 'langue',
42
			'order' => 'order'
43
	);
44
	/**
45
	 * Méthode appelée par défaut pour charger ce widget.
46
	 */
47
	public function executer() {
48
		$retour = null;
49
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
50
		unset($this->parametres['callback']);
51
		extract($this->parametres);
52
		$this->bar = (isset($bar)) ? $bar : false;
53
		/* Le fichier Framework.php du Framework de Tela Botanica doit être appelé avant tout autre chose dans l'application.
54
		 Sinon, rien ne sera chargé.
55
		 L'emplacement du Framework peut varier en fonction de l'environnement (test, prod...). Afin de faciliter la configuration
56
		 de l'emplacement du Framework, un fichier framework.defaut.php doit être renommé en framework.php et configuré pour chaque installation de
57
		 l'application.
58
		 Chemin du fichier chargeant le framework requis */
59
		$framework = dirname(__FILE__).'/framework.php';
60
		if (!file_exists($framework)) {
61
			$e = "Veuillez paramêtrer l'emplacement et la version du Framework dans le fichier $framework";
62
			trigger_error($e, E_USER_ERROR);
63
		} else {
64
			// Inclusion du Framework
65
			require_once $framework;
66
			// Ajout d'information concernant cette application
67
			Framework::setCheminAppli(__FILE__);// Obligatoire
68
			Framework::setInfoAppli(Config::get('info'));// Optionnel
3239 idir 69
 
3228 delphine 70
		}
71
		$langue = (isset($langue)) ? $langue : self::LANGUE_DEFAUT;
72
		$this->langue = I18n::setLangue($langue);
73
		$this->parametres['langue'] = $langue;
3120 delphine 74
 
3228 delphine 75
		if (!isset($mode)) {
76
			$mode = self::SERVICE_DEFAUT;
77
		}
78
		if (!isset($projet)) {
79
			$this->parametres['projet'] = self::PROJET_DEFAUT;
80
		}
3239 idir 81
 
3228 delphine 82
		$methode = $this->traiterNomMethodeExecuter($mode);
3239 idir 83
		if (method_exists($this, $methode)) {
84
			$retour = $this->$methode();
3228 delphine 85
		} else {
86
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
87
		}
3239 idir 88
 
3257 delphine 89
		$contenu = ''; //print_r($retour);exit;
3228 delphine 90
		if (is_null($retour)) {
91
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
92
		} else {
3239 idir 93
			if (isset($retour['donnees'])) {
3271 idir 94
				// ne pas afficher le projet dans l'url si on est dans saisie de base
3286 idir 95
				$projet_dans_url = ( $this->parametres['projet'] !== 'base') ? '?'. $this->parametres['projet'].'&'.'langue='.$this->parametres['langue'] : '';
3271 idir 96
 
3260 idir 97
				$retour['donnees']['conf_mode'] = $this->config['parametres']['modeServeur'];
3249 idir 98
				$retour['donnees']['prod'] = ($this->config['parametres']['modeServeur'] === 'prod');
3228 delphine 99
				$retour['donnees']['bar'] = $this->bar;
3268 idir 100
				$retour['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['cheminDos']);
3228 delphine 101
				$retour['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
3240 idir 102
				$retour['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
103
				$retour['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
104
				$retour['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
3286 idir 105
				$retour['donnees']['authTpl'] = $this->config['manager']['authTpl']. $projet_dans_url;
3228 delphine 106
				$retour['donnees']['mode'] = $mode;
3260 idir 107
				if( isset( $this->parametres['squelette'] ) ) {
108
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS. $this->parametres['squelette'].'.tpl.html';
109
				} else {
110
					$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
111
				}
3228 delphine 112
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
113
			} else {
114
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
115
			}
116
		}
117
		$this->envoyer($contenu);
118
	}
3120 delphine 119
 
3239 idir 120
 
3228 delphine 121
	private function executerSaisie() {
122
		$retour = array();
123
		$retour['squelette'] = 'saisie';
3248 idir 124
		$retour['donnees']['general'] = I18n::get('General');
125
		$retour['donnees']['aide'] = I18n::get('Aide');
3228 delphine 126
		$retour['donnees']['observateur'] = I18n::get('Observateur');
3248 idir 127
		$retour['donnees']['observation'] = I18n::get('Observation');
128
		$retour['donnees']['image'] = I18n::get('Image');
129
 		$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
130
 		$retour['donnees']['resume'] = I18n::get('Resume');
3228 delphine 131
		$retour['donnees']['widget'] = $this->rechercherProjet();
132
		return $retour;
133
	}
3239 idir 134
 
3228 delphine 135
	/* Recherche si le projet existe sinon va chercher les infos de base */
136
	private function rechercherProjet() {
137
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
3239 idir 138
		$estProjetDefini = true;
139
		$tab = array();
3228 delphine 140
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
3239 idir 141
		$json = $this->getDao()->consulter($url);
142
 
3257 delphine 143
		if ( $json !== "[]" ) {
3239 idir 144
			$tab = $this->rechercherChampsSupp();
145
		} else {
146
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
147
			$json = $this->getDao()->consulter($url);
3228 delphine 148
			$estProjetDefini = false;
149
		}
3239 idir 150
		$tableau = json_decode($json, true);
3228 delphine 151
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
152
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
3249 idir 153
		if ($tableau['milieux'] != '') {
154
			$tableau['milieux'] = explode(';', $tableau['milieux']);
3228 delphine 155
		} else {
156
			$tableau['milieux'] = array();
157
		}
3278 delphine 158
		if (isset($tableau['motscles'])) {
159
		    $tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
160
		}
3239 idir 161
		$tableau['chpSupp'] = $tab;
3240 idir 162
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
3249 idir 163
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['dossierTmp'] . $tableau['projet'] . $langue_projet_url . '/' );
3228 delphine 164
		return $tableau;
165
	}
3239 idir 166
 
3228 delphine 167
	/* Recherche si un projet a des champs de saisie supplémentaire */
168
	private function rechercherChampsSupp() {
169
		$retour = array();
3239 idir 170
		$projet = $this->parametres['projet'];
171
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
3228 delphine 172
		$json = $this->getDao()->consulter($url);
173
		$retour = (array) json_decode($json, true);
3249 idir 174
 
3239 idir 175
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
176
 
177
 
3249 idir 178
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
179
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
180
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
3239 idir 181
 
182
			if ( isset( $chsup['fieldValues'] ) ) {
183
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
184
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
3249 idir 185
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = $this->clean_string( $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
3239 idir 186
				}
187
 
188
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
189
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value ) {
3249 idir 190
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key] = $this->clean_string( $list_value );
3228 delphine 191
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
3249 idir 192
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( $list_value ) );
3228 delphine 193
					}
194
				}
195
			}
3239 idir 196
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
3228 delphine 197
		}
198
		return $retour;
199
	}
3239 idir 200
 
3249 idir 201
	private function clean_string( $string ) {
202
		// les fonctions de base de php ne parviennent pas à une conversion satisfaisante des codes ascii
203
		// qui ont été générés automatiquement lors de la transmission des chaines en json
204
		// dans le widget cel manager vers la base
205
		// Pour les mêmes raisons, @apos@ et @quot@ est une autre astuces utilisée dans ce même widget
206
		// pour permettre la transmission des apostrophes et guillements sans erreur
207
		$patterns = array( '/\@apos\@/', '/\@quot\@/', '/u00c0/', '/u00c1/', '/u00c2/', '/u00c3/', '/u00c4/', '/u00c5/', '/u00c6/', '/u00c7/', '/u00c8/', '/u00c9/', '/u00ca/', '/u00cb/', '/u00cc/', '/u00cd/', '/u00ce/', '/u00cf/', '/u00d1/', '/u00d2/', '/u00d3/', '/u00d4/', '/u00d5/', '/u00d6/', '/u00d8/', '/u00d9/', '/u00da/', '/u00db/', '/u00dc/', '/u00dd/', '/u00df/', '/u00e0/', '/u00e1/', '/u00e2/', '/u00e3/', '/u00e4/', '/u00e5/', '/u00e6/', '/u00e7/', '/u00e8/', '/u00e9/', '/u00ea/', '/u00eb/', '/u00ec/', '/u00ed/', '/u00ee/', '/u00ef/', '/u00f0/', '/u00f1/', '/u00f2/', '/u00f3/', '/u00f4/', '/u00f5/', '/u00f6/', '/u00f8/', '/u00f9/', '/u00fa/', '/u00fb/', '/u00fc/', '/u00fd/', '/u00ff/' );
208
		$replacements = array( '&apos;', '&quot;', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý','ÿ' );
209
 
210
		$clean_string = preg_replace( $patterns, $replacements, $string );
211
 
212
		return $clean_string;
213
	}
214
 
3239 idir 215
 
216
 
3228 delphine 217
	// remplace certains parametres définis en bd par les parametres définis dans l'url
218
	private function traiterParametres($estProjetDefini, $tableau) {
3278 delphine 219
		$criteres = array('tag-obs', 'tag-img', 'projet', 'titre', 'logo');
3228 delphine 220
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
221
		foreach($this->parametres as $nom_critere => $valeur_critere) {
3249 idir 222
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
3228 delphine 223
				$tableau[$nom_critere] = $valeur_critere;
224
			} else if (in_array($nom_critere, $criteres)) {
225
				$tableau[$nom_critere] = $valeur_critere;
226
			}
227
		}
228
		return $tableau;
229
	}
3239 idir 230
 
231
 
232
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
233
		$retour = array();
234
		$referentiel = $infos_projets['referentiel'];
3228 delphine 235
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
3260 idir 236
		$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
237
		$retour['url_ws_autocompletion_ns_tpl'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
3228 delphine 238
		$retour['ns_referentiel'] = $referentiel;
3239 idir 239
 
240
		if ( isset( $infos_projets['type_especes'] ) ) {
241
 
242
			switch ( $infos_projets['type_especes'] ) {
3249 idir 243
				case 'fixe' :
3257 delphine 244
					$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
3228 delphine 245
					break;
3257 delphine 246
				case 'referentiel' : break;
3249 idir 247
				case 'liste' :
3239 idir 248
					$referentiel = $infos_projets['referentiel'];
3256 idir 249
////////////////////// temporaire test transmission liste taxons
250
					$retour['taxons'] = $this->recupererListeNomsSci();
3239 idir 251
					break;
3228 delphine 252
			}
3239 idir 253
		} else if ( isset( $infos_projets['referentiel'] ) ) {
3228 delphine 254
			$referentiel = $infos_projets['referentiel'];
3239 idir 255
			if ( isset($infos_projets['num_nom'] ) ) {
3257 delphine 256
				$retour = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
3228 delphine 257
			}
258
		}
259
		return $retour;
260
	}
3239 idir 261
 
3228 delphine 262
	/**
263
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
264
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
265
	 * et non le taxon?)
266
	 * @param string|int $num_nom
267
	 * @return array
268
	 */
3239 idir 269
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
270
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
271
		$infos = json_decode( file_get_contents( $url_service_infos ) );
3228 delphine 272
		// trop de champs injectés dans les infos espèces peuvent
273
		// faire planter javascript
3239 idir 274
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet',
275
				'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
3228 delphine 276
		$resultat = array();
277
		$retour = array();
3239 idir 278
		if ( isset( $infos ) && !empty( $infos ) ) {
279
			$infos = (array) $infos;
3249 idir 280
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
3239 idir 281
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
3249 idir 282
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
3228 delphine 283
				$retour['espece_imposee'] = true;
284
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
285
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
3239 idir 286
				$retour['infos_espece'] = $this->array2js( $resultat, true );
3228 delphine 287
			}
288
		}
289
		return $retour;
290
	}
3120 delphine 291
 
3239 idir 292
	protected function getReferentielImpose() {
293
		$referentiel_impose = true;
3249 idir 294
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
3239 idir 295
			$this->ns_referentiel = $_GET['referentiel'];
296
		} else if (isset($this->configProjet['referentiel'])) {
297
			$this->ns_referentiel = $this->configProjet['referentiel'];
298
		} else if (isset($this->configMission['referentiel'])) {
299
			$this->ns_referentiel = $this->configMission['referentiel'];
300
		} else {
301
			$referentiel_impose = false;
302
		}
303
		return $referentiel_impose;
304
	}
3231 delphine 305
 
3228 delphine 306
	/**
3256 idir 307
	 * Trie par nom français les taxons lus dans le fichier csv
3228 delphine 308
	 */
309
	protected function recupererListeNomsSci() {
310
		$taxons = $this->recupererListeTaxon();
311
		if (is_array($taxons)) {
312
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
313
		}
314
		return $taxons;
315
	}
3239 idir 316
 
3228 delphine 317
	/**
318
	 * @TODO documenter
319
	 * @return array
320
	 */
321
	protected function recupererListeNoms() {
322
		$taxons = $this->recupererListeTaxon();
323
		$nomsAAfficher = array();
324
		$nomsSpeciaux = array();
325
		if (is_array($taxons)) {
326
			foreach ($taxons as $taxon) {
327
				$nomSciTitle = $taxon['nom_ret'].
328
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
329
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
330
				$nomFrTitle = $taxon['nom_sel'].
331
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
332
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
3239 idir 333
 
3228 delphine 334
				if ($taxon['groupe'] == 'special') {
335
					$nomsSpeciaux[] = array(
336
							'num_nom' => $taxon['num_nom_sel'],
337
							'nom_a_afficher' => $taxon['nom_fr'],
338
							'nom_a_sauver' => $taxon['nom_sel'],
339
							'nom_title' => $nomSciTitle,
340
							'nom_type' => 'nom-special');
341
				} else {
342
					$nomsAAfficher[] = array(
343
							'num_nom' => $taxon['num_nom_sel'],
344
							'nom_a_afficher' => $taxon['nom_sel'],
345
							'nom_a_sauver' => $taxon['nom_sel'],
346
							'nom_title' => $nomSciTitle,
347
							'nom_type' => 'nom-sci');
348
					$nomsAAfficher[] = array(
349
							'num_nom' => $taxon['num_nom_sel'],
350
							'nom_a_afficher' => $taxon['nom_fr'],
351
							'nom_a_sauver' => $taxon['nom_fr'],
352
							'nom_title' => $nomFrTitle,
353
							'nom_type' => 'nom-fr');
354
				}
355
			}
356
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
357
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
358
		}
359
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
360
	}
3239 idir 361
 
3228 delphine 362
	/**
3256 idir 363
	 * Lit une liste de taxons depuis un fichier csv fourni
3228 delphine 364
	 */
365
	protected function recupererListeTaxon() {
366
		$taxons = array();
3256 idir 367
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
368
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
3260 idir 369
		$fichier_csv = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . 'especes.csv';
3257 delphine 370
 
3256 idir 371
		if ( file_exists( $fichier_csv ) && is_readable( $fichier_csv ) ) {
372
			$taxons = $this->decomposerFichierCsv( $fichier_csv );
3228 delphine 373
		} else {
3256 idir 374
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_csv'.";
3228 delphine 375
		}
376
		return $taxons;
377
	}
3239 idir 378
 
3228 delphine 379
	/**
3256 idir 380
	 * Découpe un fihcier csv
3228 delphine 381
	 */
3256 idir 382
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
3228 delphine 383
		$header = null;
384
		$data = array();
3256 idir 385
		if (($handle = fopen($fichier, "r")) !== FALSE) {
3228 delphine 386
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
387
				if (!$header) {
388
					$header = $row;
389
				} else {
390
					$data[] = array_combine($header, $row);
391
				}
392
			}
393
			fclose($handle);
394
		}
395
		return $data;
396
	}
3239 idir 397
 
3228 delphine 398
	/**
399
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
400
	 * @param array $array
401
	 * @param boolean $show_keys
402
	 * @return une portion de JSON représentant le tableau
403
	 */
404
	protected function array2js($array,$show_keys) {
405
		$tableauJs = '{}';
406
		if (!empty($array)) {
407
			$total = count($array) - 1;
408
			$i = 0;
409
			$dimensions = array();
410
			foreach ($array as $key => $value) {
411
				if (is_array($value)) {
412
					$dimensions[$i] = array2js($value,$show_keys);
413
					if ($show_keys) {
3260 idir 414
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
3228 delphine 415
					}
416
				} else {
3260 idir 417
					$dimensions[$i] = '\"'.addslashes($value).'\"';
3228 delphine 418
					if ($show_keys) {
3260 idir 419
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
3228 delphine 420
					}
421
				}
422
				if ($i == 0) {
423
					$dimensions[$i] = '{'.$dimensions[$i];
424
				}
425
				if ($i == $total) {
426
					$dimensions[$i].= '}';
427
				}
428
				$i++;
429
			}
430
			$tableauJs = implode(',', $dimensions);
431
		}
432
		return $tableauJs;
433
	}
3120 delphine 434
 
3257 delphine 435
	private function remove_accents($string) {
436
	    if ( !preg_match('/[\x80-\xff]/', $string) )
437
	        return $string;
3260 idir 438
 
3257 delphine 439
	        $chars = array(
440
	            // Decompositions for Latin-1 Supplement
441
	            chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
442
	            chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
443
	            chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
444
	            chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
445
	            chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
446
	            chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
447
	            chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
448
	            chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
449
	            chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
450
	            chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
451
	            chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
452
	            chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
453
	            chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
454
	            chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
455
	            chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
456
	            chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
457
	            chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
458
	            chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
459
	            chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
460
	            chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
461
	            chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
462
	            chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
463
	            chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
464
	            chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
465
	            chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
466
	            chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
467
	            chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
468
	            chr(195).chr(191) => 'y',
469
	            // Decompositions for Latin Extended-A
470
	            chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
471
	            chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
472
	            chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
473
	            chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
474
	            chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
475
	            chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
476
	            chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
477
	            chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
478
	            chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
479
	            chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
480
	            chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
481
	            chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
482
	            chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
483
	            chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
484
	            chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
485
	            chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
486
	            chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
487
	            chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
488
	            chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
489
	            chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
490
	            chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
491
	            chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
492
	            chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
493
	            chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
494
	            chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
495
	            chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
496
	            chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
497
	            chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
498
	            chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
499
	            chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
500
	            chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
501
	            chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
502
	            chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
503
	            chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
504
	            chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
505
	            chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
506
	            chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
507
	            chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
508
	            chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
509
	            chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
510
	            chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
511
	            chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
512
	            chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
513
	            chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
514
	            chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
515
	            chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
516
	            chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
517
	            chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
518
	            chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
519
	            chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
520
	            chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
521
	            chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
522
	            chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
523
	            chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
524
	            chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
525
	            chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
526
	            chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
527
	            chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
528
	            chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
529
	            chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
530
	            chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
531
	            chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
532
	            chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
533
	            chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
534
	        );
535
 
536
	        $string = strtr($string, $chars);
537
 
538
	        return $string;
539
	}
3120 delphine 540
}
3239 idir 541
?>