Subversion Repositories eFlore/Applications.cel

Rev

Rev 3425 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3425 Rev 3543
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 Saisie2 extends WidgetCommun {
23
class Saisie2 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') ? '?'. $this->parametres['projet'].'&'.'langue='.$this->parametres['langue'] : '';
100
				$projet_dans_url = ( $this->parametres['projet'] !== 'base') ? '?'. $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_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
106
				$retour['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
107
				$retour['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
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);
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);
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;
110
				$retour['donnees']['authTpl'] = $this->config['manager']['authTpl']. $projet_dans_url;
111
				$retour['donnees']['mode'] = $mode;
111
				$retour['donnees']['mode'] = $mode;
112
				$retour['donnees']['langue'] = $langue;
112
				$retour['donnees']['langue'] = $langue;
113
				$retour['donnees']['widgets_url'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'],'');
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);
114
				$retour['donnees']['url_ws_obs_list'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS_LIST);
115
				$retour['donnees']['url_ws_cel_imgs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_IMG_LIST) . '/liste-ids?obsId=';
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'] );
116
				$retour['donnees']['url_ws_cel_img_url'] = str_replace ( '%s.jpg', '{id}XS', $this->config['chemins']['celImgUrlTpl'] );
117
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
117
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$retour['squelette'].'.tpl.html';
118
				switch ( $retour['squelette'] ) {
118
				switch ( $retour['squelette'] ) {
119
					case 'apa':
119
					case 'apa':
120
						$retour['donnees']['squelette'] = $this->parametres['projet'];
120
						$retour['donnees']['squelette'] = $this->parametres['projet'];
121
						break;
121
						break;
122
					case 'apaforms':
122
					case 'apaforms':
123
						$retour['donnees']['squelette'] = $this->parametres['squelette'];
123
						$retour['donnees']['squelette'] = $this->parametres['squelette'];
124
						break;
124
						break;
125
					default:
125
					default:
126
						$retour['donnees']['squelette'] = $retour['squelette'];
126
						$retour['donnees']['squelette'] = $retour['squelette'];
127
						break;
127
						break;
128
				}
128
				}
129
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
129
				$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
130
			} else {
130
			} else {
131
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
131
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
132
			}
132
			}
133
		}
133
		}
134
		$this->envoyer($contenu);
134
		$this->envoyer($contenu);
135
	}
135
	}
136
 
136
 
137
 
137
 
138
	private function executerSaisie() {
138
	private function executerSaisie() {
139
		$retour = array();
139
		$retour = array();
140
		if (in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX) ) {
140
		if (in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX) ) {
141
			if (isset($this->parametres['squelette']) && in_array($this->parametres['squelette'], self::SQUELETTES_SPECIAUX) ) {
141
			if (isset($this->parametres['squelette']) && in_array($this->parametres['squelette'], self::SQUELETTES_SPECIAUX) ) {
142
				$retour['squelette'] = 'apaforms';
142
				$retour['squelette'] = 'apaforms';
143
			} else {
143
			} else {
144
				$retour['squelette'] = 'apa';
144
				$retour['squelette'] = 'apa';
145
			}
145
			}
146
		} else {
146
		} else {
147
			$retour['squelette'] = 'saisie';
147
			$retour['squelette'] = 'saisie';
148
			$retour['donnees']['general']     = I18n::get('General');
148
			$retour['donnees']['general']     = I18n::get('General');
149
			$retour['donnees']['aide']        = I18n::get('Aide');
149
			$retour['donnees']['aide']        = I18n::get('Aide');
150
			$retour['donnees']['observateur'] = I18n::get('Observateur');
150
			$retour['donnees']['observateur'] = I18n::get('Observateur');
151
			$retour['donnees']['observation'] = I18n::get('Observation');
151
			$retour['donnees']['observation'] = I18n::get('Observation');
152
			$retour['donnees']['image']       = I18n::get('Image');
152
			$retour['donnees']['image']       = I18n::get('Image');
153
	 		$retour['donnees']['chpsupp']     = I18n::get('Chpsupp');
153
	 		$retour['donnees']['chpsupp']     = I18n::get('Chpsupp');
154
	 		$retour['donnees']['resume']      = I18n::get('Resume');
154
	 		$retour['donnees']['resume']      = I18n::get('Resume');
155
		}
155
		}
