Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1475 Rev 1476
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_NOM = "noms";
26
	const WS_NOM = "noms";
27
	const NS_PROJET = "bdtfx";
-
 
28
	const NS_PROJET_VERSION = "1.01";
27
	private $NS_PROJET_VERSION = "1.01";
29
	const EFLORE_API_VERSION = "0.1";
28
	const EFLORE_API_VERSION = "0.1";
-
 
29
	private $NS_PROJET = "bdtfx";
-
 
30
 
30
 
31
	private $projetsVersions = array();
31
	private $projet = null;
32
	private $projet = null;
32
	private $configProjet = null;
33
	private $configProjet = null;
33
 
34
 
34
	/**
35
	/**
35
	 * Méthode appelée par défaut pour charger ce widget.
36
	 * Méthode appelée par défaut pour charger ce widget.
36
	 */
37
	 */
37
	public function executer() {
38
	public function executer() {
38
		$retour = null;
39
		$retour = null;
39
		extract($this->parametres);
40
		extract($this->parametres);
40
 
41
 
41
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
42
		$this->projet = isset($projet) ? $projet : self::PROJET_DEFAUT;
42
		$this->chargerConfigProjet();
43
		$this->chargerConfigProjet();
-
 
44
		$this->chargerProjetsVersion();
43
 
45
 
44
		$service = isset($service) ? $service : 'widget';
46
		$service = isset($service) ? $service : 'widget';
45
		$methode = $this->traiterNomMethodeExecuter($service);
47
		$methode = $this->traiterNomMethodeExecuter($service);
46
		if (method_exists($this, $methode)) {
48
		if (method_exists($this, $methode)) {
47
			$retour = $this->$methode();
49
			$retour = $this->$methode();
48
		} else {
50
		} else {
49
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
51
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
50
		}
52
		}
51
 
53
 
52
		$contenu = null;
54
		$contenu = null;
53
		$mime = null;
55
		$mime = null;
54
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
56
		if (is_array($retour) && array_key_exists('squelette', $retour)) {
55
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
57
			$ext = (isset($retour['squelette_ext'])) ? $retour['squelette_ext'] : '.tpl.html';
56
			if($this->projetASquelette()) {
58
			if($this->projetASquelette()) {
57
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
59
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet.self::DS.$retour['squelette'].$ext;
58
			} else {
60
			} else {
59
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
61
				$squelette = dirname(__FILE__).self::DS.'squelettes'.self::DS.'defaut'.self::DS.'defaut'.$ext;
60
			}
62
			}
61
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
63
			$contenu = $this->traiterSquelettePhp($squelette, $retour['donnees']);
62
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
64
			$mime = isset($retour['mime']) ? $retour['mime'] : null;
63
		} else {
65
		} else {
64
			if (count($this->messages) == 0) {
66
			if (count($this->messages) == 0) {
65
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format.";
67
				$this->messages[] = "La méthode du sous-service ne renvoie pas les données dans le bon format.";
66
			}
68
			}
67
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
69
			$contenu = 'Un problème est survenu : '.print_r($this->messages, true);
68
		}
70
		}
69
 
71
 
70
		$this->envoyer($contenu, $mime);
72
		$this->envoyer($contenu, $mime);
71
	}
73
	}
72
 
74
 
73
	private function chargerConfigProjet() {
75
	private function chargerConfigProjet() {
74
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
76
		$fichier_config = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'.ini';
75
		if (file_exists($fichier_config)) {
77
		if (file_exists($fichier_config)) {
76
			if (!$this->configProjet	= parse_ini_file($fichier_config)) {
78
			if (!$this->configProjet	= parse_ini_file($fichier_config)) {
77
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
79
				$this->messages[] = "Le fichier ini '$fichier_config' du projet n'a pu être chargé.";
78
			}
80
			}
79
		} else {
81
		} else {
80
			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
82
			$this->debug[] = "Le fichier ini '$fichier_config' du projet n'existe pas.";
81
		}
83
		}
82
	}
84
	}
-
 
85
	
-
 
