Subversion Repositories eFlore/Applications.cel

Rev

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

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