Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3249 Rev 3256
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');
116
		$retour['donnees']['general'] = I18n::get('General');
117
		$retour['donnees']['aide'] = I18n::get('Aide');
117
		$retour['donnees']['aide'] = I18n::get('Aide');
118
		$retour['donnees']['observateur'] = I18n::get('Observateur');
118
		$retour['donnees']['observateur'] = I18n::get('Observateur');
119
		$retour['donnees']['observation'] = I18n::get('Observation');
119
		$retour['donnees']['observation'] = I18n::get('Observation');
120
		$retour['donnees']['image'] = I18n::get('Image');
120
		$retour['donnees']['image'] = I18n::get('Image');
121
 		$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
121
 		$retour['donnees']['chpsupp'] = I18n::get('Chpsupp');
122
 		$retour['donnees']['resume'] = I18n::get('Resume');
122
 		$retour['donnees']['resume'] = I18n::get('Resume');
123
		$retour['donnees']['widget'] = $this->rechercherProjet();
123
		$retour['donnees']['widget'] = $this->rechercherProjet();
124
		return $retour;
124
		return $retour;
125
	}
125
	}
126
 
126
 
127
	/* 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 */
128
	private function rechercherProjet() {
128
	private function rechercherProjet() {
129
		// 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)
130
		$estProjetDefini = true;
130
		$estProjetDefini = true;
131
		$tab = array();
131
		$tab = array();
132
		$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'];
133
		$json = $this->getDao()->consulter($url);
133
		$json = $this->getDao()->consulter($url);
134
 
134
 
135
		if ( $json ) {
135
		if ( $json ) {
136
			$tab = $this->rechercherChampsSupp();
136
			$tab = $this->rechercherChampsSupp();
137
		} else {
137
		} else {
138
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
138
			$url = $this->config['manager']['celUrlTpl'].'?projet=base&langue='.$this->parametres['langue'];
139
			$json = $this->getDao()->consulter($url);
139
			$json = $this->getDao()->consulter($url);
140
			$estProjetDefini = false;
140
			$estProjetDefini = false;
141
		}
141
		}
142
		$tableau = json_decode($json, true);
142
		$tableau = json_decode($json, true);
143
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
143
		$tableau = $this->traiterParametres($estProjetDefini, $tableau[0]);
144
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
144
		$tableau['especes'] = $this->rechercherInfosEspeces($tableau);
145
		if ($tableau['milieux'] != '') {
145
		if ($tableau['milieux'] != '') {
146
			$tableau['milieux'] = explode(';', $tableau['milieux']);
146
			$tableau['milieux'] = explode(';', $tableau['milieux']);
147
		} else {
147
		} else {
148
			$tableau['milieux'] = array();
148
			$tableau['milieux'] = array();
149
		}
149
		}
150
		$tableau['chpSupp'] = $tab;
150
		$tableau['chpSupp'] = $tab;
151
		$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'] : '';
152
		$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 . '/' );
153
		return $tableau;
153
		return $tableau;
154
	}
154
	}
155
 
155
 
156
	/* Recherche si un projet a des champs de saisie supplémentaire */
156
	/* Recherche si un projet a des champs de saisie supplémentaire */
157
	private function rechercherChampsSupp() {
157
	private function rechercherChampsSupp() {
158
		$retour = array();
158
		$retour = array();
159
		$projet = $this->parametres['projet'];
159
		$projet = $this->parametres['projet'];
160
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
160
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
161
		$json = $this->getDao()->consulter($url);
161
		$json = $this->getDao()->consulter($url);
162
		$retour = (array) json_decode($json, true);
162
		$retour = (array) json_decode($json, true);
163
 
163
 
164
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
164
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
165
 
165
 
166
 
166
 
167
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
167
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
168
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
168
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
169
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
169
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
170
 
170
 
171
			if ( isset( $chsup['fieldValues'] ) ) {
171
			if ( isset( $chsup['fieldValues'] ) ) {
172
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
172
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $chsup['fieldValues'], true );
173
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
173
				if ( isset($retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] ) ) {
174
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = $this->clean_string( $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
174
					$retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] = $this->clean_string( $retour[$projet]['champs-supp'][$key]['fieldValues']['placeholder'] );
175
				}
175
				}
176
 
176
 
177
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
177
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
178
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value ) {
178
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value ) {
179
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key] = $this->clean_string( $list_value );
179
						$retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'][$list_key] = $this->clean_string( $list_value );