86
	private function chargerProjetsVersion() {
-
 
87
		foreach ($this->configProjet as $config => $valeur) {
-
 
88
			if(strstr($config,'.version')) {
-
 
89
				$this->projetsVersions[str_replace('.version', '', $config)] = $valeur;
-
 
90
			}
-
 
91
		}
-
 
92
	}
83
 
93
 
-
 
94
	public function executerWidget() {
-
 
95
		$referentiel_impose = false;
-
 
96
		if(isset($_GET['referentiel']) && $_GET['referentiel'] != '') {
-
 
97
			$this->NS_PROJET = isset($_GET['referentiel']) && $_GET['referentiel'] != '' ? $_GET['referentiel'] : $this->NS_PROJET;
-
 
98
			$this->NS_PROJET_VERSION = $this->projetsVersions[$this->NS_PROJET];
-
 
99
			$referentiel_impose = true;
-
 
100
		}
84
	public function executerWidget() {
101
		
85
		$widget['squelette'] = $this->projet;
102
		$widget['squelette'] = $this->projet;
86
		$widget['donnees'] = array();
103
		$widget['donnees'] = array();
87
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
104
		$widget['donnees']['url_base'] = sprintf($this->config['chemins']['baseURLAbsoluDyn'], '');
88
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
105
		$widget['donnees']['url_ws_saisie'] = sprintf($this->config['chemins']['baseURLServicesCelTpl'], self::WS_SAISIE);
89
 
106
 
90
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
107
		// cas du projet par défaut ou bien d'un projet n'ayant pas de squelette spécifique
91
		if ($this->projet == 'defaut' || !$this->projetASquelette()) {
108
		if ($this->projet == 'defaut' || !$this->projetASquelette()) {
92
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
109
			$urlWsNsTpl = $this->config['chemins']['baseURLServicesEfloreTpl'];
93
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, self::NS_PROJET, self::WS_NOM);
110
			$urlWsNs = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, $this->NS_PROJET, self::WS_NOM);
-
 
111
			$urlWsNsSansRef = sprintf($urlWsNsTpl, self::EFLORE_API_VERSION, '{referentiel}', self::WS_NOM);
94
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
112
			$widget['donnees']['url_ws_autocompletion_ns'] = $urlWsNs;
-
 
113
			$widget['donnees']['url_ws_autocompletion_ns_tpl'] = $urlWsNsSansRef;
95
			$widget['donnees']['ns_referentiel'] = self::NS_PROJET.':'.self::NS_PROJET_VERSION;
114
			$widget['donnees']['ns_referentiel'] = $this->NS_PROJET.':'.$this->NS_PROJET_VERSION;
-
 
115
			$widget['donnees']['ns_projet'] = $this->NS_PROJET;
96
			$widget['donnees']['ns_version'] = self::NS_PROJET_VERSION;
116
			$widget['donnees']['ns_version'] = $this->NS_PROJET_VERSION;
-
 
117
			$widget['donnees']['referentiel_impose'] = $referentiel_impose;
-
 
118
			$widget['donnees']['projets_versions'] = $this->projetsVersions;
97
			if(self::especeEstImposee()) {
119
			if(self::especeEstImposee()) {
98
				$nom = self::executerChargementInfosTaxon($_GET['num_nom']);
120
				$nom = self::executerChargementInfosTaxon($_GET['num_nom']);
99
				$widget['donnees']['espece_imposee'] = true;
121
				$widget['donnees']['espece_imposee'] = true;
100
				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
122
				$widget['donnees']['nn_espece_defaut'] = $_GET['num_nom'];
101
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
123
				$widget['donnees']['nom_sci_espece_defaut'] = $nom['nom_sci'];
102
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
124
				$widget['donnees']['infos_espece'] = $this->array2js($nom, true);
103
			} else {
125
			} else {
104
				$widget['donnees']['espece_imposee'] = false;
126
				$widget['donnees']['espece_imposee'] = false;
105
				$widget['donnees']['nn_espece_defaut'] = '';
127
				$widget['donnees']['nn_espece_defaut'] = '';
106
				$widget['donnees']['nom_sci_espece_defaut'] = '';
128
				$widget['donnees']['nom_sci_espece_defaut'] = '';
107
				$widget['donnees']['infos_espece'] = array();
129
				$widget['donnees']['infos_espece'] = array();
108
			}
130
			}
109
		} else {
131
		} else {
110
			$widget['donnees']['taxons'] = $this->recupererListeTaxon();
132
			$widget['donnees']['taxons'] = $this->recupererListeTaxon();
111
			$widget['donnees']['milieux'] = $this->parserMilieux();
133
			$widget['donnees']['milieux'] = $this->parserMilieux();
112
		}
134
		}
