| 712 | jpm | 1 | <?php
 | 
        
           |  |  | 2 | // declare(encoding='UTF-8');
 | 
        
           |  |  | 3 | /**
 | 
        
           |  |  | 4 |  * Widget fournissant des interfaces de saisies simplifiée pour différent projets.
 | 
        
           |  |  | 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=AideCELWidgetSaisie
 | 
        
           |  |  | 10 |  *
 | 
        
           |  |  | 11 |  * Paramètres :
 | 
        
           |  |  | 12 |  * ===> projet = chaine  [par défaut : Biodiversite34]
 | 
        
           |  |  | 13 |  * Indique quel projet nous voulons charger
 | 
        
           |  |  | 14 |  *
 | 
        
           |  |  | 15 |  * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
 | 
        
           |  |  | 16 |  * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 | 
        
           |  |  | 17 |  * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 | 
        
           |  |  | 18 |  * @version		$Id$
 | 
        
           |  |  | 19 |  * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
 | 
        
           |  |  | 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 | 	private $NS_PROJET_VERSION = '1.01';
 | 
        
           |  |  | 30 | 	const EFLORE_API_VERSION = '0.1';
 | 
        
           |  |  | 31 | 	private $NS_PROJET = 'bdtfx';
 | 
        
           | 1050 | jpm | 32 |   | 
        
           | 1476 | aurelien | 33 | 	private $projetsVersions = array();
 | 
        
           | 719 | jpm | 34 | 	private $projet = null;
 | 
        
           |  |  | 35 | 	private $configProjet = null;
 | 
        
           | 1050 | jpm | 36 |   | 
        
           | 712 | jpm | 37 | 	/**
 | 
        
           |  |  | 38 | 	 * Méthode appelée par défaut pour charger ce widget.
 | 
        
           |  |  | 39 | 	 */
 | 
        
           |  |  | 40 | 	public function executer() {
 | 
        
           |  |  | 41 | 		$retour = null;
 | 
        
           |  |  | 42 | 		extract($this->parametres);
 | 
        
           |  |  | 43 |   | 
        
           | 1345 | aurelien | 44 | 		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
 | 
        
           | 719 | jpm | 45 | 		$this->chargerConfigProjet();
 | 
        
           | 1476 | aurelien | 46 | 		$this->chargerProjetsVersion();
 | 
        
           | 1050 | jpm | 47 |   | 
        
           | 1345 | aurelien | 48 | 		$service = isset($service) ? $service : 'widget';
 | 
        
           | 719 | jpm | 49 | 		$methode = $this->traiterNomMethodeExecuter($service);
 | 
        
           | 712 | jpm | 50 | 		if (method_exists($this, $methode)) {
 | 
        
           |  |  | 51 | 			$retour = $this->$methode();
 | 
        
           |  |  | 52 | 		} else {
 | 
        
           |  |  | 53 | 			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
 | 
        
           |  |  | 54 | 		}
 | 
        
           |  |  | 55 |   | 
        
           | 1050 | jpm | 56 | 		$contenu = null;
 | 
        
           |  |  | 57 | 		$mime = null;
 | 
        
           |  |  | 58 | 		if (is_array($retour) && array_key_exists('squelette', $retour)) {
 | 
        
           | 719 | jpm | 59 | 			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
 | 
        
           | 1475 | aurelien | 60 | 			if($this->projetASquelette()) {
 | 
        
           |  |  | 61 | 				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
 | 
        
           |  |  | 62 | 			} else {
 | 
        
           |  |  | 63 | 				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
 | 
        
           |  |  | 64 | 			}
 | 
        
           | 712 | jpm | 65 | 			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
 | 
        
           | 1050 | jpm | 66 | 			$mime = isset($retour['mime']) ? $retour['mime'] : null;
 | 
        
           |  |  | 67 | 		} else {
 | 
        
           |  |  | 68 | 			if (count($this->messages) == 0) {
 | 
        
           |  |  | 69 | 				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format.";
 | 
        
           |  |  | 70 | 			}
 | 
        
           |  |  | 71 | 			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
 | 
        
           | 712 | jpm | 72 | 		}
 | 
        
           | 1050 | jpm | 73 |   | 
        
           |  |  | 74 | 		$this->envoyer($contenu, $mime);
 | 
        
           | 712 | jpm | 75 | 	}
 | 
        
           | 1050 | jpm | 76 |   | 
        
           | 719 | jpm | 77 | 	private function chargerConfigProjet() {
 | 
        
           |  |  | 78 | 		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
 | 
        
           |  |  | 79 | 		if (file_exists($fichier_config)) {
 | 
        
           | 1526 | jpm | 80 | 			if (!$this->configProjet = parse_ini_file($fichier_config)) {
 | 
        
           | 719 | jpm | 81 | 				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
 | 
        
           | 1050 | jpm | 82 | 			}
 | 
        
           | 719 | jpm | 83 | 		} else {
 | 
        
           | 1345 | aurelien | 84 | 			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
 | 
        
           | 719 | jpm | 85 | 		}
 | 
        
           |  |  | 86 | 	}
 | 
        
           | 1526 | jpm | 87 |   | 
        
           | 1476 | aurelien | 88 | 	private function chargerProjetsVersion() {
 | 
        
           | 1526 | jpm | 89 | 		if (isset($this->configProjet)) {
 | 
        
           |  |  | 90 | 			foreach ($this->configProjet as $config => $valeur) {
 | 
        
           |  |  | 91 | 				if(strstr($config,'.version')) {
 | 
        
           |  |  | 92 | 					$this->projetsVersions[str_replace('.version', '', $config)] = $valeur;
 | 
        
           |  |  | 93 | 				}
 | 
        
           | 1476 | aurelien | 94 | 			}
 | 
        
           |  |  | 95 | 		}
 | 
        
           |  |  | 96 | 	}
 | 
        
           | 1050 | jpm | 97 |   | 
        
           | 1345 | aurelien | 98 | 	public function executerWidget() {
 | 
        
           | 1476 | aurelien | 99 | 		$referentiel_impose = false;
 | 
        
           | 1526 | jpm | 100 | 		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '') {
 | 
        
           | 1476 | aurelien | 101 | 			$this->NS_PROJET = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->NS_PROJET;
 | 
        
           |  |  | 102 | 			$this->NS_PROJET_VERSION = $this->projetsVersions[$this->NS_PROJET];
 | 
        
           |  |  | 103 | 			$referentiel_impose = true;
 | 
        
           |  |  | 104 | 		}
 | 
        
           | 1526 | jpm | 105 |   | 
        
           | 1050 | jpm | 106 | 		$widget['squelette'] = $this->projet;
 | 
        
           |  |  | 107 | 		$widget['donnees'] = array();
 | 
        
           |  |  | 108 | 		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
 | 
        
           |  |  | 109 | 		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
 | 
        
           | 1580 | jpm | 110 | 		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
 | 
        
           | 1888 | mathias | 111 | 		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
 | 
        
           | 1536 | jpm | 112 | 		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
 | 
        
           | 1526 | jpm | 113 |   | 
        
           | 1536 | jpm | 114 |   | 
        
           | 1516 | aurelien | 115 | 		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
 | 
        
           |  |  | 116 | 		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
 | 
        
           |  |  | 117 | 		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
 | 
        
           | 1526 | jpm | 118 |   | 
        
           | 1475 | aurelien | 119 | 		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
 | 
        
           | 1916 | jpm | 120 | 		if ($this->projet == 'defaut' || $this->projet == 'florileges' || $this->projet == 'sauvages' || !$this->projetASquelette()) {
 | 
        
           | 1345 | aurelien | 121 | 			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
 | 
        
           | 1476 | aurelien | 122 | 			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
 | 
        
           |  |  | 123 | 			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
 | 
        
           | 1345 | aurelien | 124 | 			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
 | 
        
           | 1476 | aurelien | 125 | 			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
 | 
        
           |  |  | 126 | 			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
 | 
        
           |  |  | 127 | 			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
 | 
        
           |  |  | 128 | 			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
 | 
        
           |  |  | 129 | 			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
 | 
        
           |  |  | 130 | 			$widget['donnees']['projets_versions'] = $this->projetsVersions;
 | 
        
           | 1526 | jpm | 131 | 			$widget['donnees']['espece_imposee'] = false;
 | 
        
           |  |  | 132 | 			$widget['donnees']['nn_espece_defaut'] = '';
 | 
        
           |  |  | 133 | 			$widget['donnees']['nom_sci_espece_defaut'] = '';
 | 
        
           | 1536 | jpm | 134 | 			$widget['donnees']['infos_espece'] = '{}';
 | 
        
           | 1526 | jpm | 135 |   | 
        
           |  |  | 136 | 			if ($this->especeEstImposee()) {
 | 
        
           |  |  | 137 | 				$nom = $this->executerChargementInfosTaxon($_GET['num_nom']);
 | 
        
           | 1418 | aurelien | 138 | 				$widget['donnees']['espece_imposee'] = true;
 | 
        
           |  |  | 139 | 				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
 | 
        
           | 1419 | aurelien | 140 | 				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
 | 
        
           |  |  | 141 | 				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
 | 
        
           | 1418 | aurelien | 142 | 			}
 | 
        
           | 1536 | jpm | 143 | 		}
 | 
        
           |  |  | 144 | 		if ($this->projet != 'defaut' || $this->projetASquelette()) {
 | 
        
           | 1946 | jpm | 145 | 			if ($this->projet == 'florileges' || $this->projet == 'sauvages') {
 | 
        
           | 1613 | jpm | 146 | 				$widget['donnees']['taxons'] = $this->recupererListeNoms();
 | 
        
           |  |  | 147 | 			} else {
 | 
        
           |  |  | 148 | 				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
 | 
        
           |  |  | 149 | 			}
 | 
        
           | 1345 | aurelien | 150 | 			$widget['donnees']['milieux'] = $this->parserMilieux();
 | 
        
           | 719 | jpm | 151 | 		}
 | 
        
           | 1345 | aurelien | 152 | 		return  $widget;
 | 
        
           | 719 | jpm | 153 | 	}
 | 
        
           | 1526 | jpm | 154 |   | 
        
           | 1475 | aurelien | 155 | 	private function projetASquelette() {
 | 
        
           | 1526 | jpm | 156 | 		// fonction très simple qui ne teste que si le dossier du projet courant
 | 
        
           | 1475 | aurelien | 157 | 		// existe, mais elle suffit pour le moment.
 | 
        
           |  |  | 158 | 		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
 | 
        
           |  |  | 159 | 	}
 | 
        
           | 1050 | jpm | 160 |   | 
        
           | 1345 | aurelien | 161 | 	public function executerTaxons() {
 | 
        
           |  |  | 162 | 		$widget['squelette'] = $this->projet.'_taxons';
 | 
        
           |  |  | 163 | 		$widget['squelette_ext'] = '.tpl.js';
 | 
        
           | 1613 | jpm | 164 | 		$widget['donnees'] = array();
 | 
        
           | 1629 | jpm | 165 | 		$nomsAAfficher = $this->recupererListeNomsSci();
 | 
        
           |  |  | 166 | 		$taxons_tries = array();
 | 
        
           | 1691 | raphael | 167 | 		foreach ($nomsAAfficher as $taxon) {
 | 
        
           | 1629 | jpm | 168 | 			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
 | 
        
           |  |  | 169 | 		}
 | 
        
           |  |  | 170 | 		$widget['donnees']['taxons'] = json_encode($taxons_tries);
 | 
        
           |  |  | 171 | 		return $widget;
 | 
        
           | 1345 | aurelien | 172 | 	}
 | 
        
           | 1613 | jpm | 173 |   | 
        
           |  |  | 174 | 	private function recupererListeNomsSci() {
 | 
        
           |  |  | 175 | 		$taxons = $this->recupererListeTaxon();
 | 
        
           |  |  | 176 | 		if (is_array($taxons)) {
 | 
        
           |  |  | 177 | 			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
 | 
        
           |  |  | 178 | 		}
 | 
        
           | 1629 | jpm | 179 | 		return $taxons;
 | 
        
           | 1613 | jpm | 180 | 	}
 | 
        
           |  |  | 181 |   | 
        
           |  |  | 182 | 	private function recupererListeNoms() {
 | 
        
           |  |  | 183 | 		$taxons = $this->recupererListeTaxon();
 | 
        
           |  |  | 184 | 		$nomsAAfficher = array();
 | 
        
           |  |  | 185 | 		$nomsSpeciaux = array();
 | 
        
           |  |  | 186 | 		if (is_array($taxons)) {
 | 
        
           |  |  | 187 | 			foreach ($taxons as $taxon) {
 | 
        
           |  |  | 188 | 				$nomSciTitle = $taxon['nom_ret'].
 | 
        
           |  |  | 189 | 					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
 | 
        
           |  |  | 190 | 					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
 | 
        
           |  |  | 191 | 				$nomFrTitle = $taxon['nom_sel'].
 | 
        
           |  |  | 192 | 					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
 | 
        
           |  |  | 193 | 					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
 | 
        
           |  |  | 194 |   | 
        
           |  |  | 195 | 				if ($taxon['groupe'] == 'special') {
 | 
        
           |  |  | 196 | 					$nomsSpeciaux[] = array(
 | 
        
           |  |  | 197 | 						'num_nom' => $taxon['num_nom_sel'],
 | 
        
           |  |  | 198 | 						'nom_a_afficher' => $taxon['nom_fr'],
 | 
        
           |  |  | 199 | 						'nom_a_sauver' => $taxon['nom_sel'],
 | 
        
           |  |  | 200 | 						'nom_title' => $nomSciTitle,
 | 
        
           |  |  | 201 | 						'nom_type' => 'nom-special');
 | 
        
           |  |  | 202 | 				} else {
 | 
        
           |  |  | 203 | 					$nomsAAfficher[] = array(
 | 
        
           |  |  | 204 | 						'num_nom' => $taxon['num_nom_sel'],
 | 
        
           |  |  | 205 | 						'nom_a_afficher' => $taxon['nom_sel'],
 | 
        
           |  |  | 206 | 						'nom_a_sauver' => $taxon['nom_sel'],
 | 
        
           |  |  | 207 | 						'nom_title' => $nomSciTitle,
 | 
        
           |  |  | 208 | 						'nom_type' => 'nom-sci');
 | 
        
           |  |  | 209 | 					$nomsAAfficher[] = array(
 | 
        
           |  |  | 210 | 						'num_nom' => $taxon['num_nom_sel'],
 | 
        
           |  |  | 211 | 						'nom_a_afficher' => $taxon['nom_fr'],
 | 
        
           |  |  | 212 | 						'nom_a_sauver' => $taxon['nom_fr'],
 | 
        
           |  |  | 213 | 						'nom_title' => $nomFrTitle,
 | 
        
           |  |  | 214 | 						'nom_type' => 'nom-fr');
 | 
        
           |  |  | 215 | 				}
 | 
        
           |  |  | 216 | 			}
 | 
        
           |  |  | 217 | 			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
 | 
        
           |  |  | 218 | 			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
 | 
        
           |  |  | 219 | 		}
 | 
        
           |  |  | 220 | 		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
 | 
        
           |  |  | 221 | 	}
 | 
        
           | 1345 | aurelien | 222 |   | 
        
           |  |  | 223 | 	private function recupererListeTaxon() {
 | 
        
           |  |  | 224 | 		$taxons = null;
 | 
        
           |  |  | 225 | 		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
 | 
        
           |  |  | 226 | 		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
 | 
        
           | 712 | jpm | 227 | 			$taxons = $this->decomposerFichierTsv($fichier_tsv);
 | 
        
           | 1345 | aurelien | 228 | 		} else {
 | 
        
           |  |  | 229 | 			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
 | 
        
           |  |  | 230 | 		}
 | 
        
           |  |  | 231 | 		return $taxons;
 | 
        
           |  |  | 232 | 	}
 | 
        
           |  |  | 233 |   | 
        
           |  |  | 234 | 	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
 | 
        
           | 1536 | jpm | 235 | 		$header = null;
 | 
        
           | 1345 | aurelien | 236 | 		$data = array();
 | 
        
           |  |  | 237 | 		if (($handle = fopen($fichier, 'r')) !== FALSE) {
 | 
        
           |  |  | 238 | 			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
 | 
        
           |  |  | 239 | 				if (!$header) {
 | 
        
           |  |  | 240 | 					$header = $row;
 | 
        
           |  |  | 241 | 				} else {
 | 
        
           |  |  | 242 | 					$data[] = array_combine($header, $row);
 | 
        
           |  |  | 243 | 				}
 | 
        
           |  |  | 244 | 			}
 | 
        
           |  |  | 245 | 			fclose($handle);
 | 
        
           |  |  | 246 | 		}
 | 
        
           |  |  | 247 | 		return $data;
 | 
        
           | 712 | jpm | 248 | 	}
 | 
        
           | 1050 | jpm | 249 |   | 
        
           | 1345 | aurelien | 250 | 	private function parserMilieux() {
 | 
        
           | 1050 | jpm | 251 | 		$infosMilieux = array();
 | 
        
           | 1536 | jpm | 252 | 		if (isset($this->configProjet['milieux'])) {
 | 
        
           |  |  | 253 | 			$milieux = explode('|', $this->configProjet['milieux']);
 | 
        
           |  |  | 254 | 			foreach ($milieux as $milieu) {
 | 
        
           |  |  | 255 | 				$details = explode(';', $milieu);
 | 
        
           |  |  | 256 | 				if (isset($details[1])) {
 | 
        
           |  |  | 257 | 					$infosMilieux[$details[0]] = $details[1];
 | 
        
           |  |  | 258 | 				} else {
 | 
        
           |  |  | 259 | 					$infosMilieux[$details[0]] = '';
 | 
        
           |  |  | 260 | 				}
 | 
        
           | 1050 | jpm | 261 | 			}
 | 
        
           | 1536 | jpm | 262 | 			ksort($infosMilieux);
 | 
        
           | 1050 | jpm | 263 | 		}
 | 
        
           |  |  | 264 | 		return $infosMilieux;
 | 
        
           |  |  | 265 | 	}
 | 
        
           | 1526 | jpm | 266 |   | 
        
           | 1418 | aurelien | 267 | 	private function especeEstImposee() {
 | 
        
           | 1536 | jpm | 268 | 		return (isset($_GET['num_nom']) && $_GET['num_nom'] != '');
 | 
        
           | 1418 | aurelien | 269 | 	}
 | 
        
           | 1526 | jpm | 270 |   | 
        
           | 1418 | aurelien | 271 | 	private function executerChargementInfosTaxon($num_nom) {
 | 
        
           | 1476 | aurelien | 272 | 		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
 | 
        
           | 1418 | aurelien | 273 | 		$infos = json_decode(file_get_contents($url_service_infos));
 | 
        
           | 1909 | raphael | 274 | 		// trop de champs injectés dans les infos espèces peut
 | 
        
           |  |  | 275 | 		// faire planter javascript
 | 
        
           | 1916 | jpm | 276 | 		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
 | 
        
           | 1909 | raphael | 277 | 		'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
 | 
        
           | 1419 | aurelien | 278 | 		$resultat = array();
 | 
        
           | 1539 | jpm | 279 | 		if (isset($infos) && !empty($infos)) {
 | 
        
           | 1419 | aurelien | 280 | 			$infos = (array)$infos;
 | 
        
           | 1909 | raphael | 281 | 			if(isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
 | 
        
           |  |  | 282 | 				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
 | 
        
           |  |  | 283 | 				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
 | 
        
           | 1916 | jpm | 284 | 			}
 | 
        
           | 1419 | aurelien | 285 | 		}
 | 
        
           | 1418 | aurelien | 286 | 		return $resultat;
 | 
        
           |  |  | 287 | 	}
 | 
        
           | 1050 | jpm | 288 |   | 
        
           | 1526 | jpm | 289 | 	private function array2js($array,$show_keys) {
 | 
        
           | 1536 | jpm | 290 | 		$tableauJs = '{}';
 | 
        
           |  |  | 291 | 		if (!empty($array)) {
 | 
        
           |  |  | 292 | 			$total = count($array) - 1;
 | 
        
           |  |  | 293 | 			$i = 0;
 | 
        
           |  |  | 294 | 			$dimensions = array();
 | 
        
           |  |  | 295 | 			foreach ($array as $key => $value) {
 | 
        
           |  |  | 296 | 				if (is_array($value)) {
 | 
        
           |  |  | 297 | 					$dimensions[$i] = array2js($value,$show_keys);
 | 
        
           |  |  | 298 | 					if ($show_keys) {
 | 
        
           |  |  | 299 | 						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
 | 
        
           |  |  | 300 | 					}
 | 
        
           |  |  | 301 | 				} else {
 | 
        
           |  |  | 302 | 					$dimensions[$i] = '"'.addslashes($value).'"';
 | 
        
           |  |  | 303 | 					if ($show_keys) {
 | 
        
           |  |  | 304 | 						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
 | 
        
           |  |  | 305 | 					}
 | 
        
           | 1526 | jpm | 306 | 				}
 | 
        
           | 1536 | jpm | 307 | 				if ($i == 0) {
 | 
        
           |  |  | 308 | 					$dimensions[$i] = '{'.$dimensions[$i];
 | 
        
           | 1526 | jpm | 309 | 				}
 | 
        
           | 1536 | jpm | 310 | 				if ($i == $total) {
 | 
        
           |  |  | 311 | 					$dimensions[$i].= '}';
 | 
        
           |  |  | 312 | 				}
 | 
        
           |  |  | 313 | 				$i++;
 | 
        
           | 1526 | jpm | 314 | 			}
 | 
        
           | 1536 | jpm | 315 | 			$tableauJs = implode(',', $dimensions);
 | 
        
           | 1526 | jpm | 316 | 		}
 | 
        
           | 1536 | jpm | 317 | 		return $tableauJs;
 | 
        
           | 1526 | jpm | 318 | 	}
 | 
        
           | 1345 | aurelien | 319 | }
 | 
        
           |  |  | 320 | ?>
 |