156
		$retour['donnees']['widget'] = $this->rechercherProjet();
156
		$retour['donnees']['widget'] = $this->rechercherProjet();
157
		return $retour;
157
		return $retour;
158
	}
158
	}
159
 
159
 
160
	/* Recherche si le projet existe sinon va chercher les infos de base */
160
	/* Recherche si le projet existe sinon va chercher les infos de base */
161
	private function rechercherProjet() {
161
	private function rechercherProjet() {
162
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
162
		// projet avec un squelette défini (et non juste un mot-clé d'observation)
163
		$estProjetDefini = true;
163
		$estProjetDefini = true;
164
		$tab = array();
164
		$tab = array();
165
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
165
		$url = $this->config['manager']['celUrlTpl'].'?projet='.$this->parametres['projet'].'&langue='.$this->parametres['langue'];
166
		$json = $this->getDao()->consulter($url);
166
		$json = $this->getDao()->consulter($url);
167
		if (!in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX)){
167
		if (!in_array($this->parametres['projet'], self::WIDGETS_SPECIAUX)){
168
			if ( $json !== "[]") {
168
			if ( $json !== "[]") {
169
				$tab = $this->rechercherChampsSupp();
169
				$tab = $this->rechercherChampsSupp();
170
			} else {
170
			} else {
171
				$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
171
				$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
172
				$json = $this->getDao()->consulter($url);
172
				$json = $this->getDao()->consulter($url);
173
				$estProjetDefini = false;
173
				$estProjetDefini = false;
174
			}
174
			}
175
		}
175
		}
176
		$tableau = json_decode($json, true);
176
		$tableau = json_decode($json, true);
177
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
177
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
178
		if (
178
		if (
179
			isset($this->parametres['squelette']) &&
179
			isset($this->parametres['squelette']) &&
180
			($this->parametres['squelette'] === 'plantes' || $this->parametres['squelette'] === 'lichens')
180
			($this->parametres['squelette'] === 'plantes' || $this->parametres['squelette'] === 'lichens')
181
		) {
181
		) {
182
			$tableau['type_especes'] = 'liste';
182
			$tableau['type_especes'] = 'liste';
183
			if ( $this->parametres['squelette'] === 'lichens' ) {
183
			if ( $this->parametres['squelette'] === 'lichens' ) {
184
				$tableau['referentiel'] = 'taxref';
184
				$tableau['referentiel'] = 'taxref';
185
			}
185
			}
186
		}
186
		}
187
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
187
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
188
		if (isset($tableau['type_especes']) && 'fixe' === $tableau['type_especes']) {
188
		if (isset($tableau['type_especes']) && 'fixe' === $tableau['type_especes']) {
189
			// si on trouve ":" dans referentiel, referentiel = première partie
189
			// si on trouve ":" dans referentiel, referentiel = première partie
190
			$tableau['referentiel'] = (strstr($tableau['referentiel'],':',true)) ?: $tableau['referentiel'];
190
			$tableau['referentiel'] = (strstr($tableau['referentiel'],':',true)) ?: $tableau['referentiel'];
191
		}
191
		}
192
		$tableau['milieux'] = ($tableau['milieux'] != '') ? explode(';', $tableau['milieux']) : [];
192
		$tableau['milieux'] = ($tableau['milieux'] != '') ? explode(';', $tableau['milieux']) : [];
193
		if(!isset($this->parametres['id-obs'])) {
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'])) {
194
			if (isset($this->parametres['dept']) || isset($this->parametres['commune'],$this->parametres['dept']) || isset($this->parametres['code_insee'])) {
195
				$localisation = $this->traiterParamsLocalisation($this->parametres);
195
				$localisation = $this->traiterParamsLocalisation($this->parametres);
196
				// les paramètres dans l'url peuvent surcharger les données de localisation de la bdd
196
				// les paramètres dans l'url peuvent surcharger les données de localisation de la bdd
197
				if ($localisation) $tableau['localisation'] = $localisation;
197
				if ($localisation) $tableau['localisation'] = $localisation;
198
			}
198
			}
199
			if (isset($tableau['localisation'])) $tableau['localisation'] = $this->traiterLocalisation($tableau['localisation']);
199
			if (isset($tableau['localisation'])) $tableau['localisation'] = $this->traiterLocalisation($tableau['localisation']);
200
		}