113
		return  $widget;
135
		return  $widget;
114
	}
136
	}
115
	
137
	
116
	private function projetASquelette() {
138
	private function projetASquelette() {
117
		// fonction très simple qui ne teste que si le dossier du projet courant 
139
		// fonction très simple qui ne teste que si le dossier du projet courant 
118
		// existe, mais elle suffit pour le moment.
140
		// existe, mais elle suffit pour le moment.
119
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
141
		return file_exists(dirname(__FILE__).self::DS.'squelettes'.self::DS.$this->projet);
120
	}
142
	}
121
 
143
 
122
	public function executerTaxons() {
144
	public function executerTaxons() {
123
		$widget['squelette'] = $this->projet.'_taxons';
145
		$widget['squelette'] = $this->projet.'_taxons';
124
		$widget['squelette_ext'] = '.tpl.js';
146
		$widget['squelette_ext'] = '.tpl.js';
125
		$widget['donnees'] = array();
147
		$widget['donnees'] = array();
126
		$taxons = $this->recupererListeTaxon();
148
		$taxons = $this->recupererListeTaxon();
127
		$taxons_tries = array();
149
		$taxons_tries = array();
128
		foreach ($taxons as $taxon) {
150
		foreach ($taxons as $taxon) {
129
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
151
			$taxons_tries[$taxon['num_nom_sel']] = $taxon;
130
		}
152
		}
131
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
153
		$widget['donnees']['taxons'] = json_encode($taxons_tries);
132
		return  $widget;
154
		return  $widget;
133
	}
155
	}
134
 
156
 
135
	private function recupererListeTaxon() {
157
	private function recupererListeTaxon() {
136
		$taxons = null;
158
		$taxons = null;
137
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
159
		$fichier_tsv = dirname(__FILE__).self::DS.'configurations'.self::DS.$this->projet.'_taxons.tsv';
138
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
160
		if (file_exists($fichier_tsv) && is_readable($fichier_tsv)) {
139
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
161
			$taxons = $this->decomposerFichierTsv($fichier_tsv);
140
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
162
			$taxons = self::trierTableauMd($taxons, array('nom_fr' => SORT_ASC));
141
		} else {
163
		} else {
142
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
164
			$this->debug[] = "Impossible d'ouvrir le fichier '$fichier_tsv'.";
143
		}
165
		}
144
		return $taxons;
166
		return $taxons;
145
	}
167
	}
146
 
168
 
147
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
169
	private function decomposerFichierTsv($fichier, $delimiter = "\t"){
148
		$header = NULL;
170
		$header = NULL;
149
		$data = array();
171
		$data = array();
150
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
172
		if (($handle = fopen($fichier, 'r')) !== FALSE) {
151
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
173
			while (($row = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
152
				if (!$header) {
174
				if (!$header) {
153
					$header = $row;
175
					$header = $row;
154
				} else {
176
				} else {
155
					$data[] = array_combine($header, $row);
177
					$data[] = array_combine($header, $row);
156
				}
178
				}
157
			}
179
			}
158
			fclose($handle);
180
			fclose($handle);
159
		}
181
		}
160
		return $data;
182
		return $data;
161
	}
183
	}
162
 
184
 
163
	private function parserMilieux() {
185
	private function parserMilieux() {
164
		$infosMilieux = array();
186
		$infosMilieux = array();
165
		$milieux = explode('|', $this->configProjet['milieux']);
187
		$milieux = explode('|', $this->configProjet['milieux']);
166
		foreach ($milieux as $milieu) {
188
		foreach ($milieux as $milieu) {
167
			$details = explode(';', $milieu);
189
			$details = explode(';', $milieu);
168
			if (isset($details[1])) {
190
			if (isset($details[1])) {
169
				$infosMilieux[$details[0]] = $details[1];
191
				$infosMilieux[$details[0]] = $details[1];
170
			} else {
192
			} else {
171
				$infosMilieux[$details[0]] = '';
193
				$infosMilieux[$details[0]] = '';
172
			}
194
			}
173
		}
195
		}
174
		ksort($infosMilieux);
196
		ksort($infosMilieux);
175
		return $infosMilieux;
197
		return $infosMilieux;
176
	}
198
	}
