Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1909 Rev 1916
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Widget fournissant des interfaces de saisies simplifiée pour différent projets.
4
 * Widget fournissant des interfaces de saisies simplifiée pour différent projets.
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=AideCELWidgetSaisie
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetSaisie
10
 *
10
 *
11
 * Paramètres :
11
 * Paramètres :
12
 * ===> projet = chaine  [par défaut : Biodiversite34]
12
 * ===> projet = chaine  [par défaut : Biodiversite34]
13
 * Indique quel projet nous voulons charger
13
 * Indique quel projet nous voulons charger
14
 *
14
 *
15
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
15
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
16
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
16
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
17
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
17
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
18
 * @version		$Id$
18
 * @version		$Id$
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
19
 * @copyright	Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
20
 */
20
 */
21
class Saisie extends WidgetCommun {
21
class Saisie extends WidgetCommun {
22
 
22
 
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'defaut';
24
	const PROJET_DEFAUT = 'defaut';
25
	const WS_SAISIE = 'CelWidgetSaisie';
25
	const WS_SAISIE = 'CelWidgetSaisie';
26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
26
	const WS_UPLOAD = 'CelWidgetUploadImageTemp';
27
	const WS_OBS = 'CelObs';
27
	const WS_OBS = 'CelObs';
28
	const WS_NOM = 'noms';
28
	const WS_NOM = 'noms';
29
	private $NS_PROJET_VERSION = '1.01';
29
	private $NS_PROJET_VERSION = '1.01';
30
	const EFLORE_API_VERSION = '0.1';
30
	const EFLORE_API_VERSION = '0.1';
31
	private $NS_PROJET = 'bdtfx';
31
	private $NS_PROJET = 'bdtfx';
32
 
32
 
33
	private $projetsVersions = array();
33
	private $projetsVersions = array();
34
	private $projet = null;
34
	private $projet = null;
35
	private $configProjet = null;
35
	private $configProjet = null;
36
 
36
 
37
	/**
37
	/**
38
	 * Méthode appelée par défaut pour charger ce widget.
38
	 * Méthode appelée par défaut pour charger ce widget.
39
	 */
39
	 */
40
	public function executer() {
40
	public function executer() {
41
		$retour = null;
41
		$retour = null;
42
		extract($this->parametres);
42
		extract($this->parametres);
43
 
43
 
44
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
44
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
45
		$this->chargerConfigProjet();
45
		$this->chargerConfigProjet();
46
		$this->chargerProjetsVersion();
46
		$this->chargerProjetsVersion();
47
 
47
 
48
		$service = isset($service) ? $service : 'widget';
48
		$service = isset($service) ? $service : 'widget';
49
		$methode = $this->traiterNomMethodeExecuter($service);
49
		$methode = $this->traiterNomMethodeExecuter($service);
50
		if (method_exists($this, $methode)) {
50
		if (method_exists($this, $methode)) {
51
			$retour = $this->$methode();
51
			$retour = $this->$methode();
52
		} else {
52
		} else {
53
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
53
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
54
		}
54
		}
55
 
55
 
56
		$contenu = null;
56
		$contenu = null;
57
		$mime = null;
57
		$mime = null;
58
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
58
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
59
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
59
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
60
			if($this->projetASquelette()) {
60
			if($this->projetASquelette()) {
61
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
61
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
62
			} else {
62
			} else {
63
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
63
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
64
			}
64
			}
65
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
65
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
66
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
66
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
67
		} else {
67
		} else {
68
			if (count($this->messages) == 0) {
68
			if (count($this->messages) == 0) {
69
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format.";
69
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format.";
70
			}
70
			}
71
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
71
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
72
		}
72
		}
73
 
73
 
74
		$this->envoyer($contenu, $mime);
74
		$this->envoyer($contenu, $mime);
75
	}
75
	}
76
 
76
 
77
	private function chargerConfigProjet() {
77
	private function chargerConfigProjet() {
78
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
78
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
79
		if (file_exists($fichier_config)) {
79
		if (file_exists($fichier_config)) {
80
			if (!$this->configProjet = parse_ini_file($fichier_config)) {
80
			if (!$this->configProjet = parse_ini_file($fichier_config)) {
81
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
81
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
82
			}
82
			}
83
		} else {
83
		} else {
84
			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
84
			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
85
		}
85
		}
86
	}
86
	}
