Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
712 jpm 1
<?php
2
/**
2688 mathias 3
 * Widget fournissant des interfaces de saisie simplifiée pour différent projets
712 jpm 4
 *
5
 * Cas d'utilisation et documentation :
2688 mathias 6
 * @link http://www.tela-botanica.org/wikini/AideCarnetEnLigne/wakka.php?wiki=AideCELWidgetSaisie
712 jpm 7
 *
8
 * Paramètres :
2688 mathias 9
 * - projet [par défaut : defaut] : indique le mot-clé à associer aux obs saisies; si un widget de saisie personnalisé
10
 * 		portant ce nom existe, il sera chargé
11
 * - mission [par défaut : vide] : permet de charger un "sous-widget", dans le cas où un widget personnalisé
12
 * 		est associé au projet, et ce widget accepte des sous-widgets (ex: "missions-flore")
712 jpm 13
 *
2408 jpm 14
 * @author Mathias CHOUET <mathias@tela-botanica.org>
15
 * @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @author Aurelien PERONNET <aurelien@tela-botanica.org>
17
 * @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
2688 mathias 19
 * @copyright 1999-2015 Tela Botanica <accueil@tela-botanica.org>
712 jpm 20
 */
21
class Saisie extends WidgetCommun {
1050 jpm 22
 
712 jpm 23
	const DS = DIRECTORY_SEPARATOR;
1345 aurelien 24
	const PROJET_DEFAUT = 'defaut';
1580 jpm 25
	const WS_SAISIE = 'CelWidgetSaisie';
1888 mathias 26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
1580 jpm 27
	const WS_OBS = 'CelObs';
28
	const WS_NOM = 'noms';
29
	const EFLORE_API_VERSION = '0.1';
2929 delphine 30
	const REFERENTIEL_DEFAUT = 'bdtfxr';
1050 jpm 31
 
2906 aurel 32
	/** référentiel utilisé pour la complétion des noms scientifiques */
2688 mathias 33
	protected $ns_referentiel;
34
	/** mot-clé associé aux saisies, et template personnalisé si appliquable */
35
	protected $projet = null;
36
	protected $configProjet = null;
37
	protected $configMission = null;
2805 mathias 38
	protected $mission = null;
2786 mathias 39
	/** langue (traduction), charge un template de la forme "defaut_en.tpl.html" */
40
	protected $langue = null;
1050 jpm 41
 
712 jpm 42
	/**
2688 mathias 43
	 * Amorçage du widget
712 jpm 44
	 */
45
	public function executer() {
2688 mathias 46
		// paramètres par défaut
47
		$this->ns_referentiel = self::REFERENTIEL_DEFAUT;
48
		$this->projet = self::PROJET_DEFAUT;
712 jpm 49
 
2688 mathias 50
		// définition du projet / mission
51
		if (isset($this->parametres['projet']) && trim($this->parametres['projet']) != "") {
52
			$projets = explode(',', $this->parametres['projet']);
2577 aurelien 53
			$this->projet = strtolower($projets[0]);
2500 mathias 54
		}
719 jpm 55
		$this->chargerConfigProjet();
1050 jpm 56
 
2688 mathias 57
		// exécution du service (le widget entier ou une sous-partie, par ex "Taxons")
58
		$retour = null;
59
		$service = isset($this->parametres['service']) ? $this->parametres['service'] : 'widget';
719 jpm 60
		$methode = $this->traiterNomMethodeExecuter($service);
712 jpm 61
		if (method_exists($this, $methode)) {
62
			$retour = $this->$methode();
63
		} else {
2688 mathias 64
			$this->messages[] = "Le service '$methode' n'est pas disponible.";
712 jpm 65
		}
66
 
2786 mathias 67
		// définition de la langue, en mode souple
68
		if (isset($this->parametres['lang'])) {
69
			$this->langue = $this->parametres['lang'];
70
		}
71
 
2688 mathias 72
		// injection des données dans le squelette
1050 jpm 73
		$contenu = null;
74
		$mime = null;
75
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
719 jpm 76
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
2786 mathias 77
			// Suffixe de template pour la langue - fr par défaut @TODO configurer ça un jour
78
			$suffixeLangue = "";
79
			if ($this->langue != null && $this->langue != "fr") {
80
				$suffixeLangue = "_" . $this->langue;
81
			}
82
			// Template par défaut ou spécifique
2406 jpm 83
			if ($this->projetASquelette()) {
2786 mathias 84
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$suffixeLangue.$ext;
1475 aurelien 85
			} else {
2786 mathias 86
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$suffixeLangue.$ext;
1475 aurelien 87
			}
712 jpm 88
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
1050 jpm 89
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
90
		} else {
91
			if (count($this->messages) == 0) {
2688 mathias 92
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format";
1050 jpm 93
			}
2688 mathias 94
			$contenu = 'Un problème est survenu : ' . print_r($this->messages, true);
712 jpm 95
		}
1050 jpm 96
 
2688 mathias 97
		// envoi de la page
1050 jpm 98
		$this->envoyer($contenu, $mime);
712 jpm 99
	}