200
		}
201
		if (isset($tableau['motscles'])) {
201
		if (isset($tableau['motscles'])) {
-
 
202
    		if (isset($tableau['tag-obs'])) {
-
 
203
    		    $tableau['tag-obs'] .= $tableau['motscles'];print_r($tableau);exit;
-
 
204
		    } else if (isset($tableau['tag-img'])) {
-
 
205
		        $tableau['tag-img'] .= $tableau['motscles'];
-
 
206
		    } else {
202
		    $tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
207
		        $tableau['tag-obs'] = $tableau['tag-img'] = $tableau['motscles'];
-
 
208
		    }
-
 
209
		    
203
		}
210
		}
204
		$tableau['chpSupp'] = $tab;
211
		$tableau['chpSupp'] = $tab;
205
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
212
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
206
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['imgProjet'] . $tableau['projet'] . $langue_projet_url . '/' );
213
		$tableau['chemin_fichiers'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['imgProjet'] . $tableau['projet'] . $langue_projet_url . '/' );
207
		return $tableau;
214
		return $tableau;
208
	}
215
	}
209
 
216
 
210
	/* Recherche si un projet a des champs de saisie supplémentaire */
217
	/* Recherche si un projet a des champs de saisie supplémentaire */
211
	private function rechercherChampsSupp() {
218
	private function rechercherChampsSupp() {
212
		$retour = array();
219
		$retour = array();
213
		$projet = $this->parametres['projet'];
220
		$projet = $this->parametres['projet'];
214
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
221
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
215
		$json = $this->getDao()->consulter($url);
222
		$json = $this->getDao()->consulter($url);
216
		$retour = json_decode($json, true);
223
		$retour = json_decode($json, true);
217
 
224
 
218
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
225
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
219
 
226
 
220
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
227
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
221
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
228
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
222
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
229
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
223
 
230
 
224
			if ( isset( $chsup['fieldValues'] ) ) {
231
			if ( isset( $chsup['fieldValues'] ) ) {
225
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $this->clean_string( $chsup['fieldValues'] ), true );
232
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $this->clean_string( $chsup['fieldValues'] ), true );
226
 
233
 
227
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
234
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
228
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
235
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
229
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
236
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
230
						$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] ) ) ) : '';
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] ) ) ) : '';
231
					}
238
					}
232
				}
239
				}
233
			}
240
			}
234
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
241
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
235
		}
242
		}
236
		return $retour;
243
		return $retour;
237
	}
244
	}
238
 
245
 
239
	// remplace certains parametres définis en bd par les parametres définis dans l'url
246
	// remplace certains parametres définis en bd par les parametres définis dans l'url
240
	private function traiterParametres($estProjetDefini, $tableau) {
247
	private function traiterParametres($estProjetDefini, $tableau) {
241
		$criteres = array('tag-obs', 'tag-img', 'projet', 'titre', 'logo');
248
		$criteres = array('tag-obs', 'tag-img', 'projet', 'titre', 'logo');
242
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
249
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
243
		foreach($this->parametres as $nom_critere => $valeur_critere) {
250
		foreach($this->parametres as $nom_critere => $valeur_critere) {
244
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
251
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
245
				$tableau[$nom_critere] = $valeur_critere;
252
				$tableau[$nom_critere] = $valeur_critere;
246
			} else if (in_array($nom_critere, $criteres)) {
253
			} else if (in_array($nom_critere, $criteres)) {
247
				$tableau[$nom_critere] = $valeur_critere;
254
				$tableau[$nom_critere] = $valeur_critere;
248
			}
255
			}
249
		}
256
		}