87
 
87
 
88
	private function chargerProjetsVersion() {
88
	private function chargerProjetsVersion() {
89
		if (isset($this->configProjet)) {
89
		if (isset($this->configProjet)) {
90
			foreach ($this->configProjet as $config => $valeur) {
90
			foreach ($this->configProjet as $config => $valeur) {
91
				if(strstr($config,'.version')) {
91
				if(strstr($config,'.version')) {
92
					$this->projetsVersions[str_replace('.version', '', $config)] = $valeur;
92
					$this->projetsVersions[str_replace('.version', '', $config)] = $valeur;
93
				}
93
				}
94
			}
94
			}
95
		}
95
		}
96
	}
96
	}
97
 
97
 
98
	public function executerWidget() {
98
	public function executerWidget() {
99
		$referentiel_impose = false;
99
		$referentiel_impose = false;
100
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '') {
100
		if (isset($_GET['referentiel']) && $_GET['referentiel'] != '') {
101
			$this->NS_PROJET = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->NS_PROJET;
101
			$this->NS_PROJET = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->NS_PROJET;
102
			$this->NS_PROJET_VERSION = $this->projetsVersions[$this->NS_PROJET];
102
			$this->NS_PROJET_VERSION = $this->projetsVersions[$this->NS_PROJET];
103
			$referentiel_impose = true;
103
			$referentiel_impose = true;
104
		}
104
		}
105
 
105
 
106
		$widget['squelette'] = $this->projet;
106
		$widget['squelette'] = $this->projet;
107
		$widget['donnees'] = array();
107
		$widget['donnees'] = array();
108
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
108
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
109
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
109
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
110
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
110
		$widget['donnees']['url_ws_obs'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_OBS);
111
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
111
		$widget['donnees']['url_ws_upload'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_UPLOAD);
112
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
112
		$widget['donnees']['url_ws_annuaire'] = sprintf($this->config['chemins']['baseURLServicesAnnuaireTpl'], 'utilisateur/identite-par-courriel/');
113
 
113
 
114
 
114
 
115
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
115
		$widget['donnees']['logo'] = isset($_GET['logo']) ? $_GET['logo'] : 'defaut';
116
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
116
		$widget['donnees']['titre'] = isset($_GET['titre']) ? $_GET['titre'] : 'defaut';
117
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
117
		$widget['donnees']['titre'] = ($widget['donnees']['titre'] == '0') ? '' : $widget['donnees']['titre'];
118
 
118
 
119
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
119
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
120
		if ($this->projet == 'defaut' || $this->projet == 'florileges' || !$this->projetASquelette()) {
120
		if ($this->projet == 'defaut' || $this->projet == 'florileges' || $this->projet == 'sauvages' || !$this->projetASquelette()) {
121
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
121
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
122
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
122
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
123
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
123
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
124
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
124
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
125
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
125
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
126
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
126
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
127
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
127
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
128
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
128
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
129
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
129
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
130
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
130
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
131
			$widget['donnees']['espece_imposee'] = false;
131
			$widget['donnees']['espece_imposee'] = false;
132
			$widget['donnees']['nn_espece_defaut'] = '';
132
			$widget['donnees']['nn_espece_defaut'] = '';
133
			$widget['donnees']['nom_sci_espece_defaut'] = '';
133
			$widget['donnees']['nom_sci_espece_defaut'] = '';
134
			$widget['donnees']['infos_espece'] = '{}';
134
			$widget['donnees']['infos_espece'] = '{}';
135
 
135
 
136
			if ($this->especeEstImposee()) {
136
			if ($this->especeEstImposee()) {
137
				$nom = $this->executerChargementInfosTaxon($_GET['num_nom']);
137
				$nom = $this->executerChargementInfosTaxon($_GET['num_nom']);
138
				$widget['donnees']['espece_imposee'] = true;
138
				$widget['donnees']['espece_imposee'] = true;
139
				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
139
				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
140
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
140
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
141
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
141
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
142
			}
142
			}
143
		}
143
		}
144
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
144
		if ($this->projet != 'defaut' || $this->projetASquelette()) {
145
			if ($this->projet == 'florileges') {
145
			if ($this->projet == 'florileges') {
146
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
146
				$widget['donnees']['taxons'] = $this->recupererListeNoms();
147
			} else {
147
			} else {
148
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
148
				$widget['donnees']['taxons'] = $this->recupererListeNomsSci();
149
			}
149
			}
150
			$widget['donnees']['milieux'] = $this->parserMilieux();
150
			$widget['donnees']['milieux'] = $this->parserMilieux();
151
		}
151
		}
