Subversion Repositories eFlore/Applications.cel

Rev

Rev 1050 | Rev 1355 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1050 Rev 1345
Line 19... Line 19...
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 {
Line 22... Line 22...
22
 
22
 
23
	const DS = DIRECTORY_SEPARATOR;
23
	const DS = DIRECTORY_SEPARATOR;
24
	const PROJET_DEFAUT = 'biodiversite34';
24
	const PROJET_DEFAUT = 'defaut';
-
 
25
	const WS_SAISIE = "CelWidgetSaisie";
-
 
26
	const WS_NOM = "noms";
-
 
27
	const NS_PROJET = "bdtfx";
-
 
28
	const NS_PROJET_VERSION = "1.01";
Line 25... Line 29...
25
	const WS_SAISIE = "CelWidgetSaisie";
29
	const EFLORE_API_VERSION = "0.1";
26
 
30
 
Line 27... Line 31...
27
	private $projet = null;
31
	private $projet = null;
Line 32... Line 36...
32
	 */
36
	 */
33
	public function executer() {
37
	public function executer() {
34
		$retour = null;
38
		$retour = null;
35
		extract($this->parametres);
39
		extract($this->parametres);
Line 36... Line -...
36
 
-
 
37
		if (!isset($projet)) {
40
 
38
			$this->projet = self::PROJET_DEFAUT;
-
 
39
		} else {
-
 
40
			$this->projet = $projet;
-
 
41
		}
41
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
Line 42... Line 42...
42
		$this->chargerConfigProjet();
42
		$this->chargerConfigProjet();
43
 
43
 
44
		$service = (isset($service)) ? $service : $this->projet;
44
		$service = isset($service) ? $service : 'widget';
45
		$methode = $this->traiterNomMethodeExecuter($service);
45
		$methode = $this->traiterNomMethodeExecuter($service);
46
		if (method_exists($this, $methode)) {
46
		if (method_exists($this, $methode)) {
47
			$retour = $this->$methode();
47
			$retour = $this->$methode();
Line 71... Line 71...
71
		if (file_exists($fichier_config)) {
71
		if (file_exists($fichier_config)) {
72
			if (!$this->configProjet	= parse_ini_file($fichier_config)) {
72
			if (!$this->configProjet	= parse_ini_file($fichier_config)) {
73
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
73
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
74
			}
74
			}
75
		} else {
75
		} else {
76
			$this->messages[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
76
			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
77
		}
77
		}
78
	}
78
	}
Line -... Line 79...
-
 
79
 
-
 
80
	public function executerWidget() {
-
 
81
		$widget['squelette'] = $this->projet;
-
 
82
		$widget['donnees'] = array();
-
 
83
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
84
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
85
 
-
 
86
 
-
 
87
		if ($this->projet == 'defaut') {
-
 
88
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
-
 
89
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, self::NS_PROJET, self::WS_NOM);
-
 
90
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
-
 
91
			$widget['donnees']['ns_referentiel'] = self::NS_PROJET.':'.self::NS_PROJET_VERSION;
-
 
92
			$widget['donnees']['ns_version'] = self::NS_PROJET_VERSION;
-
 
93
		} else {
-
 
94
			$widget['donnees']['taxons'] = $this->recupererListeTaxon();
-
 
95
			$widget['donnees']['milieux'] = $this->parserMilieux();
-
 
96
		}
-
 
97
		return  $widget;
-
 
98
	}
79
 
99
 
80
	public function executerTaxons() {
100
	public function executerTaxons() {
81
		$widget['squelette'] = $this->projet.'_taxons';
101
		$widget['squelette'] = $this->projet.'_taxons';
82
		$widget['squelette_ext'] = '.tpl.js';
102
		$widget['squelette_ext'] = '.tpl.js';
83
		$widget['donnees'] = array();
-
 
84
		$methode = 'recupererListeTaxon'.str_replace(' ', '', ucwords(str_replace('-', ' ', strtolower($this->projet))));
103
		$widget['donnees'] = array();
85
		$taxons = $this->$methode();
104
		$taxons = $this->recupererListeTaxon();
86
		$taxons_tries = array();
105
		$taxons_tries = array();
87
		foreach ($taxons as $taxon) {
106
		foreach ($taxons as $taxon) {
88
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
107
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
89
		}
108
		}
90
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
109
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
91
		return  $widget;
110
		return  $widget;
Line -... Line 111...
-
 
111
	}
-
 
112
 
-
 
113
	private function recupererListeTaxon() {
-
 
114
		$taxons = null;
-
 
115
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
-
 
116
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
117
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
118
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
-
 
119
		} else {
-
 
120
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
121
		}
-
 
122
		return $taxons;
-
 
123
	}
-
 
124
 
-
 
125
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
-
 
126
		$header = NULL;
-
 
127
		$data = array();
-
 
128
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
-
 
129
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
-
 
130
				if (!$header) {
-
 
131
					$header = $row;
-
 
132
				} else {
-
 
133
					$data[] = array_combine($header, $row);
-
 
134
				}
-
 
135
			}
-
 
136
			fclose($handle);
-
 
137
		}
-
 
138
		return $data;
-
 
139
	}