180
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
180
						// 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 ) );
181
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( $list_value ) );
182
					}
182
					}
183
				}
183
				}
184
			}
184
			}
185
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
185
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
186
		}
186
		}
187
		return $retour;
187
		return $retour;
188
	}
188
	}
189
 
189
 
190
	private function clean_string( $string ) {
190
	private function clean_string( $string ) {
191
		// les fonctions de base de php ne parviennent pas à une conversion satisfaisante des codes ascii
191
		// les fonctions de base de php ne parviennent pas à une conversion satisfaisante des codes ascii
192
		// qui ont été générés automatiquement lors de la transmission des chaines en json
192
		// qui ont été générés automatiquement lors de la transmission des chaines en json
193
		// dans le widget cel manager vers la base
193
		// dans le widget cel manager vers la base
194
		// Pour les mêmes raisons, @apos@ et @quot@ est une autre astuces utilisée dans ce même widget
194
		// Pour les mêmes raisons, @apos@ et @quot@ est une autre astuces utilisée dans ce même widget
195
		// pour permettre la transmission des apostrophes et guillements sans erreur
195
		// pour permettre la transmission des apostrophes et guillements sans erreur
196
		$patterns = array( '/\@apos\@/', '/\@quot\@/', '/u00c0/', '/u00c1/', '/u00c2/', '/u00c3/', '/u00c4/', '/u00c5/', '/u00c6/', '/u00c7/', '/u00c8/', '/u00c9/', '/u00ca/', '/u00cb/', '/u00cc/', '/u00cd/', '/u00ce/', '/u00cf/', '/u00d1/', '/u00d2/', '/u00d3/', '/u00d4/', '/u00d5/', '/u00d6/', '/u00d8/', '/u00d9/', '/u00da/', '/u00db/', '/u00dc/', '/u00dd/', '/u00df/', '/u00e0/', '/u00e1/', '/u00e2/', '/u00e3/', '/u00e4/', '/u00e5/', '/u00e6/', '/u00e7/', '/u00e8/', '/u00e9/', '/u00ea/', '/u00eb/', '/u00ec/', '/u00ed/', '/u00ee/', '/u00ef/', '/u00f0/', '/u00f1/', '/u00f2/', '/u00f3/', '/u00f4/', '/u00f5/', '/u00f6/', '/u00f8/', '/u00f9/', '/u00fa/', '/u00fb/', '/u00fc/', '/u00fd/', '/u00ff/' );
196
		$patterns = array( '/\@apos\@/', '/\@quot\@/', '/u00c0/', '/u00c1/', '/u00c2/', '/u00c3/', '/u00c4/', '/u00c5/', '/u00c6/', '/u00c7/', '/u00c8/', '/u00c9/', '/u00ca/', '/u00cb/', '/u00cc/', '/u00cd/', '/u00ce/', '/u00cf/', '/u00d1/', '/u00d2/', '/u00d3/', '/u00d4/', '/u00d5/', '/u00d6/', '/u00d8/', '/u00d9/', '/u00da/', '/u00db/', '/u00dc/', '/u00dd/', '/u00df/', '/u00e0/', '/u00e1/', '/u00e2/', '/u00e3/', '/u00e4/', '/u00e5/', '/u00e6/', '/u00e7/', '/u00e8/', '/u00e9/', '/u00ea/', '/u00eb/', '/u00ec/', '/u00ed/', '/u00ee/', '/u00ef/', '/u00f0/', '/u00f1/', '/u00f2/', '/u00f3/', '/u00f4/', '/u00f5/', '/u00f6/', '/u00f8/', '/u00f9/', '/u00fa/', '/u00fb/', '/u00fc/', '/u00fd/', '/u00ff/' );
197
		$replacements = array( '&apos;', '&quot;', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý','ÿ' );
197
		$replacements = array( '&apos;', '&quot;', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý','ÿ' );
198
 
198
 
199
		$clean_string = preg_replace( $patterns, $replacements, $string );
199
		$clean_string = preg_replace( $patterns, $replacements, $string );
200
 
200
 
201
		return $clean_string;
201
		return $clean_string;
202
	}
202
	}
203
 
203
 
204
	private function remove_accents($string) {
204
	private function remove_accents($string) {
205
		if ( !preg_match('/[\x80-\xff]/', $string) )
205
		if ( !preg_match('/[\x80-\xff]/', $string) )
206
			return $string;
206
			return $string;
207
 
207
 
208
		$chars = array(
208
		$chars = array(
209
			// Decompositions for Latin-1 Supplement
209
			// Decompositions for Latin-1 Supplement
210
			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
210
			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
211
			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
211
			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
212
			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
212
			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
213
			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
213
			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
214
			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
214
			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
215
			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
215
			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
216
			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
216
			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
217
			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
217
			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
218
			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
218
			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
219
			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
219
			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
220
			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
220
			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
221
			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
221
			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
222
			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
222
			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
223
			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
223
			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
224
			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
224
			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
225
			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
225
			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
226
			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
226
			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
227
			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
227
			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
228
			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
228
			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
229
			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
229
			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
230
			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
230
			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
231
			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
231
			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
232
			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
232
			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
233
			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
233
			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
234
			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
234
			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
235
			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
235
			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
236
			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
236
			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
237
			chr(195).chr(191) => 'y',
237
			chr(195).chr(191) => 'y',
238
			// Decompositions for Latin Extended-A
238
			// Decompositions for Latin Extended-A
239
			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
239
			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
240
			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
240
			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
241
			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
241
			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
242
			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
242
			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
243
			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
243
			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
244
			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
244
			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
245
			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
245
			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
246
			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
246
			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
247
			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
247
			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
248
			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
248
			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
249
			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
249
			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
250
			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
250
			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
251
			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
251
			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
252
			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
252
			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
253
			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
253
			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
254
			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
254
			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
255
			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
255
			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
256
			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
256
			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
257
			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
257
			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
258
			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
258
			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
259
			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
259
			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
260
			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
260
			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
261
			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
261
			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
262
			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
262
			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
263
			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
263
			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
264
			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
264
			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
265
			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
265
			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
266
			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
266
			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
267
			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
267
			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
268
			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
268
			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
269
			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
269
			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
270
			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
270
			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
271
			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
271
			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
272
			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
272
			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
273
			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
273
			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
274
			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
274
			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
275
			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
275
			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
276
			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
276
			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
277
			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
277
			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
278
			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
278
			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
279
			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
279
			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
280
			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
280
			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
281
			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
281
			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
282
			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
282
			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
283
			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
283
			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
284
			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
284
			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
285
			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
285
			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
286
			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
286
			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
287
			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
287
			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
288
			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
288
			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
289
			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
289
			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
290
			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
290
			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
291
			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
291
			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
292
			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
292
			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
293
			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
293
			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
294
			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
294
			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
295
			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
295
			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
296
			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
296
			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
297
			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
297
			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
298
			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
298
			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
299
			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
299
			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
300
			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
300
			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
301
			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
301
			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
302
			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
302
			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
303
		);
303
		);
304
 
304
 
305
		$string = strtr($string, $chars);
305
		$string = strtr($string, $chars);
306
 
306
 
307
		return $string;
307
		return $string;
308
	}
308
	}
309
 
309
 
310
	// remplace certains parametres définis en bd par les parametres définis dans l'url
310
	// remplace certains parametres définis en bd par les parametres définis dans l'url
311
	private function traiterParametres($estProjetDefini, $tableau) {
311
	private function traiterParametres($estProjetDefini, $tableau) {
312
		$criteres = array('tag', 'motcle', 'projet', 'titre', 'logo');
312
		$criteres = array('tag', 'motcle', 'projet', 'titre', 'logo');
313
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
313
		$criteresProjetNonDefini = array('commune', 'num_nom', 'referentiel');
314
		foreach($this->parametres as $nom_critere => $valeur_critere) {
314
		foreach($this->parametres as $nom_critere => $valeur_critere) {
315
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
315
			if (($estProjetDefini == false || $tableau['projet'] == 'base') && in_array($nom_critere, $criteresProjetNonDefini)) {
316
				$tableau[$nom_critere] = $valeur_critere;
316
				$tableau[$nom_critere] = $valeur_critere;
317
			} else if (in_array($nom_critere, $criteres)) {
317
			} else if (in_array($nom_critere, $criteres)) {
318
				$tableau[$nom_critere] = $valeur_critere;
318
				$tableau[$nom_critere] = $valeur_critere;
319
			}
319
			}
320
		}
320
		}
321
		return $tableau;
321
		return $tableau;
322
	}
322
	}
323
 
323
 
324
 
324
 
325
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
325
	private function rechercherInfosEspeces( $infos_projets ) { //print_r($infos_projets);exit;
326
		$retour = array();
326
		$retour = array();
327
		$referentiel = $infos_projets['referentiel'];
327
		$referentiel = $infos_projets['referentiel'];
328
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
328
		$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
329
		$urlWsNs = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );
329
		$urlWsNs = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, $referentiel, self::WS_NOM );