250
		return $tableau;
257
		return $tableau;
251
	}
258
	}
252
 
259
 
253
	private function traiterLocalisation( $infos_localisation ) {
260
	private function traiterLocalisation( $infos_localisation ) {
254
		$infos = explode(';', $infos_localisation);
261
		$infos = explode(';', $infos_localisation);
255
		$tableauTmp = array();
262
		$tableauTmp = array();
256
		$retour = array();
263
		$retour = array();
257
		foreach ($infos as $info) {
264
		foreach ($infos as $info) {
258
			$tableauTmp = explode(':', $info);
265
			$tableauTmp = explode(':', $info);
259
			$retour[$tableauTmp[0]] = $tableauTmp[1];
266
			$retour[$tableauTmp[0]] = $tableauTmp[1];
260
		}
267
		}
261
		return $retour;
268
		return $retour;
262
	}
269
	}
263
 
270
 
264
	private function traiterParamsLocalisation( $params ) {
271
	private function traiterParamsLocalisation( $params ) {
265
		$infos = array();
272
		$infos = array();
266
		$tableauTmp = array();
273
		$tableauTmp = array();
267
		$zoom = '12';
274
		$zoom = '12';
268
		if (isset($params['commune'])) {
275
		if (isset($params['commune'])) {
269
			$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?zone='.$params['commune'].'&code='.$params['dept'];
276
			$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?zone='.$params['commune'].'&code='.$params['dept'];
270
		} else if (isset($params['dept'])) {
277
		} else if (isset($params['dept'])) {
271
			// pas trouvé de manière simple de déterminer le centroïde du département
278
			// pas trouvé de manière simple de déterminer le centroïde du département
272
			// du coup on retrouve le code insee du chef lieu
279
			// du coup on retrouve le code insee du chef lieu
273
			$params['code_insee'] = $this->recupererChefLieuDept($params['dept']);
280
			$params['code_insee'] = $this->recupererChefLieuDept($params['dept']);
274
			$zoom = '9';
281
			$zoom = '9';
275
		}
282
		}
276
		// quoi qu'il arrive, s'il est défini, on donne la priorité au code insee (plus précis)
283
		// quoi qu'il arrive, s'il est défini, on donne la priorité au code insee (plus précis)
277
		if (isset($params['code_insee'])) {
284
		if (isset($params['code_insee'])) {
278
			$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?code='.$params['code_insee'];
285
			$url = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_COORD). '?code='.$params['code_insee'];
279
		}
286
		}
280
		if(!empty($url)) $json = $this->getDao()->consulter($url);
287
		if(!empty($url)) $json = $this->getDao()->consulter($url);
281
		if(!empty($json)) $infos = json_decode($json, true);
288
		if(!empty($json)) $infos = json_decode($json, true);
282
		if(!empty($infos)) {
289
		if(!empty($infos)) {
283
			$infos['lat'] = str_replace(',','.',strval(round($infos['lat'],5)));
290
			$infos['lat'] = str_replace(',','.',strval(round($infos['lat'],5)));
284
			$infos['lng'] = str_replace(',','.',strval(round($infos['lng'],5)));
291
			$infos['lng'] = str_replace(',','.',strval(round($infos['lng'],5)));
285
			return 'latitude:'.$infos['lat'].';longitude:'.$infos['lng'].';zoom:'.$zoom;
292
			return 'latitude:'.$infos['lat'].';longitude:'.$infos['lng'].';zoom:'.$zoom;
286
		} else {
293
		} else {
287
			return false;
294
			return false;
288
		}
295
		}
289
	}
296
	}
290
 
297
 
