Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3235 Rev 3241
1
 <?php
1
 <?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
4
 * Service affichant les dernières photo publiques du CEL ouvrable sous forme de diaporama.
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=AideCELWidgetPhoto
9
 * @link http://www.tela-botanica.org/wikini/eflore/wakka.php?wiki=AideCELWidgetPhoto
10
 *
10
 *
11
 * Paramètres :
11
 * Paramètres :
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
12
 * ===> extra = booléen (1 ou 0)  [par défaut : 1]
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
13
 * Affiche / Cache la vignette en taille plus importante au bas du widget.
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
14
 * ===> vignette = [0-9]+,[0-9]+  [par défaut : 4,3]
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
15
 * Indique le nombre de vignette par ligne et le nombre de ligne.
16
 *
16
 *
17
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
17
 * @author              Jean-Pascal MILCENT <jpm@tela-botanica.org>
18
 * @license     GPL v3 <http://www.gnu.org/licenses/gpl.txt>
18
 * @license     GPL v3 <http://www.gnu.org/licenses/gpl.txt>
19
 * @license     CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
19
 * @license     CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
20
 * @version     $Id$
20
 * @version     $Id$
21
 * @copyright   Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
21
 * @copyright   Copyright (c) 2010, Tela Botanica (accueil@tela-botanica.org)
22
 */
22
 */