330
		$urlWsNsSansRef = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
330
		$urlWsNsSansRef = sprintf( $urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM );
331
		$retour['url_ws_autocompletion_ns'] = $urlWsNs;
331
		$retour['url_ws_autocompletion_ns'] = $urlWsNs;
332
		$retour['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
332
		$retour['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
333
		$retour['ns_referentiel'] = $referentiel;
333
		$retour['ns_referentiel'] = $referentiel;
334
 
334
 
335
		if ( isset( $infos_projets['type_especes'] ) ) {
335
		if ( isset( $infos_projets['type_especes'] ) ) {
336
 
336
 
337
			switch ( $infos_projets['type_especes'] ) {
337
			switch ( $infos_projets['type_especes'] ) {
338
				case 'fixe' :
338
				case 'fixe' :
339
					$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
339
					$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['especes'] );
340
					break;
340
					break;
341
				case 'referentiel' :
341
				case 'referentiel' :
342
				case 'liste' :
342
				case 'liste' :
343
					$referentiel = $infos_projets['referentiel'];
343
					$referentiel = $infos_projets['referentiel'];
-
 
344
////////////////////// temporaire test transmission liste taxons
-
 
345
					$retour['taxons'] = $this->recupererListeNomsSci();
344
					break;
346
					break;
345
			}
347
			}
346
		} else if ( isset( $infos_projets['referentiel'] ) ) {
348
		} else if ( isset( $infos_projets['referentiel'] ) ) {
347
			$referentiel = $infos_projets['referentiel'];
349
			$referentiel = $infos_projets['referentiel'];
348
			if ( isset($infos_projets['num_nom'] ) ) {
350
			if ( isset($infos_projets['num_nom'] ) ) {
349
				$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
351
				$retour['especes'] = $this->chargerInfosTaxon( $infos_projets['referentiel'], $infos_projets['num_nom'] );
350
			}
352
			}
351
		}
353
		}
352
 
354
 
353
		$projetsAListeDeNoms = $this->transformerEnTableau( $this->config['projets']['liste_noms'] ) ;
355
		// $projetsAListeDeNoms = $this->transformerEnTableau( $this->config['projets']['liste_noms'] ) ;
-
 
356
		// if ( in_array( $this->parametres['projet'], $projetsAListeDeNoms ) && !$this->especeEstImposee() ) {
354
		if ( in_array( $this->projet, $projetsAListeDeNoms ) && !$this->especeEstImposee() ) {
357
		// var_dump($this->parametres['projet']);
355
			$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau( $this->config['projets']['liste_noms_sci_et_verna'] );
358
		// 	$projetsAListeDeNomsSciEtVerna = $this->transformerEnTableau( $this->config['projets']['liste_noms_sci_et_verna'] );
356
			if ( in_array( $this->projet, $projetsAListeDeNomsSciEtVerna ) ) {
359
		// 	if ( in_array( $this->parametres['projet'], $projetsAListeDeNomsSciEtVerna ) ) {
357
				$retour['taxons'] = $this->recupererListeNoms();
360
		// 		$retour['taxons'] = $this->recupererListeNoms();
358
			} else {
361
		// 	} else {
359
				$retour['taxons'] = $this->recupererListeNomsSci();
362
		// 		$retour['taxons'] = $this->recupererListeNomsSci();
360
			}
363
		// 	}
361
		}
364
		// }
362
		return $retour;
365
		return $retour;
363
	}
