Subversion Repositories eFlore/Applications.cel

Rev

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

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