152
		return  $widget;
152
		return  $widget;
153
	}
153
	}
154
 
154
 
155
	private function projetASquelette() {
155
	private function projetASquelette() {
156
		// fonction très simple qui ne teste que si le dossier du projet courant
156
		// fonction très simple qui ne teste que si le dossier du projet courant
157
		// existe, mais elle suffit pour le moment.
157
		// existe, mais elle suffit pour le moment.
158
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
158
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
159
	}
159
	}
160
 
160
 
161
	public function executerTaxons() {
161
	public function executerTaxons() {
162
		$widget['squelette'] = $this->projet.'_taxons';
162
		$widget['squelette'] = $this->projet.'_taxons';
163
		$widget['squelette_ext'] = '.tpl.js';
163
		$widget['squelette_ext'] = '.tpl.js';
164
		$widget['donnees'] = array();
164
		$widget['donnees'] = array();
165
		$nomsAAfficher = $this->recupererListeNomsSci();
165
		$nomsAAfficher = $this->recupererListeNomsSci();
166
		$taxons_tries = array();
166
		$taxons_tries = array();
167
		foreach ($nomsAAfficher as $taxon) {
167
		foreach ($nomsAAfficher as $taxon) {
168
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
168
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
169
		}
169
		}
170
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
170
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
171
		return $widget;
171
		return $widget;
172
	}
172
	}
173
 
173
 
174
	private function recupererListeNomsSci() {
174
	private function recupererListeNomsSci() {
175
		$taxons = $this->recupererListeTaxon();
175
		$taxons = $this->recupererListeTaxon();
176
		if (is_array($taxons)) {
176
		if (is_array($taxons)) {
177
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
177
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
178
		}
178
		}
179
		return $taxons;
179
		return $taxons;
180
	}
180
	}
181
 
181
 