366
	}
364
 
367
 
365
	/**
368
	/**
366
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
369
	 * Consulte un webservice pour obtenir des informations sur le taxon dont le
367
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
370
	 * numéro nomenclatural est $num_nom (ce sont donc plutôt des infos sur le nom
368
	 * et non le taxon?)
371
	 * et non le taxon?)
369
	 * @param string|int $num_nom
372
	 * @param string|int $num_nom
370
	 * @return array
373
	 * @return array
371
	 */
374
	 */
372
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
375
	protected function chargerInfosTaxon( $referentiel, $num_nom ) {
373
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
376
		$url_service_infos = sprintf( $this->config['chemins']['infosTaxonUrl'], $referentiel, $num_nom );
374
		$infos = json_decode( file_get_contents( $url_service_infos ) );
377
		$infos = json_decode( file_get_contents( $url_service_infos ) );
375
		// trop de champs injectés dans les infos espèces peuvent
378
		// trop de champs injectés dans les infos espèces peuvent
376
		// faire planter javascript
379
		// faire planter javascript
377
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet',
380
		$champs_a_garder = array( 'id', 'nom_sci','nom_sci_complet', 'nom_complet',
378
				'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
381
				'famille','nom_retenu.id', 'nom_retenu_complet', 'num_taxonomique' );
379
		$resultat = array();
382
		$resultat = array();
380
		$retour = array();
383
		$retour = array();
381
		if ( isset( $infos ) && !empty( $infos ) ) {
384
		if ( isset( $infos ) && !empty( $infos ) ) {
382
			$infos = (array) $infos;
385
			$infos = (array) $infos;
383
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
386
			if ( isset( $infos['nom_sci'] ) && $infos['nom_sci'] !== '' ) {
384
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
387
				$resultat = array_intersect_key( $infos, array_flip($champs_a_garder ) );
385
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
388
				$resultat['retenu'] = ( $infos['id'] == $infos['nom_retenu.id'] ) ? 'true' : 'false';
386
				$retour['espece_imposee'] = true;
389
				$retour['espece_imposee'] = true;
387
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
390
				$retour['nn_espece_defaut'] = $nnEspeceImposee;
388
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
391
				$retour['nom_sci_espece_defaut'] = $resultat['nom_complet'];
389
				$retour['infos_espece'] = $this->array2js( $resultat, true );
392
				$retour['infos_espece'] = $this->array2js( $resultat, true );
390
			}
393
			}
391
		}
394
		}