291
	private function rechercherInfosEspeces( $infos_projets ) {
298
	private function rechercherInfosEspeces( $infos_projets ) {
292
		$retour = array();
299
		$retour = array();
293
		$referentiel = $infos_projets['referentiel'];
300
		$referentiel = $infos_projets['referentiel'];
294
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
301
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
295
		$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
302
		$retour['url_ws_autocompletion_ns'] = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );;
296
		$retour['url_ws_autocompletion_ns_tpl'] = 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 );
297
		$retour['ns_referentiel'] = $referentiel;
304
		$retour['ns_referentiel'] = $referentiel;
298
 
305
 
299
		if ( isset( $infos_projets['type_especes'] ) ) {
306
		if ( isset( $infos_projets['type_especes'] ) ) {
300
 
307
 
301
			switch ( $infos_projets['type_especes'] ) {
308
			switch ( $infos_projets['type_especes'] ) {
302
				case 'fixe' :
309
				case 'fixe' :
303
					$info_taxon = explode(':', $referentiel);
310
					$info_taxon = explode(':', $referentiel);
304
					if (!empty($info_taxon) && count((array) $info_taxon) === 2) {
311
					if (!empty($info_taxon) && count((array) $info_taxon) === 2) {
305
						$retour = $this->chargerInfosTaxon( $info_taxon[0], $info_taxon[1] );
312
						$retour = $this->chargerInfosTaxon( $info_taxon[0], $info_taxon[1] );
306
					}
313
					}
307
					break;
314
					break;
308
				case 'referentiel' : break;
315
				case 'referentiel' : break;
309
				case 'liste' :
316
				case 'liste' :
310
					$retour['taxons'] = $this->recupererListeNomsSci();
317
					$retour['taxons'] = $this->recupererListeNomsSci();
311
					break;
318
					break;
312
			}
319
			}
313
		} else if ( isset( $referentiel ) ) {
320
		} else if ( isset( $referentiel ) ) {
314
			if ( isset($infos_projets['num_nom'] ) ) {
321
			if ( isset($infos_projets['num_nom'] ) ) {
315
				$retour = $this->chargerInfosTaxon( $referentiel, $infos_projets['num_nom'] );
322
				$retour = $this->chargerInfosTaxon( $referentiel, $infos_projets['num_nom'] );
316
			}
323
			}
317
		}
324
		}
318
		return $retour;
325
		return $retour;
319
	}
326
	}
320
 
327
 
321
	/**
328
	/**
322
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
329
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
323
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
330
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
324
	 * et non le taxon?)
331
	 * et non le taxon?)
325
	 * @param string|int $num_nom
332
	 * @param string|int $num_nom
326
	 * @return array
333
	 * @return array
327
	 */
334
	 */
328
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
335
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
329
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
336
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
330
		$infos = json_decode( file_get_contents( $url_service_infos ) );
337
		$infos = json_decode( file_get_contents( $url_service_infos ) );
331
		// trop de champs injectés dans les infos espèces peuvent
338
		// trop de champs injectés dans les infos espèces peuvent
332
		// faire planter javascript
339
		// faire planter javascript
333
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet', 'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
340
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet', 'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
334
		$resultat = array();
341
		$resultat = array();
335
		$retour = array();
342
		$retour = array();
336
		if ( isset( $infos ) && !empty( $infos ) ) {
343
		if ( isset( $infos ) && !empty( $infos ) ) {
337
			$infos = (array) $infos;
344
			$infos = (array) $infos;
338
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
345
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
339
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
346
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
340
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
347
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
341
				$retour['espece_imposee'] = true;
348
				$retour['espece_imposee'] = true;
342
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
349
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
343
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
350
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
344
				$retour['infos_espece'] = $this->array2js( $resultat, true );
351
				$retour['infos_espece'] = $this->array2js( $resultat, true );
345
			}
352
			}
346
		}
353
		}
347
		return $retour;
354
		return $retour;
348
	}
355
	}
349
 
356
 