-
 
140
 
-
 
141
	private function parserMilieux() {
-
 
142
		$infosMilieux = array();
-
 
143
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
144
		foreach ($milieux as $milieu) {
-
 
145
			$details = explode(';', $milieu);
-
 
146
			if (isset($details[1])) {
-
 
147
				$infosMilieux[$details[0]] = $details[1];
-
 
148
			} else {
-
 
149
				$infosMilieux[$details[0]] = '';
-
 
150
			}
-
 
151
		}
-
 
152
		ksort($infosMilieux);
-
 
153
		return $infosMilieux;
92
	}
154
	}
93
 
155
 
-
 
156
	public function executerUploadImage() {
-
 
157
		$retour = array(
-
 
158
				'squelette' => $this->projet.'_image',
-
 
159
				'squelette_ext' => '.tpl.xml',
-
 
160
				'mime' => 'text/xml',
-
 
161
				'donnees' => array(
-
 
162
						'urlMiniature' => '',
-
 
163
						'imageNom' => '',
-
 
164
						'message' => '',
-
 
165
						'debogage' => ''));
94
	public function executerUploadImage() {
166
		$message = '';
95
		$retour = array();
167
		$debogage = '';
96
		if ($_FILES['fichier']['error'] == 0) {
168
		if ($_FILES['fichier']['error'] == UPLOAD_ERR_OK) {
97
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
169
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
Line 98... Line 170...
98
				if ($_FILES['fichier']['type'] == 'image/jpeg') {
170
				if ($_FILES['fichier']['type'] == 'image/jpeg') {
Line 132... Line 204...
132
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
204
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
133
						imagedestroy($imageMiniature);
205
						imagedestroy($imageMiniature);
134
						imagedestroy($imageOriginale);
206
						imagedestroy($imageOriginale);
Line 135... Line 207...
135
 
207
 
136
						// Retour des infos
-
 
137
						$retour['squelette'] = $this->projet.'_image';
-
 
138
						$retour['squelette_ext'] = '.tpl.xml';
208
						// Retour des infos
139
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
209
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
140
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
-
 
141
						$retour['mime'] = 'text/xml';
210
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
142
					} else {
211
					} else {
143
						$this->messages[] = "L'image n'a pu être déplacé sur le serveur.";
212
						$message = "L'image n'a pu être déplacé sur le serveur.";
144
					}
213
					}
145
				} else {
214
				} else {
146
					$this->messages[] = "L'image n'est pas au format JPEG.";
215
					$message = "L'image n'est pas au format JPEG.";
147
				}
216
				}
148
			} else {
217
			} else {
-
 
218
				$message = "L'image n'a pu être téléversée.";
149
				$this->messages[] = "L'image n'a pu être uploadée :".print_r($_FILES, true);
219
				$debogage = $message.print_r($_FILES, true);
150
			}
220
			}
151
		} else {
-
 
152
			$this->messages[] = "Une erreur de transfert a eu lieu (téléversement interrompu). ".
221
		} else {
153
				"Code erreur : {$_FILES['fichier']['error']}. ".
-
 
154
				"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
-
 
155
		}
-
 
156
		return $retour;
-
 
157
	}
-
 
158
 
-
 
