Subversion Repositories eFlore/Applications.cel

Rev

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

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