182
	private function recupererListeNoms() {
182
	private function recupererListeNoms() {
183
		$taxons = $this->recupererListeTaxon();
183
		$taxons = $this->recupererListeTaxon();
184
		$nomsAAfficher = array();
184
		$nomsAAfficher = array();
185
		$nomsSpeciaux = array();
185
		$nomsSpeciaux = array();
186
		if (is_array($taxons)) {
186
		if (is_array($taxons)) {
187
			foreach ($taxons as $taxon) {
187
			foreach ($taxons as $taxon) {
188
				$nomSciTitle = $taxon['nom_ret'].
188
				$nomSciTitle = $taxon['nom_ret'].
189
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
189
					($taxon['nom_fr'] != '' ? ' - '.$taxon['nom_fr'] : '' ).
190
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
190
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
191
				$nomFrTitle = $taxon['nom_sel'].
191
				$nomFrTitle = $taxon['nom_sel'].
192
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
192
					($taxon['nom_ret'] != $taxon['nom_sel']? ' - '.$taxon['nom_ret'] : '' ).
193
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
193
					($taxon['nom_fr_autre'] != '' ? ' - '.$taxon['nom_fr_autre'] : '' );
194
 
194
 
195
				if ($taxon['groupe'] == 'special') {
195
				if ($taxon['groupe'] == 'special') {
196
					$nomsSpeciaux[] = array(
196
					$nomsSpeciaux[] = array(
197
						'num_nom' => $taxon['num_nom_sel'],
197
						'num_nom' => $taxon['num_nom_sel'],
198
						'nom_a_afficher' => $taxon['nom_fr'],
198
						'nom_a_afficher' => $taxon['nom_fr'],
199
						'nom_a_sauver' => $taxon['nom_sel'],
199
						'nom_a_sauver' => $taxon['nom_sel'],
200
						'nom_title' => $nomSciTitle,
200
						'nom_title' => $nomSciTitle,
201
						'nom_type' => 'nom-special');
201
						'nom_type' => 'nom-special');
202
				} else {
202
				} else {
203
					$nomsAAfficher[] = array(
203
					$nomsAAfficher[] = array(
204
						'num_nom' => $taxon['num_nom_sel'],
204
						'num_nom' => $taxon['num_nom_sel'],
205
						'nom_a_afficher' => $taxon['nom_sel'],
205
						'nom_a_afficher' => $taxon['nom_sel'],
206
						'nom_a_sauver' => $taxon['nom_sel'],
206
						'nom_a_sauver' => $taxon['nom_sel'],
207
						'nom_title' => $nomSciTitle,
207
						'nom_title' => $nomSciTitle,
208
						'nom_type' => 'nom-sci');
208
						'nom_type' => 'nom-sci');
209
					$nomsAAfficher[] = array(
209
					$nomsAAfficher[] = array(
210
						'num_nom' => $taxon['num_nom_sel'],
210
						'num_nom' => $taxon['num_nom_sel'],
211
						'nom_a_afficher' => $taxon['nom_fr'],
211
						'nom_a_afficher' => $taxon['nom_fr'],
212
						'nom_a_sauver' => $taxon['nom_fr'],
212
						'nom_a_sauver' => $taxon['nom_fr'],
213
						'nom_title' => $nomFrTitle,
213
						'nom_title' => $nomFrTitle,
214
						'nom_type' => 'nom-fr');
214
						'nom_type' => 'nom-fr');
215
				}
215
				}
216
			}
216
			}
217
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
217
			$nomsAAfficher = self::trierTableauMd($nomsAAfficher, array('nom_a_afficher' => SORT_ASC));
218
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
218
			$nomsSpeciaux = self::trierTableauMd($nomsSpeciaux, array('nom_a_afficher' => SORT_ASC));
219
		}
219
		}
220
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
220
		return array('speciaux' => $nomsSpeciaux, 'sci-et-fr' => $nomsAAfficher);
221
	}
221
	}
222
 
222
 
223
	private function recupererListeTaxon() {
223
	private function recupererListeTaxon() {
224
		$taxons = null;
224
		$taxons = null;
225
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
225
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
226
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
226
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
227
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
227
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
228
		} else {
228
		} else {
229
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
229
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
230
		}
230
		}
231
		return $taxons;
231
		return $taxons;
232
	}
232
	}
233
 
233
 
234
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
234
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
235
		$header = null;
235
		$header = null;
236
		$data = array();
236
		$data = array();
237
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
237
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
238
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
238
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
239
				if (!$header) {
239
				if (!$header) {
240
					$header = $row;
240
					$header = $row;
241
				} else {
241
				} else {
242
					$data[] = array_combine($header, $row);
242
					$data[] = array_combine($header, $row);
243
				}
243
				}
244
			}
244
			}
245
			fclose($handle);
245
			fclose($handle);
246
		}
246
		}
247
		return $data;
247
		return $data;
248
	}
248
	}
249
 
249
 
250
	private function parserMilieux() {
250
	private function parserMilieux() {
251
		$infosMilieux = array();
251
		$infosMilieux = array();
252
		if (isset($this->configProjet['milieux'])) {
252
		if (isset($this->configProjet['milieux'])) {
253
			$milieux = explode('|', $this->configProjet['milieux']);
253
			$milieux = explode('|', $this->configProjet['milieux']);
254
			foreach ($milieux as $milieu) {
254
			foreach ($milieux as $milieu) {
255
				$details = explode(';', $milieu);
255
				$details = explode(';', $milieu);
256
				if (isset($details[1])) {
256
				if (isset($details[1])) {
257
					$infosMilieux[$details[0]] = $details[1];
257
					$infosMilieux[$details[0]] = $details[1];
258
				} else {
258
				} else {
259
					$infosMilieux[$details[0]] = '';
259
					$infosMilieux[$details[0]] = '';
260
				}
260
				}
261
			}
261
			}
262
			ksort($infosMilieux);
262
			ksort($infosMilieux);
263
		}
263
		}
264
		return $infosMilieux;
264
		return $infosMilieux;
265
	}
265
	}