350
	protected function getReferentielImpose() {
357
	protected function getReferentielImpose() {
351
		$referentiel_impose = true;
358
		$referentiel_impose = true;
352
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
359
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
353
			$this->ns_referentiel = $_GET['referentiel'];
360
			$this->ns_referentiel = $_GET['referentiel'];
354
		} else if (isset($this->configProjet['referentiel'])) {
361
		} else if (isset($this->configProjet['referentiel'])) {
355
			$this->ns_referentiel = $this->configProjet['referentiel'];
362
			$this->ns_referentiel = $this->configProjet['referentiel'];
356
		} else if (isset($this->configMission['referentiel'])) {
363
		} else if (isset($this->configMission['referentiel'])) {
357
			$this->ns_referentiel = $this->configMission['referentiel'];
364
			$this->ns_referentiel = $this->configMission['referentiel'];
358
		} else {
365
		} else {
359
			$referentiel_impose = false;
366
			$referentiel_impose = false;
360
		}
367
		}
361
		return $referentiel_impose;
368
		return $referentiel_impose;
362
	}
369
	}
363
 
370
 
364
	/**
371
	/**
365
	 * Trie par nom français les taxons lus dans le fichier csv/tsv
372
	 * Trie par nom français les taxons lus dans le fichier csv/tsv
366
	 */
373
	 */
367
	protected function recupererListeNomsSci() {
374
	protected function recupererListeNomsSci() {
368
		$taxons = $this->recupererListeTaxon();
375
		$taxons = $this->recupererListeTaxon();
369
		if (is_array($taxons)) {
376
		if (is_array($taxons)) {
370
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
377
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
371
		}
378
		}
372
		return $taxons;
379
		return $taxons;
373
	}
380
	}
374
 
381
 
375
	/**
382
	/**
376
	 * @TODO documenter
383
	 * @TODO documenter
377
	 * @return array
384
	 * @return array
378
	 */
385
	 */
379
	protected function recupererListeNoms() {
386
	protected function recupererListeNoms() {
380
		$taxons = $this->recupererListeTaxon();
387
		$taxons = $this->recupererListeTaxon();
381
		$nomsAAfficher = array();
388
		$nomsAAfficher = array();
382
		$nomsSpeciaux = array();
389
		$nomsSpeciaux = array();
383
		if (is_array($taxons)) {
390
		if (is_array($taxons)) {
384
			foreach ($taxons as $taxon) {
391
			foreach ($taxons as $taxon) {
385
				$nomSciTitle = $taxon['nom_ret'].
392
				$nomSciTitle = $taxon['nom_ret'].
386
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
393
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
387
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
394
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
388
				$nomFrTitle = $taxon['nom_sel'].
395
				$nomFrTitle = $taxon['nom_sel'].
389
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
396
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
390
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
397
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
391
 
398
 
392
				if ($taxon['groupe'] == 'special') {
399
				if ($taxon['groupe'] == 'special') {
393
					$nomsSpeciaux[] = array(
400
					$nomsSpeciaux[] = array(
394
							'num_nom' => $taxon['num_nom_sel'],
401
							'num_nom' => $taxon['num_nom_sel'],
395
							'nom_a_afficher' => $taxon['nom_fr'],
402
							'nom_a_afficher' => $taxon['nom_fr'],
396
							'nom_a_sauver' => $taxon['nom_sel'],
403
							'nom_a_sauver' => $taxon['nom_sel'],
397
							'nom_title' => $nomSciTitle,
404
							'nom_title' => $nomSciTitle,
398
							'nom_type' => 'nom-special');
405
							'nom_type' => 'nom-special');
399
				} else {
406
				} else {
400
					$nomsAAfficher[] = array(
407
					$nomsAAfficher[] = array(
401
							'num_nom' => $taxon['num_nom_sel'],
408
							'num_nom' => $taxon['num_nom_sel'],
402
							'nom_a_afficher' => $taxon['nom_sel'],
409
							'nom_a_afficher' => $taxon['nom_sel'],
403
							'nom_a_sauver' => $taxon['nom_sel'],
410
							'nom_a_sauver' => $taxon['nom_sel'],
404
							'nom_title' => $nomSciTitle,
411
							'nom_title' => $nomSciTitle,
405
							'nom_type' => 'nom-sci');
412
							'nom_type' => 'nom-sci');
406
					$nomsAAfficher[] = array(
413
					$nomsAAfficher[] = array(
407
							'num_nom' => $taxon['num_nom_sel'],
414
							'num_nom' => $taxon['num_nom_sel'],
408
							'nom_a_afficher' => $taxon['nom_fr'],
415
							'nom_a_afficher' => $taxon['nom_fr'],
409
							'nom_a_sauver' => $taxon['nom_fr'],
416
							'nom_a_sauver' => $taxon['nom_fr'],
410
							'nom_title' => $nomFrTitle,
417
							'nom_title' => $nomFrTitle,
411
							'nom_type' => 'nom-fr');
418
							'nom_type' => 'nom-fr');
412
				}
419
				}
413
			}
420
			}
414
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
421
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
415
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
422
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
416
		}
423
		}
417
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
424
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
418
	}
425
	}