177
	
199
	
178
	private function especeEstImposee() {
200
	private function especeEstImposee() {
179
		return isset($_GET['num_nom']) && $_GET['num_nom'] != '';
201
		return isset($_GET['num_nom']) && $_GET['num_nom'] != '';
180
	}
202
	}
181
	
203
	
182
	private function executerChargementInfosTaxon($num_nom) {
204
	private function executerChargementInfosTaxon($num_nom) {
183
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $num_nom);
205
		$url_service_infos = sprintf($this->config['chemins']['infosTaxonUrl'], $this->NS_PROJET, $num_nom);
184
		$infos = json_decode(file_get_contents($url_service_infos));
206
		$infos = json_decode(file_get_contents($url_service_infos));
185
		$resultat = array();
207
		$resultat = array();
186
		if(isset($infos) && !empty($infos)) {
208
		if(isset($infos) && !empty($infos)) {
187
			$infos = (array)$infos;
209
			$infos = (array)$infos;
188
			$resultat = (isset($infos['nom_sci']) && $infos['nom_sci'] != '') ? $infos : array();
210
			$resultat = (isset($infos['nom_sci']) && $infos['nom_sci'] != '') ? $infos : array();
189
		}
211
		}
190
		return $resultat;
212
		return $resultat;
191
	}
213
	}
192
 
214
 