1050 jpm 100
 
2688 mathias 101
	/**
102
	 * Charge le fichier de configuration associé au projet : configurations/nomduprojet.ini
103
	 * Si une mission est définie, charge séparément la section de la configuration concernant
104
	 * cette mission : [nommission]
105
	 */
106
	protected function chargerConfigProjet() {
719 jpm 107
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
108
		if (file_exists($fichier_config)) {
2408 jpm 109
			if ($this->configProjet = parse_ini_file($fichier_config, true)) {
110
				if (isset($_GET['mission'])) {
2805 mathias 111
					$this->mission = strtolower(trim($_GET['mission']));
112
					if (isset($this->configProjet[$this->mission])) {
113
						$this->configMission = $this->configProjet[$this->mission];
2408 jpm 114
					}
2688 mathias 115
				}
2408 jpm 116
			} else {
2688 mathias 117
				$this->messages[] = "Le fichier de configuration '$fichier_config' n'a pu être chargé.";
1050 jpm 118
			}
719 jpm 119
		} else {
2688 mathias 120
			$this->debug[] = "Le fichier de configuration '$fichier_config' n'existe pas.";
719 jpm 121
		}
122
	}
1526 jpm 123
 
2688 mathias 124
	/**
125
	 * Retourne true si le dossier du projet courant existe, false sinon
126
	 * @return boolean
127
	 */
128
	protected function projetASquelette() {
2408 jpm 129
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
1476 aurelien 130
	}
1050 jpm 131
 
2688 mathias 132
	/**
133
	 * Exécution du widget complet
134
	 * @return Ambigous <string, unknown, multitype:string unknown >
135
	 */
1345 aurelien 136
	public function executerWidget() {
1050 jpm 137
		$widget['squelette'] = $this->projet;
138
		$widget['donnees'] = array();
139
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
140
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
1580 jpm 141
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
1888 mathias 142
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
1536 jpm 143
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
2082 mathias 144
		$widget['donnees']['url_remarques'] = $this->config['chemins']['widgetRemarquesUrl'];
1526 jpm 145
 
2851 mathias 146
		$widget['donnees']['logo'] = $this->getLogoPage();
2408 jpm 147
		$widget['donnees']['titre'] = $this->getTitrePage();
2805 mathias 148
		$widget['donnees']['nom_mission'] = $this->getNomMissionFlore();
1526 jpm 149
 
2906 aurel 150
		$widget['donnees']['zone_geo'] = $this->getZoneGeo();
2916 mathias 151
		$widget['donnees']['groupe_zones_geo'] = $this->getGroupeZonesGeo();
2851 mathias 152
		$widget['donnees']['referentiel_impose'] = $this->getReferentielImpose();
153
		$widget['donnees']['espece_imposee'] = false;
154
		$widget['donnees']['nn_espece_defaut'] = '';
155
		$widget['donnees']['nom_sci_espece_defaut'] = '';
2498 aurelien 156
		$widget['donnees']['infos_espece'] = '{}';
2848 mathias 157
 
158
		$widget['donnees']['prod'] = ($this->config['parametres']['modeServeur'] == "prod");
3037 mathias 159
 
160
		$widget['donnees']['cleGoogleMaps'] = $this->config['api']['cleGoogleMaps'];
2498 aurelien 161
 
2406 jpm 162
		$projetsAutorises = $this->transformerEnTableau($this->config['projets']['autorises']);
1526 jpm 163
 
2851 mathias 164
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
165
		$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->ns_referentiel, self::WS_NOM);
166
		$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
167
		$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
168
		$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
2498 aurelien 169
		$widget['donnees']['ns_referentiel'] = $this->ns_referentiel;
2744 aurelien 170
 