419
 
426
 
420
	/**
427
	/**
421
	 * Lit une liste de taxons depuis un fichier csv ou tsv fourni
428
	 * Lit une liste de taxons depuis un fichier csv ou tsv fourni
422
	 */
429
	 */
423
	protected function recupererListeTaxon() {
430
	protected function recupererListeTaxon() {
424
		$taxons = array();
431
		$taxons = array();
425
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
432
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
426
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
433
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
427
		$nom_fichier = ($this->parametres['squelette'] === 'lichens') ? 'lichens_taxons' : 'especes';
434
		$nom_fichier = ($this->parametres['squelette'] === 'lichens') ? 'lichens_taxons' : 'especes';
428
		$chemin_taxon = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . $nom_fichier. '.';
435
		$chemin_taxon = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . $nom_fichier. '.';
429
 
436
 
430
		if ( file_exists( $chemin_taxon . 'csv' ) && is_readable( $chemin_taxon . 'csv' ) ) {
437
		if ( file_exists( $chemin_taxon . 'csv' ) && is_readable( $chemin_taxon . 'csv' ) ) {
431
			$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'csv' );
438
			$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'csv' );
432
		} else if ( file_exists( $chemin_taxon . 'tsv' ) && is_readable( $chemin_taxon . 'tsv' ) ) {
439
		} else if ( file_exists( $chemin_taxon . 'tsv' ) && is_readable( $chemin_taxon . 'tsv' ) ) {
433
			$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'tsv' );
440
			$taxons = $this->decomposerFichierCsv( $chemin_taxon . 'tsv' );
434
		} else {
441
		} else {
435
			$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
442
			$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
436
		}
443
		}
437
		return $taxons;
444
		return $taxons;
438
	}
445
	}
439
 
446
 
440
	/**
447
	/**
441
	 * Lit une liste de taxons depuis un fichier csv ou tsv fourni
448
	 * Lit une liste de taxons depuis un fichier csv ou tsv fourni
442
	 */
449
	 */
443
	protected function recupererChefLieuDept($dept) {
450
	protected function recupererChefLieuDept($dept) {
444
		$infosDepts = array();
451
		$infosDepts = array();
445
		$code_insee = '';
452
		$code_insee = '';
446
		$chemin_fichier = dirname(__FILE__).self::DS.'squelettes'.self::DS.'dept.csv';
453
		$chemin_fichier = dirname(__FILE__).self::DS.'squelettes'.self::DS.'dept.csv';
447
 
454
 
448
		if (file_exists($chemin_fichier ) && is_readable($chemin_fichier)) {
455
		if (file_exists($chemin_fichier ) && is_readable($chemin_fichier)) {
449
			$infosDepts = $this->decomposerFichierCsv( $chemin_fichier,"," );
456
			$infosDepts = $this->decomposerFichierCsv( $chemin_fichier,"," );
450
			if(!empty($infosDepts) && is_array($infosDepts)) {
457
			if(!empty($infosDepts) && is_array($infosDepts)) {
451
				foreach ($infosDepts as $key => $infosDept) {
458
				foreach ($infosDepts as $key => $infosDept) {
452
					if($dept == $infosDept['dep']) {
459
					if($dept == $infosDept['dep']) {
453
						return $code_insee = $infosDept['cheflieu'];
460
						return $code_insee = $infosDept['cheflieu'];
454
					}
461
					}
455
				}
462
				}
456
			}
463
			}
457
		} else {
464
		} else {
458
			$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
465
			$this->debug[] = "Impossible d'ouvrir le fichier '$nom_fichier'.";
459
		}
466
		}
460
	}
467
	}
