Subversion Repositories eFlore/Applications.cel

Rev

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

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