23
class Manager extends WidgetCommun {
23
class Manager extends WidgetCommun {
24
 
24
 
25
	const DS = DIRECTORY_SEPARATOR;
25
	const DS = DIRECTORY_SEPARATOR;
26
	const SERVICE_DEFAUT = 'manager';
26
	const SERVICE_DEFAUT = 'manager';
27
	private $cel_url_tpl = null;
27
	private $cel_url_tpl = null;
28
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
28
	/** Si spécifié, on ajoute une barre de navigation inter-applications */
29
	private $bar;
29
	private $bar;
30
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
30
	//private $parametres_autorises = array('projet', 'type', 'langue', 'order');
31
	private $parametres_autorises = array(
31
	private $parametres_autorises = array(
32
		'projet' => 'projet',
32
		'projet' => 'projet',
33
		'type' => 'type',
33
		'type' => 'type',
34
		'langue' => 'langue',
34
		'langue' => 'langue',
35
		'order' => 'order'
35
		'order' => 'order'
36
	);
36
	);
37
	/**
37
	/**
38
	 * Méthode appelée par défaut pour charger ce widget.
38
	 * Méthode appelée par défaut pour charger ce widget.
39
	 */
39
	 */
40
	public function executer() {
40
	public function executer() {
41
		$retour = null;
41
		$retour = null;
42
 
42
 
43
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
43
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
44
		unset( $this->parametres['callback'] );
44
		unset( $this->parametres['callback'] );
45
		extract( $this->parametres );
45
		extract( $this->parametres );
46
		$this->bar = ( isset( $bar ) ) ? $bar : false;
46
		$this->bar = ( isset( $bar ) ) ? $bar : false;
47
 
47
 
48
		$framework = dirname( __FILE__ ) . '/framework.php';
48
		$framework = dirname( __FILE__ ) . '/framework.php';
49
 
49
 
50
		if ( !file_exists( $framework ) ) {
50
		if ( !file_exists( $framework ) ) {
51
 
51
 
52
			$e = 'Veuillez paramêtrer l\'emplacement et la version du Framework dans le fichier $framework';
52
			$e = 'Veuillez paramêtrer l\'emplacement et la version du Framework dans le fichier $framework';
53
			trigger_error( $e, E_USER_ERROR );
53
			trigger_error( $e, E_USER_ERROR );
54
		} else {
54
		} else {
55
 
55
 
56
			// Inclusion du Framework
56
			// Inclusion du Framework
57
			require_once $framework;
57
			require_once $framework;
58
			// Ajout d'information concernant cette application
58
			// Ajout d'information concernant cette application
59
			Framework::setCheminAppli( __FILE__ );// Obligatoire
59
			Framework::setCheminAppli( __FILE__ );// Obligatoire
60
			Framework::setInfoAppli( Config::get( 'info' ) );// Optionnel
60
			Framework::setInfoAppli( Config::get( 'info' ) );// Optionnel
61
		}
61
		}
62
 
62
 
63
		if ( !isset( $mode ) ) {
63
		if ( !isset( $mode ) ) {
64
 
64
 
65
			$mode = self::SERVICE_DEFAUT;
65
			$mode = self::SERVICE_DEFAUT;
66
		}
66
		}
67
 
67
 
68
		$this->cel_url_tpl = $this->config['manager']['celUrlTpl'];
68
		$this->cel_url_tpl = $this->config['manager']['celUrlTpl'];
69
 
69
 
70
		if ( $_POST !== array() ) { //print_r($_POST);
70
		if ( $_POST !== array() ) { //print_r($_POST);
71
 
71
 
72
			$this->parametres['projet'] = $_POST['projet'];
72
			$this->parametres['projet'] = $_POST['projet'];
73
			$this->parametres['langue'] = $_POST['langue'];
73
			$this->parametres['langue'] = $_POST['langue'];
74
 
74
 
75
			if ( $mode === 'modification' ) {
75
			if ( $mode === 'modification' ) {
76
 
76
 
77
				$parametres = $this->traiterParametresModif();
77
				$parametres = $this->traiterParametresModif();
78
				$json       = $this->getDao()->modifier( $this->cel_url_tpl, $parametres );
78
				$json       = $this->getDao()->modifier( $this->cel_url_tpl, $parametres );
79
			} else {
79
			} else {
80
 
80
 
81
				$donnees = array_merge( $_POST, $this->traiterDonneesFiles() );
81
				$donnees = array_merge( $_POST, $this->traiterDonneesFiles() );
82
				// var_dump($donnees);
82
				// var_dump($donnees);
83
				$json  = $this->getDao()->ajouter( $this->cel_url_tpl, $donnees );
83
				$json  = $this->getDao()->ajouter( $this->cel_url_tpl, $donnees );
84
				$mode  = $this->parametres['mode'] = 'modification';
84
				$mode  = $this->parametres['mode'] = 'modification';
85
			}
85
			}
86
		}
86
		}
87
 
87
 
88
		$methode = $this->traiterNomMethodeExecuter( $mode );
88
		$methode = $this->traiterNomMethodeExecuter( $mode );
89
		if ( method_exists( $this, $methode ) ) {
89
		if ( method_exists( $this, $methode ) ) {
90
 
90
 
91
			$retour = $this->$methode();
91
			$retour = $this->$methode();
92
		} else {
92
		} else {
93
 
93
 
94
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
94
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
95
		}
95
		}
96
 
96
 
97
		$contenu = '';
97
		$contenu = '';
98
		if ( is_null( $retour ) ) {
98
		if ( is_null( $retour ) ) {
99
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
99
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
100
 
100
 
101
		} else {
101
		} else {
102
 
102
 
103
			if ( isset( $retour['donnees'] ) ) {
103
			if ( isset( $retour['donnees'] ) ) {
104
 
104
 
105
				$retour['donnees']['params']   = '&projet=' . $_POST['projet'] . '&langue=' . $_POST['langue'];
105
				$retour['donnees']['params']   = '&projet=' . $_POST['projet'] . '&langue=' . $_POST['langue'];
106
				$retour['donnees']['prod']     = ( $this->config['parametres']['modeServeur'] === 'prod' );
106
				$retour['donnees']['prod']     = ( $this->config['parametres']['modeServeur'] === 'prod' );
107
				$retour['donnees']['bar']      = $this->bar;
107
				$retour['donnees']['bar']      = $this->bar;
108
				$retour['donnees']['url_base'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], '' );
108
				$retour['donnees']['url_base'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], '' );
109
 
109
 
110
				$retour['donnees']['mode']     = $mode; //print_r($retour);
110
				$retour['donnees']['mode']     = $mode; //print_r($retour);
111
				$squelette = dirname( __FILE__ ) . self::DS . 'squelettes' . self::DS . $retour['squelette'] . '.tpl.html';
111
				$squelette = dirname( __FILE__ ) . self::DS . 'squelettes' . self::DS . $retour['squelette'] . '.tpl.html';
112
				$contenu   = $this->traiterSquelettePhp( $squelette, $retour['donnees'] );
112
				$contenu   = $this->traiterSquelettePhp( $squelette, $retour['donnees'] );
113
			} else {
113
			} else {
114
 
114
 
115
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
115
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
116
			}
116
			}
117
		}
117
		}
118
		$this->envoyer($contenu);
118
		$this->envoyer($contenu);
119
	}
119
	}
120
 
120
 
