Subversion Repositories eFlore/Applications.cel

Rev

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

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