2916 mathias 171
		$widget['donnees']['url_ws_coord_search_tpl'] = $this->config['chemins']['serviceCoordSearchUrl'];
2744 aurelien 172
		$widget['donnees']['url_ws_trace_rue_tpl'] = $this->config['chemins']['serviceTraceRueUrl'];
2851 mathias 173
 
174
		if ($this->especeEstImposee()) {
175
			$nnEspeceImposee = $this->getNnEspeceImposee();
176
			$nom = $this->chargerInfosTaxon($nnEspeceImposee);
177
			$widget['donnees']['espece_imposee'] = true;
178
			$widget['donnees']['nn_espece_defaut'] = $nnEspeceImposee;
179
			$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_complet'];
180
			$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
1536 jpm 181
		}
2406 jpm 182
 
183
		$projetsAListeDeNoms = $this->transformerEnTableau($this->config['projets']['liste_noms']);
3017 delphine 184
		if (in_array($this->projet, $projetsAListeDeNoms) && !$this->especeEstImposee()) {
2406 jpm 185
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau($this->config['projets']['liste_noms_sci_et_verna']);
186
			if (in_array($this->projet, $projetsAListeDeNomsSciEtVerna)) {
1613 jpm 187
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
188
			} else {
189
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
2328 jpm 190
			}
2406 jpm 191
		}
192
 
193
		// Chargement de la liste des milieux issues du fichier .ini du projet
194
		$projetsAListeDeMilieux = $this->transformerEnTableau($this->config['projets']['liste_milieux']);
195
		if (in_array($this->projet, $projetsAListeDeMilieux)) {
1345 aurelien 196
			$widget['donnees']['milieux'] = $this->parserMilieux();
719 jpm 197
		}
2406 jpm 198
 
199
		return $widget;
719 jpm 200
	}
1526 jpm 201
 
2688 mathias 202
	protected function getTitrePage() {
2408 jpm 203
		$titre = 'defaut';
204
		if (isset($this->configProjet['titre_page'])) {
205
			$titre = $this->configProjet['titre_page'];
206
		}
207
		if (isset($this->configMission['titre_page'])) {
208
			$titre = $this->configMission['titre_page'];
209
		}
210
		if (isset($_GET['titre'])) {
211
			$titre = $_GET['titre'];
212
		}
2851 mathias 213
		if ($titre === 0) { // wtf ?
2408 jpm 214
			$titre = '';
215
		}
216
		return $titre;
1475 aurelien 217
	}
1050 jpm 218
 
2851 mathias 219
	protected function getLogoPage() {
220
		$logo = 'defaut';
221
		if (isset($this->configProjet['logo_page'])) {
222
			$logo = $this->configProjet['logo_page'];
223
		}
224
		if (isset($this->configMission['logo_page'])) {
225
			$logo = $this->configMission['logo_page'];
226
		}
227
		if (isset($_GET['logo'])) {
228
			$logo = $_GET['logo'];
229
		}
230
		return $logo;
231
	}
2916 mathias 232
 
233
	protected function getGroupeZonesGeo() {
234
		$groupe = null;
235
		if (isset($_GET['groupe_zones_geo'])) {
236
			$groupe = $_GET['groupe_zones_geo'];
237
		}
238
		return $groupe;
239
	}
240
 
2906 aurel 241
	protected function getZoneGeo() {
242
		$zone_geo = null;
243
		if (isset($_GET['zone_geo'])) {
244
			$zone_geo = $_GET['zone_geo'];
245
		}
246
		return $zone_geo;
247
	}
2851 mathias 248
 
249
	protected function getReferentielImpose() {
2869 mathias 250
		$referentiel_impose = true;
2851 mathias 251
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] != "autre") {
252
			$this->ns_referentiel = $_GET['referentiel'];
2869 mathias 253
		} else if (isset($this->configProjet['referentiel'])) {
254
			$this->ns_referentiel = $this->configProjet['referentiel'];
255
		} else if (isset($this->configMission['referentiel'])) {
256
			$this->ns_referentiel = $this->configMission['referentiel'];
257
		} else {
258
			$referentiel_impose = false;
2851 mathias 259
		}
260
		return $referentiel_impose;
261
	}
262
 
2688 mathias 263
	/**
2805 mathias 264
	 * Un nom un peu plus sympatoche à afficher que juste le mot-clef associé; s'il
265
	 * n'est pas défini dans la config, on prend le mot-clef tout de même
266
	 */
