Subversion Repositories eFlore/Applications.cel

Rev

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

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