266
 
266
 
267
	private function especeEstImposee() {
267
	private function especeEstImposee() {
268
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != '');
268
		return (isset($_GET['num_nom']) && $_GET['num_nom'] != '');
269
	}
269
	}
270
 
270
 
271
	private function executerChargementInfosTaxon($num_nom) {
271
	private function executerChargementInfosTaxon($num_nom) {
272
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
272
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
273
		$infos = json_decode(file_get_contents($url_service_infos));
273
		$infos = json_decode(file_get_contents($url_service_infos));
274
		// trop de champs injectés dans les infos espèces peut
274
		// trop de champs injectés dans les infos espèces peut
275
		// faire planter javascript
275
		// faire planter javascript
276
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet', 
276
		$champs_a_garder = array('id', 'nom_sci','nom_sci_complet',
277
		'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
277
		'famille','nom_retenu.id', 'nom_retenu.libelle', 'num_taxonomique');
278
		$resultat = array();
278
		$resultat = array();
279
		if (isset($infos) && !empty($infos)) {
279
		if (isset($infos) && !empty($infos)) {
280
			$infos = (array)$infos;
280
			$infos = (array)$infos;
281
			if(isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
281
			if(isset($infos['nom_sci']) && $infos['nom_sci'] != '') {
282
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
282
				$resultat = array_intersect_key($infos, array_flip($champs_a_garder));
283
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
283
				$resultat['retenu'] = ($infos['id'] == $infos['nom_retenu.id']) ? "true" : "false";
284
			}	
284
			}
285
		}
285
		}
286
		return $resultat;
286
		return $resultat;
287
	}
287
	}
288
 
288
 