121
	private function executerManager() {
121
	private function executerManager() {
122
		$params = array();
122
		$params = array();
123
		$retour['squelette'] = 'manager';
123
		$retour['squelette'] = 'manager';
124
 
124
 
125
		foreach ( $this->parametres_autorises as $id => $pa ) {
125
		foreach ( $this->parametres_autorises as $id => $pa ) {
126
			if ( isset( $this->parametres[$pa] ) ) {
126
			if ( isset( $this->parametres[$pa] ) ) {
127
 
127
 
128
				$params[] = $pa . '=' . $this->parametres[$pa];
128
				$params[] = $pa . '=' . $this->parametres[$pa];
129
			}
129
			}
130
		}
130
		}
131
 
131
 
132
		$param = implode( $params, '&' );
132
		$param = implode( $params, '&' );
133
		$url   = $this->cel_url_tpl;
133
		$url   = $this->cel_url_tpl;
134
 
134
 
135
		if ( $param !== '' ) {
135
		if ( $param !== '' ) {
136
 
136
 
137
			$url .= '?' . $param;
137
			$url .= '?' . $param;
138
		}
138
		}
139
 
139
 
140
		$json = $this->getDao()->consulter( $url );
140
		$json = $this->getDao()->consulter( $url );
141
		$retour['donnees']['widget']       = (array) json_decode( $json, true );
141
		$retour['donnees']['widget']        = (array) json_decode( $json, true );
142
		$retour['donnees']['widgetUrlTpl'] = $this->config['manager']['widgetUrlTpl'];
142
		$retour['donnees']['widgetUrlTpl']  = $this->config['manager']['widgetUrlTpl'];
-
 
143
		$retour['donnees']['chemin_images'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['dossierTmp'] );
143
 
144
 
144
		return $retour;
145
		return $retour;
145
	}
146
	}
146
 
147
 
147
	private function executerCreation() {
148
	private function executerCreation() {
148
		//https://api.tela-botanica.org/service:cel:NomsChampsEtendus/cle
149
		//https://api.tela-botanica.org/service:cel:NomsChampsEtendus/cle
149
		$jsonlangue    = $this->getDao()->consulter( $this->config['manager']['languesUrl'] );
150
		$jsonlangue    = $this->getDao()->consulter( $this->config['manager']['languesUrl'] );
150
		$tableaulangue = (array) json_decode( $jsonlangue, true );
151
		$tableaulangue = (array) json_decode( $jsonlangue, true );
151
		$retour['squelette']          = 'creation';
152
		$retour['squelette']          = 'creation';
152
		$retour['donnees']['langues'] = $tableaulangue['resultat'] ;
153
		$retour['donnees']['langues'] = $tableaulangue['resultat'] ;
153
		$retour['donnees']['widget']  = array();
154
		$retour['donnees']['widget']  = array();
154
 
155
 
155
		if ( isset( $this->parametres['projet'] ) ) {
156
		if ( isset( $this->parametres['projet'] ) ) {
156
 
157
 
157
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'];
158
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'];
158
			$json    = $this->getDao()->consulter( $url );
159
			$json    = $this->getDao()->consulter( $url );
159
			$tableau = (array) json_decode( $json, true );
160
			$tableau = (array) json_decode( $json, true );
160
			$retour['donnees']['widget'] = $tableau[0];
161
			$retour['donnees']['widget'] = $tableau[0];
161
		}
162
		}
162
 
163
 
163
		$urltype     = $this->cel_url_tpl . '?esttype=1';
164
		$urltype     = $this->cel_url_tpl . '?esttype=1';
164
		$jsontype    = $this->getDao()->consulter( $urltype );
165
		$jsontype    = $this->getDao()->consulter( $urltype );
165
		$tableautype = (array) json_decode( $jsontype, true );
166
		$tableautype = (array) json_decode( $jsontype, true );
166
		$retour['donnees']['type'] = $tableautype;
167
		$retour['donnees']['type'] = $tableautype;
167
 
168
 
168
		return $retour;
169
		return $retour;
169
	}
170
	}
170
 
171
 
171
 
172
 
172
 
173
 
173
	private function executerModification() {
174
	private function executerModification() {
174
		$retour = array();
175
		$retour = array();
175
		if ( isset( $this->parametres['projet'] ) ) {
176
		if ( isset( $this->parametres['projet'] ) ) {
176
 
177
 
177
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'] . '&langue=' . $this->parametres['langue'];
178
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'] . '&langue=' . $this->parametres['langue'];
178
			$json    = $this->getDao()->consulter( $url );
179
			$json    = $this->getDao()->consulter( $url );
179
			$tableau = (array) json_decode( $json, true );
180
			$tableau = (array) json_decode( $json, true );
180
			$retour['squelette']         = 'creation';
181
			$retour['squelette']         = 'creation';
181
			$retour['donnees']['widget'] = $tableau[0];
182
			$retour['donnees']['widget'] = $tableau[0];
182
 
183
 
183
			$urltype     = $this->cel_url_tpl .'?esttype=1';
184
			$urltype     = $this->cel_url_tpl .'?esttype=1';
184
			$jsontype    = $this->getDao()->consulter( $urltype );
185
			$jsontype    = $this->getDao()->consulter( $urltype );
185
			$tableautype = (array) json_decode( $jsontype, true );
186
			$tableautype = (array) json_decode( $jsontype, true );
186
			$retour['donnees']['type'] = $tableautype;
187
			$retour['donnees']['type'] = $tableautype;
187
		}//print_r($retour['donnees']);
188
		}//print_r($retour['donnees']);
188
 
189
 
189
		return $retour;
190
		return $retour;
190
	}
191
	}