159
	public function executerBiodiversite34() {
-
 
160
		$widget['squelette'] = $this->projet;
-
 
161
		$widget['donnees'] = array();
-
 
162
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
163
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
164
 
-
 
165
		$widget['donnees']['taxons'] = $this->recupererListeTaxonBiodiversite34();
-
 
166
		$widget['donnees']['milieux'] = $this->parserMilieuxBiodiversite34();
-
 
167
		return  $widget;
-
 
168
	}
-
 
169
 
-
 
170
	private function parserMilieuxBiodiversite34() {
-
 
171
		$infosMilieux = array();
-
 
172
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
173
		foreach ($milieux as $milieu) {
-
 
174
			$details = explode(';', $milieu);
-
 
175
			if (isset($details[1])) {
-
 
176
				$infosMilieux[$details[0]] = $details[1];
-
 
177
			} else {
-
 
178
				$infosMilieux[$details[0]] = '';
-
 
179
			}
-
 
180
		}
-
 
181
		ksort($infosMilieux);
-
 
182
		return $infosMilieux;
-
 
183
	}
-
 
184
 
-
 
185
	private function recupererListeTaxonBiodiversite34() {
-
 
186
		$taxons = null;
-
 
187
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'biodiversite34_taxons.tsv';
-
 
188
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
189
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
190
		} else {
222
			if ($_FILES['fichier']['error'] == UPLOAD_ERR_FORM_SIZE) {
191
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
192
		}
-
 
193
 
223
				$message = "L'image téléversée excède la taille maximum autorisée.".
194
		$taxons_tries = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
-
 
195
 
-
 
196
		return $taxons_tries;
-
 
197
	}
-
 
198
 
-
 
199
	public function executerSauvages() {
-
 
200
		$widget['squelette'] = $this->projet;
-
 
201
		$widget['donnees'] = array();
-
 
202
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
-
 
203
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
-
 
204
 
-
 
205
		$widget['donnees']['taxons'] = $this->recupererListeTaxonSauvages();
-
 
206
		$widget['donnees']['milieux'] = $this->parserMilieuxSauvages();
-
 
207
		return  $widget;
-
 
208
	}
-
 
209
 
-
 
210
	private function parserMilieuxSauvages() {
-
 
211
		$infosMilieux = array();
-
 
212
		$milieux = explode('|', $this->configProjet['milieux']);
-
 
213
		foreach ($milieux as $milieu) {
-
 
214
			$details = explode(';', $milieu);
-
 
215
			if (isset($details[1])) {
-
 
216
				$infosMilieux[$details[0]] = $details[1];
224
						"Veuillez modifier votre image avant de la téléverser à nouveau.";
217
			} else {
225
			} else {
218
				$infosMilieux[$details[0]] = '';
-
 
219
			}
226
				$message = "Une erreur de transfert a eu lieu (téléversement interrompu).";
220
		}
-
 
221
		return $infosMilieux;
-
 
222
	}
-
 
223
 
-
 
224
	private function recupererListeTaxonSauvages() {
-
 
225
		$taxons = null;
-
 
226
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.'sauvages_taxons.tsv';
-
 
227
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
-
 
228
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
-
 
229
		} else {
227
			}
230
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
-
 
231
		}
-
 
232
		return $taxons;
-
 
233
	}
-
 
234
 
-
 
235
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
-
 
236
		$header = NULL;
-
 
237
	    $data = array();
-
 
238
	    if (($handle = fopen($fichier, 'r')) !== FALSE) {
-
 
239
	        while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
-
 
240
	            if (!$header) {
-
 
241
	                $header = $row;
-
 
242
	            } else {
228
			$debogage = "Code erreur : {$_FILES['fichier']['error']}. ".
243
	                $data[] = array_combine($header, $row);
-
 
244
	            }
-
 
245
	        }
-
 
246
	        fclose($handle);
229
					"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
-
 
230
		}
-
 
231
		// Retour des infos
-
 
232
		$retour['donnees']['message'] = $message;
247
	    }
233
		$retour['donnees']['debogage'] = $debogage;
248
	    return $data;
234
		return $retour;
249
	}
235
	}
250
}
236
}
-
 
237
?>
251
238