267
	protected function getNomMissionFlore() {
268
		$nom = $this->mission;
269
		if (isset($this->configMission['nom_mission'])) {
270
			$nom = $this->configMission['nom_mission'];
271
		}
272
		return $nom;
273
	}
274
 
275
	/**
2688 mathias 276
	 * Remplit un fichier JS avec une variable contenant une liste restreinte de taxons,
277
	 * pour certains projets
278
	 * @return string
279
	 */
2328 jpm 280
	public function executerTaxons() {
281
		$widget['squelette'] = $this->projet.'_taxons';
282
		$widget['squelette_ext'] = '.tpl.js';
1613 jpm 283
		$widget['donnees'] = array();
1629 jpm 284
		$nomsAAfficher = $this->recupererListeNomsSci();
285
		$taxons_tries = array();
1691 raphael 286
		foreach ($nomsAAfficher as $taxon) {
1629 jpm 287
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
2328 jpm 288
		}
289
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
290
		return $widget;
291
	}
1613 jpm 292
 
2688 mathias 293
	/**
294
	 * Trie par nom français les taxons lus dans le fichier tsv
295
	 */
296
	protected function recupererListeNomsSci() {
1613 jpm 297
		$taxons = $this->recupererListeTaxon();
298
		if (is_array($taxons)) {
299
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
300
		}
1629 jpm 301
		return $taxons;
1613 jpm 302
	}
303
 
2688 mathias 304
	/**
305
	 * @TODO documenter
306
	 * @return array
307
	 */
308
	protected function recupererListeNoms() {
1613 jpm 309
		$taxons = $this->recupererListeTaxon();
310
		$nomsAAfficher = array();
311
		$nomsSpeciaux = array();
312
		if (is_array($taxons)) {
313
			foreach ($taxons as $taxon) {
314
				$nomSciTitle = $taxon['nom_ret'].
315
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
316
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
317
				$nomFrTitle = $taxon['nom_sel'].
318
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
319
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
320
 
321
				if ($taxon['groupe'] == 'special') {
322
					$nomsSpeciaux[] = array(
323
						'num_nom' => $taxon['num_nom_sel'],
324
						'nom_a_afficher' => $taxon['nom_fr'],
325
						'nom_a_sauver' => $taxon['nom_sel'],
326
						'nom_title' => $nomSciTitle,
327
						'nom_type' => 'nom-special');
328
				} else {
329
					$nomsAAfficher[] = array(
330
						'num_nom' => $taxon['num_nom_sel'],
331
						'nom_a_afficher' => $taxon['nom_sel'],
332
						'nom_a_sauver' => $taxon['nom_sel'],
333
						'nom_title' => $nomSciTitle,
334
						'nom_type' => 'nom-sci');
335
					$nomsAAfficher[] = array(
336
						'num_nom' => $taxon['num_nom_sel'],
337
						'nom_a_afficher' => $taxon['nom_fr'],
338
						'nom_a_sauver' => $taxon['nom_fr'],
339
						'nom_title' => $nomFrTitle,
340
						'nom_type' => 'nom-fr');
341
				}
342
			}
343
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
344
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
345
		}
346
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
347
	}
2328 jpm 348
 
2688 mathias 349
	/**
350
	 * Lit une liste de taxons depuis un fichier tsv fourni
351
	 */
352
	protected function recupererListeTaxon() {
353
		$taxons = array();
3017 delphine 354
		if ($this->projet == 'missions-flore') {
355
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_'.$this->mission.'_taxons.tsv';
356
		} else {
357
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
358
		}
2328 jpm 359
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
712 jpm 360
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
2328 jpm 361
		} else {
362
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
363
		}
364
		return $taxons;
712 jpm 365
	}
1050 jpm 366
 
2688 mathias 367
	/**
368
	 * Découpe un fihcier tsv
369
	 */
370
	protected function decomposerFichierTsv($fichier, $delimiter = "\t"){
2328 jpm 371
		$header = null;
372
		$data = array();
373
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
374
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
375
				if (!$header) {
376
					$header = $row;
377
				} else {
378
					$data[] = array_combine($header, $row);
379
				}
380
			}
381
			fclose($handle);
382
		}
383
		return $data;
384
	}
385
 
2688 mathias 386
	/**
387
	 * Récupère la liste des milieux depuis la section [milieux] de la configuration
388
	 * du projet, si elle existe
389
	 * @return array
390
	 */