191
	private function traiterParametres() {
192
	private function traiterParametres() {
192
		$parametres_flux = '?';
193
		$parametres_flux = '?';
193
		$criteres        = array( 'utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'motcle', 'projet', 'num_taxon', 'num_nom', 'referentiel', 'groupe_zones_geo' );
194
		$criteres        = array( 'utilisateur', 'commune', 'dept', 'taxon', 'commentaire', 'date', 'tag', 'motcle', 'projet', 'num_taxon', 'num_nom', 'referentiel', 'groupe_zones_geo' );
194
 
195
 
195
		foreach( $this->parametres as $nom_critere => $valeur_critere ) {
196
		foreach( $this->parametres as $nom_critere => $valeur_critere ) {
196
			if ( in_array( $nom_critere, $criteres ) ) {
197
			if ( in_array( $nom_critere, $criteres ) ) {
197
 
198
 
198
				$valeur_critere   = str_replace( ' ', '%20', $valeur_critere );
199
				$valeur_critere   = str_replace( ' ', '%20', $valeur_critere );
199
				$parametres_flux .= $nom_critere . '=' . $valeur_critere . '&';
200
				$parametres_flux .= $nom_critere . '=' . $valeur_critere . '&';
200
			}
201
			}
201
		}
202
		}
202
 
203
 
203
		$parametres_flux = ( $parametres_flux === '?' ) ? '' : rtrim( $parametres_flux, '&' );
204
		$parametres_flux = ( $parametres_flux === '?' ) ? '' : rtrim( $parametres_flux, '&' );
204
 
205
 
205
		return $parametres_flux;
206
		return $parametres_flux;
206
	}
207
	}
207
 
208
 
208
	private function traiterParametresModif() {
209
	private function traiterParametresModif() {
209
		$parametres_modif = array();
210
		$parametres_modif = array();
210
 
211
 
211
		foreach ( $_POST as $id => $parametres ) {
212
		foreach ( $_POST as $id => $parametres ) {
212
			if ($parametres !== '' ) {
213
			if ($parametres !== '' ) {
213
 
214
 
214
				$parametres_modif[$id] = $parametres;
215
				$parametres_modif[$id] = $parametres;
215
			}
216
			}
216
		}
217
		}
217
 
218
 
218
		return $parametres_modif;
219
		return $parametres_modif;
219
	}
220
	}
220
 
221
 
221
	private function traiterDonneesFiles() {
222
	private function traiterDonneesFiles() {
222
		$return = array();
223
		$return = array();
223
		$dossier_url = __DIR__ . '/squelettes/img/images_projets/' . $_POST['projet'] . '/';
-
 
224
		$transmettre_donnees = false;
224
		$transmettre_donnees = false;
225
		$files_names = array();
225
		$files_names = array();
226
		$help_files_names = array();
226
		$help_files_names = array();
227
		$error =
227
		$error =
228
			"<div class=\"message-echec container\">Echec du téléchargement : ".
228
			"<div class=\"message-echec container\">Echec du téléchargement : ".
229
	    	"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
229
	    	"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
230
	    	", formats acceptés : png, gif, jpg, jpeg, ou csv.".
230
	    	", formats acceptés : png, gif, jpg, jpeg, ou csv.".
231
			"</div>";
231
			"</div>";
-
 
232
		$image_projet_langue = ( $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
-
 
233
		$dossier_url = __DIR__ . '/squelettes/img/images_projets/' . $_POST['projet'] . $image_projet_langue . '/';
232
 
234
 
233
		foreach ( array_keys( $_FILES ) as $file ) {
235
		foreach ( array_keys( $_FILES ) as $file ) {
234
 
236
 
235
			if ( $_FILES[$file]['name'] !== '' ) {
237
			if ( $_FILES[$file]['name'] !== '' ) {
236
				$extension = $this->obtenirExtension( $_FILES[$file] );
238
				$extension = $this->obtenirExtension( $_FILES[$file] );
237
 
239
 
238
				if ( $extension ) {
240
				if ( $extension ) {
239
 
241
 
240
					$transmettre_donnees = true;
242
					$transmettre_donnees = true;
241
 
243
 
242
			 		if ( strstr( $file, 'help-') ) {
244
			 		if ( strstr( $file, 'help-') ) {
243
			 			// Pas besoin de $return :
245
			 			// Pas besoin de $return :
244
			 			// Type déjà transmis dans le json des champs supp
246
			 			// Type déjà transmis dans le json des champs supp
245
						$real_file_key = str_replace( 'help-', '', $file );
247
						$real_file_key = str_replace( 'help-', '', $file );
246
						$help_files_names[$real_file_key] = $real_file_key . '.' . $extension;
248
						$help_files_names[$real_file_key] = $real_file_key . '.' . $extension;
247
					} else {
249
					} else {
248
						$return[$file] = $_FILES[$file]['type'];
250
						$return[$file] = $_FILES[$file]['type'];
249
					 	$files_names[$file] = $file .'.' . $extension;
251
					 	$files_names[$file] = $file .'.' . $extension;
250
					}
252
					}
251
				} else {
253
				} else {
252
 
254
 
253
					echo (
255
					echo (
254
						"<div class=\"message-echec container\">Echec du téléchargement : ".
256
						"<div class=\"message-echec container\">Echec du téléchargement : ".
255
				    	"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
257
				    	"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
256
				    	", formats acceptés : png, gif, jpg, jpeg, ou csv.".
258
				    	", formats acceptés : png, gif, jpg, jpeg, ou csv.".
257
						"</div>"
259
						"</div>"
258
					);
260
					);
259
				}
261
				}
260
			}
262
			}
261
		}
263
		}
262
 
264
 
263
		if ( $transmettre_donnees ) {
265
		if ( $transmettre_donnees ) {
264
			if( !is_dir( $dossier_url ) ) {
266
			if( !is_dir( $dossier_url ) ) {
265
 
267
 
266
				mkdir( $dossier_url, 0755 );
268
				mkdir( $dossier_url, 0755 );
267
			}
269
			}
268
 
270
 
269
			// Téléversements
271
			// Téléversements
270
			if ( count( $files_names ) > 0 ) {
272
			if ( count( $files_names ) > 0 ) {
271
				foreach ( array_keys( $files_names ) as $file ) {
273
				foreach ( array_keys( $files_names ) as $file ) {
272
					$this->televerser( $file, $files_names[ $file ], $dossier_url );
274
					$this->televerser( $file, $files_names[ $file ], $dossier_url );
273
				}
275
				}
274
			}
276
			}
275
			if ( count( $help_files_names ) > 0 ) {
277
			if ( count( $help_files_names ) > 0 ) {
276
				foreach ( array_keys( $help_files_names ) as $file ) {
278
				foreach ( array_keys( $help_files_names ) as $file ) {
277
					$this->televerser( 'help-' . $file, $help_files_names[ $file ], $dossier_url );
279
					$this->televerser( 'help-' . $file, $help_files_names[ $file ], $dossier_url );
278
				}
280
				}
279
			}
281
			}
280
		}
282
		}
281
 
283
 
282
		return $return;
284
		return $return;
283
	}
285
	}
284
 
286
 
285
	private function televerser( $file, $full_name, $dossier_url ) {
287
	private function televerser( $file, $full_name, $dossier_url ) {
286
		$taille_maxi = 5242880;
288
		$taille_maxi = 5242880;
287
		$taille      = filesize( $_FILES[$file]['tmp_name'] );
289
		$taille      = filesize( $_FILES[$file]['tmp_name'] );
288
		$extension   = $this->obtenirExtension( $_FILES[$file] );
290
		$extension   = $this->obtenirExtension( $_FILES[$file] );
289
		$file_name   = str_replace( $extension, '', $full_name );
291
		$file_name   = str_replace( $extension, '', $full_name );
290
 
292
 
291
		//Début des vérifications de sécurité...
293
		//Début des vérifications de sécurité...
292
		if ( file_exists( $dossier_url . $full_name ) ) {
294
		if ( file_exists( $dossier_url . $full_name ) ) {
293
 
295
 
294
			if ( $_POST['mode'] === 'modification' ) {
296
			if ( $_POST['mode'] === 'modification' ) {
295
 
297
 
296
				// Le fichier existe déjà, c'est normal si on est en mode modification
298
				// Le fichier existe déjà, c'est normal si on est en mode modification
297
				unlink ( $dossier_url . $full_name );
299
				unlink ( $dossier_url . $full_name );
298
			} else {
300
			} else {
299
 
301
 
300
				$erreur =
302
				$erreur =
301
					"<div class=\"message-echec container\">Echec du téléchargement : ".
303
					"<div class=\"message-echec container\">Echec du téléchargement : ".
302
						"Un fichier pour \"" . $file_name.
304
						"Un fichier pour \"" . $file_name.
303
						"\", existe déjà dans un projet nommé \"" . $_POST['projet'] . "\".".
305
						"\", existe déjà dans un projet nommé \"" . $_POST['projet'] . "\".".
304
						"<br>Vérifiez que le nom du projet n'est pas déjà pris, ".
306
						"<br>Vérifiez que le nom du projet n'est pas déjà pris, ".
305
						"ou qu'un fichier \"" . $full_name . "\" n'ait pas déjà été téléchargé pour ce projet.".
307
						"ou qu'un fichier \"" . $full_name . "\" n'ait pas déjà été téléchargé pour ce projet.".
306
					"</div>";
308
					"</div>";
307
			}
309
			}
308
		}
310
		}
309
 
311
 
310
		if ( !$extension ) {
312
		if ( !$extension ) {
311
 
313
 
312
			//Si le format n'est pas bon
314
			//Si le format n'est pas bon
313
			$erreur =
315
			$erreur =
314
				"<div class=\"message-echec container\">".
316
				"<div class=\"message-echec container\">".
315
					"Echec du téléchargement pour ".
317
					"Echec du téléchargement pour ".
316
					"\"" . $file_name . "\" ".
318
					"\"" . $file_name . "\" ".
317
					", formats acceptés : png, gif, jpg, jpeg, ou csv".
319
					", formats acceptés : png, gif, jpg, jpeg, ou csv".
318
				"</div>";
320
				"</div>";
319
		}
321
		}
320
 
322
 
321
		if ( $taille > $taille_maxi ) {
323
		if ( $taille > $taille_maxi ) {
322
 
324
 
323
			$erreur =
325
			$erreur =
324
				"<div class=\"message-echec container\">".
326
				"<div class=\"message-echec container\">".
325
					"Echec du téléchargement pour ".
327
					"Echec du téléchargement pour ".
326
					"\"" . $file_name . "\" ".
328
					"\"" . $file_name . "\" ".
327
					": Max 5Mo".
329
					": Max 5Mo".
328
				"</div>";
330
				"</div>";
329
		}
331
		}
330
 
332
 
331
		if ( isset( $erreur ) ) {
333
		if ( isset( $erreur ) ) {
332
 
334
 
333
			echo $erreur;
335
			echo $erreur;
334
		} else {
336
		} else {
335
 
337
 
336
			if ( !move_uploaded_file( $_FILES[$file]['tmp_name'], $dossier_url . $this->remove_accents( $full_name ) ) ) {
338
			if ( !move_uploaded_file( $_FILES[$file]['tmp_name'], $dossier_url . $this->remove_accents( $full_name ) ) ) {
337
			// move_uploaded_file() renvoie false si l'upload a échoué
339
			// move_uploaded_file() renvoie false si l'upload a échoué
338
				echo
340
				echo
339
					"<div class=\"message-echec container\">".
341
					"<div class=\"message-echec container\">".
340
						"Erreur du téléchargement pour ".
342
						"Erreur du téléchargement pour ".
341
						"\"" . $file_name . "\"".
343
						"\"" . $file_name . "\"".
342
					"</div>";
344
					"</div>";
343
			}
345
			}
344
		}
346
		}
345
	}
347
	}
346
 
348
 
347
	private function obtenirExtension( $files ) {
349
	private function obtenirExtension( $files ) {
348
		$type = exif_imagetype( $files['tmp_name'] );
350
		$type = exif_imagetype( $files['tmp_name'] );
349
		//une vérif pas mal pour les types image
351
		//une vérif pas mal pour les types image
350
		if ( $type == ( IMAGETYPE_PNG || IMAGETYPE_JPEG || IMAGETYPE_GIF ) ) {
352
		if ( $type == ( IMAGETYPE_PNG || IMAGETYPE_JPEG || IMAGETYPE_GIF ) ) {
351
 
353
 
352
	    switch ( $type ) {
354
	    switch ( $type ) {
353
	      case '1' :
355
	      case '1' :
354
	        $format = 'gif';
356
	        $format = 'gif';
355
	        break;
357
	        break;
356
	      case '2' :
358
	      case '2' :
357
	        $format = 'jpg';
359
	        $format = 'jpg';
358
	        break;
360
	        break;
359
	      case '3' :
361
	      case '3' :
360
	        $format = 'png';
362
	        $format = 'png';
361
	        break;
363
	        break;
362
	      default :
364
	      default :
363
	      	break;
365
	      	break;
364
	    }
366
	    }
365
	  } elseif ( str_replace( '.csv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'csv' ) {
367
	  } elseif ( str_replace( '.csv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'csv' ) {
366
	  	// Pas trouvé mieux pour csv :
368
	  	// Pas trouvé mieux pour csv :
367
	  	// Les fonctions qui pourraient utiliser $_FILES[file]["tmp_path"] me répondent "text/plain"...
369
	  	// Les fonctions qui pourraient utiliser $_FILES[file]["tmp_path"] me répondent "text/plain"...
368
 
370
 
369
	  	$format = 'csv';
371
	  	$format = 'csv';
370
	  } else {
372
	  } else {
371
 
373
 
372
	  	return false;
374
	  	return false;
373
	  }
375
	  }
374
		return $format;
376
		return $format;
375
	}
377
	}
376
 
378
 
377
	private function remove_accents( $string ) {
379
	private function remove_accents( $string ) {
378
		if ( !preg_match( '/[\x80-\xff]/' , $string ) ) {
380
		if ( !preg_match( '/[\x80-\xff]/' , $string ) ) {
379
 
381
 
380
			return $string;
382
			return $string;
381
		}
383
		}
382
 
384
 
383
		$chars = array(
385
		$chars = array(
384
			// Decompositions for Latin-1 Supplement
386
			// Decompositions for Latin-1 Supplement
385
			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
387
			chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
386
			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
388
			chr(195).chr(130) => 'A', chr(195).chr(131) => 'A',
387
			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
389
			chr(195).chr(132) => 'A', chr(195).chr(133) => 'A',
388
			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
390
			chr(195).chr(135) => 'C', chr(195).chr(136) => 'E',
389
			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
391
			chr(195).chr(137) => 'E', chr(195).chr(138) => 'E',
390
			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
392
			chr(195).chr(139) => 'E', chr(195).chr(140) => 'I',
391
			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
393
			chr(195).chr(141) => 'I', chr(195).chr(142) => 'I',
392
			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
394
			chr(195).chr(143) => 'I', chr(195).chr(145) => 'N',
393
			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
395
			chr(195).chr(146) => 'O', chr(195).chr(147) => 'O',
394
			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
396
			chr(195).chr(148) => 'O', chr(195).chr(149) => 'O',
395
			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
397
			chr(195).chr(150) => 'O', chr(195).chr(153) => 'U',
396
			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
398
			chr(195).chr(154) => 'U', chr(195).chr(155) => 'U',
397
			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
399
			chr(195).chr(156) => 'U', chr(195).chr(157) => 'Y',
398
			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
400
			chr(195).chr(159) => 's', chr(195).chr(160) => 'a',
399
			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
401
			chr(195).chr(161) => 'a', chr(195).chr(162) => 'a',
400
			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
402
			chr(195).chr(163) => 'a', chr(195).chr(164) => 'a',
401
			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
403
			chr(195).chr(165) => 'a', chr(195).chr(167) => 'c',
402
			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
404
			chr(195).chr(168) => 'e', chr(195).chr(169) => 'e',
403
			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
405
			chr(195).chr(170) => 'e', chr(195).chr(171) => 'e',
404
			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
406
			chr(195).chr(172) => 'i', chr(195).chr(173) => 'i',
405
			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
407
			chr(195).chr(174) => 'i', chr(195).chr(175) => 'i',
406
			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
408
			chr(195).chr(177) => 'n', chr(195).chr(178) => 'o',
407
			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
409
			chr(195).chr(179) => 'o', chr(195).chr(180) => 'o',
408
			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
410
			chr(195).chr(181) => 'o', chr(195).chr(182) => 'o',
409
			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
411
			chr(195).chr(182) => 'o', chr(195).chr(185) => 'u',
410
			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
412
			chr(195).chr(186) => 'u', chr(195).chr(187) => 'u',
411
			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
413
			chr(195).chr(188) => 'u', chr(195).chr(189) => 'y',
412
			chr(195).chr(191) => 'y',
414
			chr(195).chr(191) => 'y',
413
			// Decompositions for Latin Extended-A
415
			// Decompositions for Latin Extended-A
414
			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
416
			chr(196).chr(128) => 'A', chr(196).chr(129) => 'a',
415
			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
417
			chr(196).chr(130) => 'A', chr(196).chr(131) => 'a',
416
			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
418
			chr(196).chr(132) => 'A', chr(196).chr(133) => 'a',
417
			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
419
			chr(196).chr(134) => 'C', chr(196).chr(135) => 'c',
418
			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
420
			chr(196).chr(136) => 'C', chr(196).chr(137) => 'c',
419
			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
421
			chr(196).chr(138) => 'C', chr(196).chr(139) => 'c',
420
			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
422
			chr(196).chr(140) => 'C', chr(196).chr(141) => 'c',
421
			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
423
			chr(196).chr(142) => 'D', chr(196).chr(143) => 'd',
422
			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
424
			chr(196).chr(144) => 'D', chr(196).chr(145) => 'd',
423
			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
425
			chr(196).chr(146) => 'E', chr(196).chr(147) => 'e',
424
			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
426
			chr(196).chr(148) => 'E', chr(196).chr(149) => 'e',
425
			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
427
			chr(196).chr(150) => 'E', chr(196).chr(151) => 'e',
426
			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
428
			chr(196).chr(152) => 'E', chr(196).chr(153) => 'e',
427
			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
429
			chr(196).chr(154) => 'E', chr(196).chr(155) => 'e',
428
			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
430
			chr(196).chr(156) => 'G', chr(196).chr(157) => 'g',
429
			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
431
			chr(196).chr(158) => 'G', chr(196).chr(159) => 'g',
430
			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
432
			chr(196).chr(160) => 'G', chr(196).chr(161) => 'g',
431
			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
433
			chr(196).chr(162) => 'G', chr(196).chr(163) => 'g',
432
			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
434
			chr(196).chr(164) => 'H', chr(196).chr(165) => 'h',
433
			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
435
			chr(196).chr(166) => 'H', chr(196).chr(167) => 'h',
434
			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
436
			chr(196).chr(168) => 'I', chr(196).chr(169) => 'i',
435
			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
437
			chr(196).chr(170) => 'I', chr(196).chr(171) => 'i',
436
			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
438
			chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
437
			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
439
			chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
438
			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
440
			chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
439
			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
441
			chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
440
			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
442
			chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
441
			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
443
			chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
442
			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
444
			chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
443
			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
445
			chr(196).chr(186) => 'l', chr(196).chr(187) => 'L',
444
			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
446
			chr(196).chr(188) => 'l', chr(196).chr(189) => 'L',
445
			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
447
			chr(196).chr(190) => 'l', chr(196).chr(191) => 'L',
446
			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
448
			chr(197).chr(128) => 'l', chr(197).chr(129) => 'L',
447
			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
449
			chr(197).chr(130) => 'l', chr(197).chr(131) => 'N',
448
			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
450
			chr(197).chr(132) => 'n', chr(197).chr(133) => 'N',
449
			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
451
			chr(197).chr(134) => 'n', chr(197).chr(135) => 'N',
450
			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
452
			chr(197).chr(136) => 'n', chr(197).chr(137) => 'N',
451
			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
453
			chr(197).chr(138) => 'n', chr(197).chr(139) => 'N',
452
			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
454
			chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
453
			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
455
			chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
454
			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
456
			chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
455
			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
457
			chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
456
			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
458
			chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
457
			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
459
			chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
458
			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
460
			chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
459
			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
461
			chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
460
			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
462
			chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
461
			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
463
			chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
462
			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
464
			chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
463
			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
465
			chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
464
			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
466
			chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
465
			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
467
			chr(197).chr(166) => 'T', chr(197).chr(167) => 't',
466
			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
468
			chr(197).chr(168) => 'U', chr(197).chr(169) => 'u',
467
			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
469
			chr(197).chr(170) => 'U', chr(197).chr(171) => 'u',
468
			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
470
			chr(197).chr(172) => 'U', chr(197).chr(173) => 'u',
469
			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
471
			chr(197).chr(174) => 'U', chr(197).chr(175) => 'u',
470
			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
472
			chr(197).chr(176) => 'U', chr(197).chr(177) => 'u',
471
			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
473
			chr(197).chr(178) => 'U', chr(197).chr(179) => 'u',
472
			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
474
			chr(197).chr(180) => 'W', chr(197).chr(181) => 'w',
473
			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
475
			chr(197).chr(182) => 'Y', chr(197).chr(183) => 'y',
474
			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
476
			chr(197).chr(184) => 'Y', chr(197).chr(185) => 'Z',
475
			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
477
			chr(197).chr(186) => 'z', chr(197).chr(187) => 'Z',
476
			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
478
			chr(197).chr(188) => 'z', chr(197).chr(189) => 'Z',
477
			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
479
			chr(197).chr(190) => 'z', chr(197).chr(191) => 's'
478
		);
480
		);
479
 
481
 
480
		$string = strtr( $string, $chars );
482
		$string = strtr( $string, $chars );
481
 
483
 
482
		return preg_replace( '/([^.a-z0-9]+)/i', '-', $string );
484
		return preg_replace( '/([^.a-z0-9]+)/i', '-', $string );
483
	}
485
	}
484
}
486
}