193
	public function executerUploadImage() {
215
	public function executerUploadImage() {
194
		$retour = array(
216
		$retour = array(
195
				'squelette' => $this->projet.'_image',
217
				'squelette' => $this->projet.'_image',
196
				'squelette_ext' => '.tpl.xml',
218
				'squelette_ext' => '.tpl.xml',
197
				'mime' => 'text/xml',
219
				'mime' => 'text/xml',
198
				'donnees' => array(
220
				'donnees' => array(
199
						'urlMiniature' => '',
221
						'urlMiniature' => '',
200
						'imageNom' => '',
222
						'imageNom' => '',
201
						'message' => '',
223
						'message' => '',
202
						'debogage' => ''));
224
						'debogage' => ''));
203
		$message = '';
225
		$message = '';
204
		$debogage = '';
226
		$debogage = '';
205
		if ($_FILES['fichier']['error'] == UPLOAD_ERR_OK) {
227
		if ($_FILES['fichier']['error'] == UPLOAD_ERR_OK) {
206
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
228
			if (is_uploaded_file($_FILES['fichier']['tmp_name'])) {
207
				if ($this->verifierFormatJpeg($_FILES['fichier']['tmp_name'])) {
229
				if ($this->verifierFormatJpeg($_FILES['fichier']['tmp_name'])) {
208
					$dossierStockage = $this->config['chemins']['imagesTempDossier'];
230
					$dossierStockage = $this->config['chemins']['imagesTempDossier'];
209
 
231
 
210
					$nomFichierOriginal = preg_replace('/[.](jpeg|jpg)$/i', '.jpg', strtolower($_FILES['fichier']['name']));
232
					$nomFichierOriginal = preg_replace('/[.](jpeg|jpg)$/i', '.jpg', strtolower($_FILES['fichier']['name']));
211
					$originalChemin = $dossierStockage.$nomFichierOriginal;
233
					$originalChemin = $dossierStockage.$nomFichierOriginal;
212
					$deplacementOk = move_uploaded_file($_FILES['fichier']['tmp_name'], $originalChemin);
234
					$deplacementOk = move_uploaded_file($_FILES['fichier']['tmp_name'], $originalChemin);
213
 
235
 
214
					if ($deplacementOk === true) {
236
					if ($deplacementOk === true) {
215
						$miniatureFichier = str_replace('.jpg', '_min.jpg', $nomFichierOriginal);
237
						$miniatureFichier = str_replace('.jpg', '_min.jpg', $nomFichierOriginal);
216
						$miniatureChemin = $dossierStockage.$miniatureFichier;
238
						$miniatureChemin = $dossierStockage.$miniatureFichier;
217
 
239
 
218
						// Parametres
240
						// Parametres
219
						$largeurIdeale = 100;
241
						$largeurIdeale = 100;
220
						$hauteurIdeale = 100;
242
						$hauteurIdeale = 100;
221
						$qualite = 85;
243
						$qualite = 85;
222
 
244
 
223
						// Calcul de la hauteur et de la largeur optimale de la miniature
245
						// Calcul de la hauteur et de la largeur optimale de la miniature
224
						$taillesImgOriginale = getimagesize($originalChemin);
246
						$taillesImgOriginale = getimagesize($originalChemin);
225
						$largeurOrigine = $taillesImgOriginale[0];
247
						$largeurOrigine = $taillesImgOriginale[0];
226
						$hauteurOrigine = $taillesImgOriginale[1];
248
						$hauteurOrigine = $taillesImgOriginale[1];
227
 
249
 
228
						$largeurMin = $largeurIdeale;
250
						$largeurMin = $largeurIdeale;
229
						$hauteurMin = (int) ($hauteurOrigine * ($largeurIdeale / $largeurOrigine));
251
						$hauteurMin = (int) ($hauteurOrigine * ($largeurIdeale / $largeurOrigine));
230
						if ($hauteurMin > $hauteurIdeale) {
252
						if ($hauteurMin > $hauteurIdeale) {
231
							$hauteurMin = $hauteurIdeale;
253
							$hauteurMin = $hauteurIdeale;
232
							$largeurMin = (int)($largeurOrigine * ($hauteurMin / $hauteurOrigine));
254
							$largeurMin = (int)($largeurOrigine * ($hauteurMin / $hauteurOrigine));
233
						}
255
						}
234
 
256
 
235
						// Création de la miniature
257
						// Création de la miniature
236
						$imageOriginale = imagecreatefromjpeg($originalChemin);
258
						$imageOriginale = imagecreatefromjpeg($originalChemin);
237
						$imageMiniature = imagecreatetruecolor($largeurMin, $hauteurMin);
259
						$imageMiniature = imagecreatetruecolor($largeurMin, $hauteurMin);
238
						$couleurFond = imagecolorallocate($imageMiniature, 255, 255, 255);
260
						$couleurFond = imagecolorallocate($imageMiniature, 255, 255, 255);
239
						imagefill($imageMiniature, 0, 0, $couleurFond);
261
						imagefill($imageMiniature, 0, 0, $couleurFond);
240
						imagecopyresized($imageMiniature, $imageOriginale, 0, 0, 0, 0, $largeurMin, $hauteurMin, $largeurOrigine, $hauteurOrigine);
262
						imagecopyresized($imageMiniature, $imageOriginale, 0, 0, 0, 0, $largeurMin, $hauteurMin, $largeurOrigine, $hauteurOrigine);
241
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
263
						imagejpeg($imageMiniature, $miniatureChemin, $qualite);
242
						imagedestroy($imageMiniature);
264
						imagedestroy($imageMiniature);
243
						imagedestroy($imageOriginale);
265
						imagedestroy($imageOriginale);
244
 
266
 
245
						// Retour des infos
267
						// Retour des infos
246
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
268
						$retour['donnees']['urlMiniature'] = sprintf($this->config['chemins']['imagesTempUrlTpl'], $miniatureFichier);
247
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
269
						$retour['donnees']['imageNom'] = $nomFichierOriginal;
248
					} else {
270
					} else {
249
						$message = "L'image n'a pu être déplacé sur le serveur.";
271
						$message = "L'image n'a pu être déplacé sur le serveur.";
250
					}
272
					}
251
				} else {
273
				} else {
252
					$message = "L'image n'est pas au format JPEG.";
274
					$message = "L'image n'est pas au format JPEG.";
253
				}
275
				}
254
			} else {
276
			} else {
255
				$message = "L'image n'a pu être téléversée.";
277
				$message = "L'image n'a pu être téléversée.";
256
				$debogage = $message.print_r($_FILES, true);
278
				$debogage = $message.print_r($_FILES, true);
257
			}
279
			}
258
		} else {
280
		} else {
259
			if ($_FILES['fichier']['error'] == UPLOAD_ERR_FORM_SIZE) {
281
			if ($_FILES['fichier']['error'] == UPLOAD_ERR_FORM_SIZE) {
260
				$message = "L'image téléversée excède la taille maximum autorisée.".
282
				$message = "L'image téléversée excède la taille maximum autorisée.".
261
						"Veuillez modifier votre image avant de la téléverser à nouveau.";
283
						"Veuillez modifier votre image avant de la téléverser à nouveau.";
262
			} else {
284
			} else {
263
				$message = "Une erreur de transfert a eu lieu (téléversement interrompu).";
285
				$message = "Une erreur de transfert a eu lieu (téléversement interrompu).";
264
			}
286
			}
265
			$debogage = "Code erreur : {$_FILES['fichier']['error']}. ".
287
			$debogage = "Code erreur : {$_FILES['fichier']['error']}. ".
266
					"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
288
					"Voir : http://php.net/manual/fr/features.file-upload.errors.php";
267
		}
289
		}
268
		// Retour des infos
290
		// Retour des infos
269
		$retour['donnees']['message'] = $message;
291
		$retour['donnees']['message'] = $message;
270
		$retour['donnees']['debogage'] = $debogage;
292
		$retour['donnees']['debogage'] = $debogage;
271
		return $retour;
293
		return $retour;
272
	}