392
		return $retour;
395
		return $retour;
393
	}
396
	}
394
 
397
 
395
	protected function getReferentielImpose() {
398
	protected function getReferentielImpose() {
396
		$referentiel_impose = true;
399
		$referentiel_impose = true;
397
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
400
		if (!empty($_GET['referentiel']) && $_GET['referentiel'] !== 'autre') {
398
			$this->ns_referentiel = $_GET['referentiel'];
401
			$this->ns_referentiel = $_GET['referentiel'];
399
		} else if (isset($this->configProjet['referentiel'])) {
402
		} else if (isset($this->configProjet['referentiel'])) {
400
			$this->ns_referentiel = $this->configProjet['referentiel'];
403
			$this->ns_referentiel = $this->configProjet['referentiel'];
401
		} else if (isset($this->configMission['referentiel'])) {
404
		} else if (isset($this->configMission['referentiel'])) {
402
			$this->ns_referentiel = $this->configMission['referentiel'];
405
			$this->ns_referentiel = $this->configMission['referentiel'];
403
		} else {
406
		} else {
404
			$referentiel_impose = false;
407
			$referentiel_impose = false;
405
		}
408
		}
406
		return $referentiel_impose;
409
		return $referentiel_impose;
407
	}
410
	}
408
 
411
 
409
	/**
412
	/**
410
	 * Trie par nom français les taxons lus dans le fichier tsv
413
	 * Trie par nom français les taxons lus dans le fichier csv
411
	 */
414
	 */
412
	protected function recupererListeNomsSci() {
415
	protected function recupererListeNomsSci() {
413
		$taxons = $this->recupererListeTaxon();
416
		$taxons = $this->recupererListeTaxon();
414
		if (is_array($taxons)) {
417
		if (is_array($taxons)) {
415
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
418
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
416
		}
419
		}
417
		return $taxons;
420
		return $taxons;
418
	}
421
	}
419
 
422
 
