Subversion Repositories eFlore/Applications.cel

Rev

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

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