461
 
468
 
462
	/**
469
	/**
463
	 * Découpe un fihcier csv/tsv
470
	 * Découpe un fihcier csv/tsv
464
	 */
471
	 */
465
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
472
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
466
		$header = null;
473
		$header = null;
467
		$data = array();
474
		$data = array();
468
		if (($handle = fopen($fichier, "r")) !== FALSE) {
475
		if (($handle = fopen($fichier, "r")) !== FALSE) {
469
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
476
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
470
				if (!$header) {
477
				if (!$header) {
471
					$header = $row;
478
					$header = $row;
472
				} else {
479
				} else {
473
					$data[] = array_combine($header, $row);
480
					$data[] = array_combine($header, $row);
474
				}
481
				}
475
			}
482
			}
476
			fclose($handle);
483
			fclose($handle);
477
		}
484
		}
478
		return $data;
485
		return $data;
479
	}
486
	}
480
 
487
 
481
	/**
488
	/**
482
	 * 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 ?
483
	 * @param array $array
490
	 * @param array $array
484
	 * @param boolean $show_keys
491
	 * @param boolean $show_keys
485
	 * @return une portion de JSON représentant le tableau
492
	 * @return une portion de JSON représentant le tableau
486
	 */
493
	 */
487
	protected function array2js($array,$show_keys) {
494
	protected function array2js($array,$show_keys) {
488
		$tableauJs = '{}';
495
		$tableauJs = '{}';
489
		if (!empty($array)) {
496
		if (!empty($array)) {
490
			$total = count($array) - 1;
497
			$total = count($array) - 1;
491
			$i = 0;
498
			$i = 0;
492
			$dimensions = array();
499
			$dimensions = array();
493
			foreach ($array as $key => $value) {
500
			foreach ($array as $key => $value) {
494
				if (is_array($value)) {
501
				if (is_array($value)) {
495
					$dimensions[$i] = array2js($value,$show_keys);
502
					$dimensions[$i] = array2js($value,$show_keys);
496
					if ($show_keys) {
503
					if ($show_keys) {
497
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
504
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
498
					}
505
					}
499
				} else {
506
				} else {
500
					$dimensions[$i] = '\"'.addslashes($value).'\"';
507
					$dimensions[$i] = '\"'.addslashes($value).'\"';
501
					if ($show_keys) {
508
					if ($show_keys) {
502
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
509
						$dimensions[$i] = '\"'.$key.'\":'.$dimensions[$i];
503
					}
510
					}
504
				}
511
				}
505
				if ($i == 0) {
512
				if ($i == 0) {
506
					$dimensions[$i] = '{'.$dimensions[$i];
513
					$dimensions[$i] = '{'.$dimensions[$i];
507
				}
514
				}
508
				if ($i == $total) {
515
				if ($i == $total) {
509
					$dimensions[$i].= '}';
516
					$dimensions[$i].= '}';
510
				}
517
				}
511
				$i++;
518
				$i++;
512
			}
519
			}
513
			$tableauJs = implode(',', $dimensions);
520
			$tableauJs = implode(',', $dimensions);
514
		}
521
		}
515
		return $tableauJs;
522
		return $tableauJs;
516
	}
523
	}
517
}
524
}
518
?>
525
?>