420
	/**
423
	/**
421
	 * @TODO documenter
424
	 * @TODO documenter
422
	 * @return array
425
	 * @return array
423
	 */
426
	 */
424
	protected function recupererListeNoms() {
427
	protected function recupererListeNoms() {
425
		$taxons = $this->recupererListeTaxon();
428
		$taxons = $this->recupererListeTaxon();
426
		$nomsAAfficher = array();
429
		$nomsAAfficher = array();
427
		$nomsSpeciaux = array();
430
		$nomsSpeciaux = array();
428
		if (is_array($taxons)) {
431
		if (is_array($taxons)) {
429
			foreach ($taxons as $taxon) {
432
			foreach ($taxons as $taxon) {
430
				$nomSciTitle = $taxon['nom_ret'].
433
				$nomSciTitle = $taxon['nom_ret'].
431
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
434
				($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
432
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
435
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
433
				$nomFrTitle = $taxon['nom_sel'].
436
				$nomFrTitle = $taxon['nom_sel'].
434
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
437
				($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
435
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
438
				($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
436
 
439
 
437
				if ($taxon['groupe'] == 'special') {
440
				if ($taxon['groupe'] == 'special') {
438
					$nomsSpeciaux[] = array(
441
					$nomsSpeciaux[] = array(
439
							'num_nom' => $taxon['num_nom_sel'],
442
							'num_nom' => $taxon['num_nom_sel'],
440
							'nom_a_afficher' => $taxon['nom_fr'],
443
							'nom_a_afficher' => $taxon['nom_fr'],
441
							'nom_a_sauver' => $taxon['nom_sel'],
444
							'nom_a_sauver' => $taxon['nom_sel'],
442
							'nom_title' => $nomSciTitle,
445
							'nom_title' => $nomSciTitle,
443
							'nom_type' => 'nom-special');
446
							'nom_type' => 'nom-special');
444
				} else {
447
				} else {
445
					$nomsAAfficher[] = array(
448
					$nomsAAfficher[] = array(
446
							'num_nom' => $taxon['num_nom_sel'],
449
							'num_nom' => $taxon['num_nom_sel'],
447
							'nom_a_afficher' => $taxon['nom_sel'],
450
							'nom_a_afficher' => $taxon['nom_sel'],
448
							'nom_a_sauver' => $taxon['nom_sel'],
451
							'nom_a_sauver' => $taxon['nom_sel'],
449
							'nom_title' => $nomSciTitle,
452
							'nom_title' => $nomSciTitle,
450
							'nom_type' => 'nom-sci');
453
							'nom_type' => 'nom-sci');
451
					$nomsAAfficher[] = array(
454
					$nomsAAfficher[] = array(
452
							'num_nom' => $taxon['num_nom_sel'],
455
							'num_nom' => $taxon['num_nom_sel'],
453
							'nom_a_afficher' => $taxon['nom_fr'],
456
							'nom_a_afficher' => $taxon['nom_fr'],
454
							'nom_a_sauver' => $taxon['nom_fr'],
457
							'nom_a_sauver' => $taxon['nom_fr'],
455
							'nom_title' => $nomFrTitle,
458
							'nom_title' => $nomFrTitle,
456
							'nom_type' => 'nom-fr');
459
							'nom_type' => 'nom-fr');
457
				}
460
				}
458
			}
461
			}
459
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
462
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
460
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
463
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
461
		}
464
		}
462
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
465
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
463
	}
466
	}
464
 
467
 
465
	/**
468
	/**
466
	 * Lit une liste de taxons depuis un fichier tsv fourni
469
	 * Lit une liste de taxons depuis un fichier csv fourni
467
	 */
470
	 */
468
	protected function recupererListeTaxon() {
471
	protected function recupererListeTaxon() {
469
		$taxons = array();
472
		$taxons = array();
-
 
473
		$langue_projet_url = ( isset ( $this->parametres['langue'] ) && $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
-
 
474
		$chemin_images = dirname(__FILE__) . self::DS . '..' . self::DS . 'manager' . self::DS . 'squelettes' . self::DS . 'img' . self::DS . 'images_projets' . self::DS;
470
		if ($this->projet == 'missions-flore') {
475
		if ( $this->parametres['projet'] == 'missions-flore' ) {
-
 
476
			// chemin temporaire à modifier une fois réorganisés avec le nouveau widget
-
 
477
			// $fichier_csv = $chemin_images . $this->parametres['projet'] . '_'.$this->mission . $langue_projet_url . '/especes.csv';
471
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_'.$this->mission.'_taxons.tsv';
478
			$fichier_csv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->parametres['projet'].'_'.$this->mission.'_taxons.tsv';
472
		} else {
479
		} else {
473
			$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
480
			$fichier_csv = $chemin_images . $this->parametres['projet'] . $langue_projet_url . self::DS . 'especes.csv'; ;
474
		}
481
		}
475
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
482
		if ( file_exists( $fichier_csv ) && is_readable( $fichier_csv ) ) {
476
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
483
			$taxons = $this->decomposerFichierCsv( $fichier_csv );
477
		} else {
484
		} else {
478
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
485
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_csv'.";
479
		}
486
		}
480
		return $taxons;
487
		return $taxons;
481
	}
488
	}
482
 
489
 
483
	/**
490
	/**
484
	 * Découpe un fihcier tsv
491
	 * Découpe un fihcier csv
485
	 */
492
	 */
486
	protected function decomposerFichierTsv($fichier, $delimiter = '\t'){
493
	protected function decomposerFichierCsv($fichier, $delimiter = "\t"){
487
		$header = null;
494
		$header = null;
488
		$data = array();
495
		$data = array();
489
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
496
		if (($handle = fopen($fichier, "r")) !== FALSE) {
490
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
497
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
491
				if (!$header) {
498
				if (!$header) {
492
					$header = $row;
499
					$header = $row;
493
				} else {
500
				} else {
494
					$data[] = array_combine($header, $row);
501
					$data[] = array_combine($header, $row);
495
				}
502
				}
496
			}
503
			}
497
			fclose($handle);
504
			fclose($handle);
498
		}
505
		}
499
		return $data;
506
		return $data;
500
	}
507
	}