289
	public function executerUploadImage() {
289
	public function executerUploadImage() {
290
		$retour = array(
290
		$retour = array(
291
				'squelette' => $this->projet.'_image',
291
				'squelette' => $this->projet.'_image',
292
				'squelette_ext' => '.tpl.xml',
292
				'squelette_ext' => '.tpl.xml',
293
				'mime' => 'text/xml',
293
				'mime' => 'text/xml',
294
				'donnees' => array(
294
				'donnees' => array(
295
						'urlMiniature' => '',
295
						'urlMiniature' => '',
296
						'imageNom' => '',
296
						'imageNom' => '',
297
						'message' => '',
297
						'message' => '',
298
						'debogage' => ''));
298
						'debogage' => ''));
299
		$message = '';
299
		$message = '';
300
		$debogage = '';
300
		$debogage = '';
301
		if ($_FILES['fichier']['error'] == UPLOAD_ERR_OK) {
301
		if ($_FILES['fichier']['error'] == UPLOAD_ERR_OK) {
302
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
302
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
303
				if ($this->verifierFormatJpeg($_FILES['fichier']['tmp_name'])) {
303
				if ($this->verifierFormatJpeg($_FILES['fichier']['tmp_name'])) {
304
					$dossierStockage = $this->config['chemins']['imagesTempDossier'];
304
					$dossierStockage = $this->config['chemins']['imagesTempDossier'];
305
 
305
 
306
					$nomFichierOriginal = preg_replace('/[.](jpeg|jpg)$/i', '.jpg', strtolower($_FILES['fichier']['name']));
306
					$nomFichierOriginal = preg_replace('/[.](jpeg|jpg)$/i', '.jpg', strtolower($_FILES['fichier']['name']));
307
					$originalChemin = $dossierStockage.$nomFichierOriginal;
307
					$originalChemin = $dossierStockage.$nomFichierOriginal;
308
					$deplacementOk = move_uploaded_file($_FILES['fichier']['tmp_name'], $originalChemin);
308
					$deplacementOk = move_uploaded_file($_FILES['fichier']['tmp_name'], $originalChemin);
309
 
309
 
310
					if ($deplacementOk === true) {
310
					if ($deplacementOk === true) {
311
						$miniatureFichier = str_replace('.jpg', '_min.jpg', $nomFichierOriginal);
311
						$miniatureFichier = str_replace('.jpg', '_min.jpg', $nomFichierOriginal);
312
						$miniatureChemin = $dossierStockage.$miniatureFichier;
312
						$miniatureChemin = $dossierStockage.$miniatureFichier;
313
 
313
 
314
						// Parametres
314
						// Parametres
315
						$largeurIdeale = 100;
315
						$largeurIdeale = 100;
316
						$hauteurIdeale = 100;
316
						$hauteurIdeale = 100;
317
						$qualite = 85;
317
						$qualite = 85;
318
 
318
 
319
						// Calcul de la hauteur et de la largeur optimale de la miniature
319
						// Calcul de la hauteur et de la largeur optimale de la miniature
320
						$taillesImgOriginale = getimagesize($originalChemin);
320
						$taillesImgOriginale = getimagesize($originalChemin);
321
						$largeurOrigine = $taillesImgOriginale[0];
321
						$largeurOrigine = $taillesImgOriginale[0];
322
						$hauteurOrigine = $taillesImgOriginale[1];
322
						$hauteurOrigine = $taillesImgOriginale[1];
323
 
323
 
324
						$largeurMin = $largeurIdeale;
324
						$largeurMin = $largeurIdeale;
325
						$hauteurMin = (int) ($hauteurOrigine * ($largeurIdeale / $largeurOrigine));
325
						$hauteurMin = (int) ($hauteurOrigine * ($largeurIdeale / $largeurOrigine));
326
						if ($hauteurMin > $hauteurIdeale) {
326
						if ($hauteurMin > $hauteurIdeale) {
327
							$hauteurMin = $hauteurIdeale;
327
							$hauteurMin = $hauteurIdeale;
328
							$largeurMin = (int)($largeurOrigine * ($hauteurMin / $hauteurOrigine));
328
							$largeurMin = (int)($largeurOrigine * ($hauteurMin / $hauteurOrigine));
329
						}
329
						}
330
 
330
 
331
						// Création de la miniature
331
						// Création de la miniature
332
						$imageOriginale = imagecreatefromjpeg($originalChemin);
332
						$imageOriginale = imagecreatefromjpeg($originalChemin);
333
						$imageMiniature = imagecreatetruecolor($largeurMin, $hauteurMin);
333
						$imageMiniature = imagecreatetruecolor($largeurMin, $hauteurMin);
334
						$couleurFond = imagecolorallocate($imageMiniature, 255, 255, 255);
334
						$couleurFond = imagecolorallocate($imageMiniature, 255, 255, 255);
335
						imagefill($imageMiniature, 0, 0, $couleurFond);
335
						imagefill($imageMiniature, 0, 0, $couleurFond);
336
						imagecopyresized($imageMiniature, $imageOriginale, 0, 0, 0, 0, $largeurMin, $hauteurMin, $largeurOrigine, $hauteurOrigine);
336
						imagecopyresized($imageMiniature, $imageOriginale, 0, 0, 0, 0, $largeurMin, $hauteurMin, $largeurOrigine, $hauteurOrigine);
337
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
337
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
338
						imagedestroy($imageMiniature);
338
						imagedestroy($imageMiniature);
339
						imagedestroy($imageOriginale);
339
						imagedestroy($imageOriginale);
340
 
340
 
341
						// Retour des infos
341
						// Retour des infos
342
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
342
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
343
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
343
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
344
					} else {
344
					} else {
345
						$message = "L'image n'a pu être déplacé sur le serveur.";
345
						$message = "L'image n'a pu être déplacé sur le serveur.";
346
					}
346
					}
347
				} else {
347
				} else {
348
					$message = "L'image n'est pas au format JPEG.";
348
					$message = "L'image n'est pas au format JPEG.";
349
				}
349
				}
350
			} else {
350
			} else {
351
				$message = "L'image n'a pu être téléversée.";
351
				$message = "L'image n'a pu être téléversée.";
352
				$debogage = $message.print_r($_FILES, true);
352
				$debogage = $message.print_r($_FILES, true);
353
			}
353
			}
354
		} else {
354
		} else {
355
			if ($_FILES['fichier']['error'] == UPLOAD_ERR_FORM_SIZE) {
355
			if ($_FILES['fichier']['error'] == UPLOAD_ERR_FORM_SIZE) {
356
				$message = "L'image téléversée excède la taille maximum autorisée.".
356
				$message = "L'image téléversée excède la taille maximum autorisée.".
357
						"Veuillez modifier votre image avant de la téléverser à nouveau.";
357
						"Veuillez modifier votre image avant de la téléverser à nouveau.";
358
			} else {
358
			} else {
359
				$message = "Une erreur de transfert a eu lieu (téléversement interrompu).";
359
				$message = "Une erreur de transfert a eu lieu (téléversement interrompu).";
360
			}
360
			}
361
			$debogage = "Code erreur : {$_FILES['fichier']['error']}. ".
361
			$debogage = "Code erreur : {$_FILES['fichier']['error']}. ".
362
					"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
362
					"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
363
		}
363
		}
