Subversion Repositories eFlore/Applications.cel

Rev

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

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