Subversion Repositories eFlore/Applications.cel

Rev

Rev 3198 | Rev 3662 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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