Subversion Repositories eFlore/Applications.cel

Rev

Rev 3857 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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