391
	protected function parserMilieux() {
1050 jpm 392
		$infosMilieux = array();
1536 jpm 393
		if (isset($this->configProjet['milieux'])) {
394
			$milieux = explode('|', $this->configProjet['milieux']);
395
			foreach ($milieux as $milieu) {
2328 jpm 396
				$milieu = trim($milieu);
1536 jpm 397
				$details = explode(';', $milieu);
398
				if (isset($details[1])) {
399
					$infosMilieux[$details[0]] = $details[1];
400
				} else {
401
					$infosMilieux[$details[0]] = '';
402
				}
1050 jpm 403
			}
1536 jpm 404
			ksort($infosMilieux);
1050 jpm 405
		}
406
		return $infosMilieux;
407
	}
1526 jpm 408
 
2688 mathias 409
	/**
410
	 * Retourne true si le widget est restreint à une espèce, false sinon
411
	 * @return boolean
412
	 */
413
	protected function especeEstImposee() {
414
		return ((isset($_GET['num_nom']) && $_GET['num_nom'] != '')
2408 jpm 415
			|| isset($this->configProjet['sp_imposee']) || isset($this->configMission['sp_imposee']));
1418 aurelien 416
	}
1526 jpm 417
 
2688 mathias 418
	/**
419
	 * Retourne le numéro nomenclatural (nn) de l'espèce imposée si tel est
420
	 * le cas, null sinon
421
	 * @return string
422
	 */
423
	protected function getNnEspeceImposee() {
2328 jpm 424
		$nn = null;
425
		if (isset($_GET['num_nom']) && is_numeric($_GET['num_nom'])) {
426
			$nn = $_GET['num_nom'];
427
		} else if (isset($this->configProjet['sp_imposee'])) {
428
			$nn = $this->configProjet['sp_imposee'];
2408 jpm 429
		} else if (isset($this->configMission['sp_imposee'])) {
430
			$nn = $this->configMission['sp_imposee'];
2328 jpm 431
		}
432
		return $nn;
433
	}
434
 
2688 mathias 435
	/**
436
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
437
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
438
	 * et non le taxon?)
439
	 * @param string|int $num_nom
440
	 * @return array
441
	 */
442
	protected function chargerInfosTaxon($num_nom) {
2408 jpm 443
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->ns_referentiel, $num_nom);
1418 aurelien 444
		$infos = json_decode(file_get_contents($url_service_infos));
2688 mathias 445
		// trop de champs injectés dans les infos espèces peuvent
1909 raphael 446
		// faire planter javascript
2801 mathias 447
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 'nom_complet',
2839 mathias 448
			'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique');
1419 aurelien 449
		$resultat = array();
1539 jpm 450
		if (isset($infos) && !empty($infos)) {
1419 aurelien 451
			$infos = (array)$infos;
2367 jpm 452
			if (isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
1909 raphael 453
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
454
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
1916 jpm 455
			}
1419 aurelien 456
		}
1418 aurelien 457
		return $resultat;
458
	}
1050 jpm 459
 
2688 mathias 460
	/**
461
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
462
	 * @param array $array
463
	 * @param boolean $show_keys
464
	 * @return une portion de JSON représentant le tableau
465
	 */
466
	protected function array2js($array,$show_keys) {
1536 jpm 467
		$tableauJs = '{}';
468
		if (!empty($array)) {
469
			$total = count($array) - 1;
470
			$i = 0;
471
			$dimensions = array();
472
			foreach ($array as $key => $value) {
473
				if (is_array($value)) {
474
					$dimensions[$i] = array2js($value,$show_keys);
475
					if ($show_keys) {
476
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
477
					}
478
				} else {
479
					$dimensions[$i] = '"'.addslashes($value).'"';
480
					if ($show_keys) {
481
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
482
					}
1526 jpm 483
				}
1536 jpm 484
				if ($i == 0) {
485
					$dimensions[$i] = '{'.$dimensions[$i];
1526 jpm 486
				}
1536 jpm 487
				if ($i == $total) {
488
					$dimensions[$i].= '}';
489
				}
490
				$i++;
1526 jpm 491
			}
1536 jpm 492
			$tableauJs = implode(',', $dimensions);
1526 jpm 493
		}
1536 jpm 494
		return $tableauJs;
1526 jpm 495
	}
2906 aurel 496
}