364
		// Retour des infos
364
		// Retour des infos
365
		$retour['donnees']['message'] = $message;
365
		$retour['donnees']['message'] = $message;
366
		$retour['donnees']['debogage'] = $debogage;
366
		$retour['donnees']['debogage'] = $debogage;
367
		return $retour;
367
		return $retour;
368
	}
368
	}
369
 
369
 
370
	// Il ne faut pas utiliser l'index type du tableau files pour tester
370
	// Il ne faut pas utiliser l'index type du tableau files pour tester
371
	// si une image est en jpeg car le type renvoyé par les navigateurs
371
	// si une image est en jpeg car le type renvoyé par les navigateurs
372
	// peut varier (ex. sous ie qui renvoie image/pjpeg
372
	// peut varier (ex. sous ie qui renvoie image/pjpeg
373
	private function verifierFormatJpeg($chemin) {
373
	private function verifierFormatJpeg($chemin) {
374
		// get imagesize renvoie un résultat consistant par contre
374
		// get imagesize renvoie un résultat consistant par contre
375
		$infos = getimagesize($chemin, $infos);
375
		$infos = getimagesize($chemin, $infos);
376
		return (isset($infos['mime']) && $infos['mime'] == 'image/jpeg');
376
		return (isset($infos['mime']) && $infos['mime'] == 'image/jpeg');
377
	}
377
	}
378
 
378
 
379
	private function array2js($array,$show_keys) {
379
	private function array2js($array,$show_keys) {
380
		$tableauJs = '{}';
380
		$tableauJs = '{}';
381
		if (!empty($array)) {
381
		if (!empty($array)) {
382
			$total = count($array) - 1;
382
			$total = count($array) - 1;
383
			$i = 0;
383
			$i = 0;
384
			$dimensions = array();
384
			$dimensions = array();
385
			foreach ($array as $key => $value) {
385
			foreach ($array as $key => $value) {
386
				if (is_array($value)) {
386
				if (is_array($value)) {
387
					$dimensions[$i] = array2js($value,$show_keys);
387
					$dimensions[$i] = array2js($value,$show_keys);
388
					if ($show_keys) {
388
					if ($show_keys) {
389
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
389
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
390
					}
390
					}
391
				} else {
391
				} else {
392
					$dimensions[$i] = '"'.addslashes($value).'"';
392
					$dimensions[$i] = '"'.addslashes($value).'"';
393
					if ($show_keys) {
393
					if ($show_keys) {
394
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
394
						$dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
395
					}
395
					}
396
				}
396
				}
397
				if ($i == 0) {
397
				if ($i == 0) {
398
					$dimensions[$i] = '{'.$dimensions[$i];
398
					$dimensions[$i] = '{'.$dimensions[$i];
399
				}
399
				}
400
				if ($i == $total) {
400
				if ($i == $total) {
401
					$dimensions[$i].= '}';
401
					$dimensions[$i].= '}';
402
				}
402
				}
403
				$i++;
403
				$i++;
404
			}
404
			}
405
			$tableauJs = implode(',', $dimensions);
405
			$tableauJs = implode(',', $dimensions);
406
		}
406
		}
407
		return $tableauJs;
407
		return $tableauJs;
408
	}
408
	}
409
}
409
}
410
?>
410
?>