294
	}
273
	
295
	
274
	// Il ne faut pas utiliser l'index type du tableau files pour tester 
296
	// Il ne faut pas utiliser l'index type du tableau files pour tester 
275
	// si une image est en jpeg car le type renvoyé par les navigateurs
297
	// si une image est en jpeg car le type renvoyé par les navigateurs
276
	// peut varier (ex. sous ie qui renvoie image/pjpeg 
298
	// peut varier (ex. sous ie qui renvoie image/pjpeg 
277
	private function verifierFormatJpeg($chemin) {
299
	private function verifierFormatJpeg($chemin) {
278
		// get imagesize renvoie un résultat consistant par contre
300
		// get imagesize renvoie un résultat consistant par contre
279
		$infos = getimagesize($chemin, $infos);
301
		$infos = getimagesize($chemin, $infos);
280
		return (isset($infos["mime"]) && $infos["mime"] == "image/jpeg");
302
		return (isset($infos["mime"]) && $infos["mime"] == "image/jpeg");
281
	}
303
	}
282
	
304
	
283
	private function array2js($array,$show_keys)
305
	private function array2js($array,$show_keys)
284
    {
306
    {
285
        $dimensions = array();
307
        $dimensions = array();
286
        $valeurs = array();
308
        $valeurs = array();
287
              
309
              
288
        $total = count ($array)-1;
310
        $total = count ($array)-1;
289
        $i=0;
311
        $i=0;
290
        foreach($array as $key=>$value){
312
        foreach($array as $key=>$value){
291
            if (is_array($value)) {
313
            if (is_array($value)) {
292
                $dimensions[$i] = array2js($value,$show_keys);
314
                $dimensions[$i] = array2js($value,$show_keys);
293
                if ($show_keys) $dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
315
                if ($show_keys) $dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
294
            } else {
316
            } else {
295
                $dimensions[$i] = '"'.addslashes($value).'"';
317
                $dimensions[$i] = '"'.addslashes($value).'"';
296
                if ($show_keys) $dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
318
                if ($show_keys) $dimensions[$i] = '"'.$key.'":'.$dimensions[$i];
297
            }
319
            }
298
            if ($i==0) $dimensions[$i] = '{'.$dimensions[$i];
320
            if ($i==0) $dimensions[$i] = '{'.$dimensions[$i];
299
            if ($i==$total) $dimensions[$i].= '}';
321
            if ($i==$total) $dimensions[$i].= '}';
300
            $i++;
322
            $i++;
301
        }
323
        }
302
        return implode(',',$dimensions);
324
        return implode(',',$dimensions);
303
    }
325
    }
304
}
326
}
305
?>
327
?>