501
 
508
 
502
	/**
509
	/**
503
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
510
	 * Convertit un tableau PHP en Javascript - @WTF pourquoi ne pas faire un json_encode ?
504
	 * @param array $array
511
	 * @param array $array
505
	 * @param boolean $show_keys
512
	 * @param boolean $show_keys
506
	 * @return une portion de JSON représentant le tableau
513
	 * @return une portion de JSON représentant le tableau
507
	 */
514
	 */
508
	protected function array2js($array,$show_keys) {
515
	protected function array2js($array,$show_keys) {
509
		$tableauJs = '{}';
516
		$tableauJs = '{}';
510
		if (!empty($array)) {
517
		if (!empty($array)) {
511
			$total = count($array) - 1;
518
			$total = count($array) - 1;
512
			$i = 0;
519
			$i = 0;
513
			$dimensions = array();
520
			$dimensions = array();
514
			foreach ($array as $key => $value) {
521
			foreach ($array as $key => $value) {
515
				if (is_array($value)) {
522
				if (is_array($value)) {
516
					$dimensions[$i] = array2js($value,$show_keys);
523
					$dimensions[$i] = array2js($value,$show_keys);
517
					if ($show_keys) {
524
					if ($show_keys) {
518
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
525
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
519
					}
526
					}
520
				} else {
527
				} else {
521
					$dimensions[$i] = '"'.addslashes($value).'"';
528
					$dimensions[$i] = '"'.addslashes($value).'"';
522
					if ($show_keys) {
529
					if ($show_keys) {
523
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
530
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
524
					}
531
					}
525
				}
532
				}
526
				if ($i == 0) {
533
				if ($i == 0) {
527
					$dimensions[$i] = '{'.$dimensions[$i];
534
					$dimensions[$i] = '{'.$dimensions[$i];
528
				}
535
				}
529
				if ($i == $total) {
536
				if ($i == $total) {
530
					$dimensions[$i].= '}';
537
					$dimensions[$i].= '}';
531
				}
538
				}
532
				$i++;
539
				$i++;
533
			}
540
			}
534
			$tableauJs = implode(',', $dimensions);
541
			$tableauJs = implode(',', $dimensions);
535
		}
542
		}
536
		return $tableauJs;
543
		return $tableauJs;
537
	}
544
	}
538
 
545
 
539
}
546
}
540
?>
547
?>