Subversion Repositories eFlore/Applications.cel

Rev

Rev 3667 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3667 Rev 3730
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
	/**
38
	/**
39
	 * Méthode appelée par défaut pour charger ce widget.
39
	 * Méthode appelée par défaut pour charger ce widget.
40
	 */
40
	 */
41
	public function executer() {
41
	public function executer() {
42
		$retour = null;
42
		$retour = null;
43
 
43
 
44
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
44
		// Pour la création de l'id du cache nous ne tenons pas compte du paramètre de l'url callback
45
		unset( $this->parametres['callback'] );
45
		unset( $this->parametres['callback'] );
46
		extract( $this->parametres );
46
		extract( $this->parametres );
47
		$this->bar = ( isset( $bar ) ) ? $bar : false;
47
		$this->bar = ( isset( $bar ) ) ? $bar : false;
48
 
48
 
49
		$framework = dirname( __FILE__ ) . '/framework.php';
49
		$framework = dirname( __FILE__ ) . '/framework.php';
50
 
50
 
51
		if ( !file_exists( $framework ) ) {
51
		if ( !file_exists( $framework ) ) {
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
			// Inclusion du Framework
55
			// Inclusion du Framework
56
			require_once $framework;
56
			require_once $framework;
57
			// Ajout d'information concernant cette application
57
			// Ajout d'information concernant cette application
58
			Framework::setCheminAppli( __FILE__ );// Obligatoire
58
			Framework::setCheminAppli( __FILE__ );// Obligatoire
59
			Framework::setInfoAppli( Config::get( 'info' ) );// Optionnel
59
			Framework::setInfoAppli( Config::get( 'info' ) );// Optionnel
60
		}
60
		}
61
 
61
 
62
		if ( !isset( $mode ) ) {
62
		if ( !isset( $mode ) ) {
63
			$mode = self::SERVICE_DEFAUT;
63
			$mode = self::SERVICE_DEFAUT;
64
		}
64
		}
65
 
65
 
66
		$this->cel_url_tpl = $this->config['manager']['celUrlTpl'];
66
		$this->cel_url_tpl = $this->config['manager']['celUrlTpl'];
67
 
67
 
68
		if ( $_POST !== array() ) { //print_r($_POST);
68
		if ( !empty( $_POST ) ) { //print_r($_POST);
69
			$this->parametres['projet'] = $_POST['projet'];
69
			$this->parametres['projet'] = $_POST['projet'];
70
			$this->parametres['langue'] = $_POST['langue'];
70
			$this->parametres['langue'] = $_POST['langue'];
71
 
71
 
72
			if ( $mode === 'modification' ) {
72
			if ( $mode === 'modification' ) {
73
				$parametres = $this->traiterParametresModif();
73
				$parametres = $this->traiterParametresModif();
74
				$donnees    = array_merge( $parametres, $this->traiterDonneesFiles() );
74
				$donnees    = array_merge( $parametres, $this->traiterDonneesFiles() );
75
				$json       = $this->getDao()->modifier( $this->cel_url_tpl, $donnees );
75
				$json       = $this->getDao()->modifier( $this->cel_url_tpl, $donnees );
76
			} else {
76
			} else {
77
				$donnees = array_merge( $_POST, $this->traiterDonneesFiles() );
77
				$donnees = array_merge( $_POST, $this->traiterDonneesFiles() );
78
				// var_dump($donnees);
-
 
79
				$json    = $this->getDao()->ajouter( $this->cel_url_tpl, $donnees );
78
				$json    = $this->getDao()->ajouter( $this->cel_url_tpl, $donnees );
80
				$mode    = $this->parametres['mode'] = 'modification';
79
				$mode    = $this->parametres['mode'] = 'modification';
81
			}
80
			}
82
		}
81
		}
83
 
82
 
84
		$methode = $this->traiterNomMethodeExecuter( $mode );
83
		$methode = $this->traiterNomMethodeExecuter( $mode );
85
		if ( method_exists( $this, $methode ) ) {
84
		if ( method_exists( $this, $methode ) ) {
86
			$retour = $this->$methode();
85
			$retour = $this->$methode();
87
		} else {
86
		} else {
88
 
87
 
89
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
88
			$this->messages[] = "Ce type de service '$methode' n'est pas disponible.";
90
		}
89
		}
91
 
90
 
92
		$contenu = '';
91
		$contenu = '';
93
		if ( is_null( $retour ) ) {
92
		if ( is_null( $retour ) ) {
94
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
93
			$this->messages[] = 'La ressource demandée a retourné une valeur nulle.';
95
 
94
 
96
		} else {
95
		} else {
97
 
96
 
98
			if ( isset( $retour['donnees'] ) ) {
97
			if ( isset( $retour['donnees'] ) ) {
99
				$retour['donnees']['params']        = '&projet=' . $_POST['projet'] . '&langue=' . $_POST['langue'];
98
				$retour['donnees']['params']        = '&projet=' . $_POST['projet'] . '&langue=' . $_POST['langue'];
100
				$retour['donnees']['prod']          = ( $this->config['parametres']['modeServeur'] === 'prod' );
99
				$retour['donnees']['prod']          = ( $this->config['parametres']['modeServeur'] === 'prod' );
101
				$retour['donnees']['bar']           = $this->bar;
100
				$retour['donnees']['bar']           = $this->bar;
102
				$retour['donnees']['url_base']      = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], '' );
101
				$retour['donnees']['url_base']      = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], '' );
103
				$retour['donnees']['chemin_images'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['dossierTmp'] );
102
				$retour['donnees']['chemin_images'] = sprintf( $this->config['chemins']['baseURLAbsoluDyn'], $this->config['manager']['dossierTmp'] );
104
				$retour['donnees']['mode']          = $mode;
103
				$retour['donnees']['mode']          = $mode;
105
				$squelette = dirname( __FILE__ ) . self::DS . 'squelettes' . self::DS . $retour['squelette'] . '.tpl.html';
104
				$squelette = dirname( __FILE__ ) . self::DS . 'squelettes' . self::DS . $retour['squelette'] . '.tpl.html';
106
				$contenu   = $this->traiterSquelettePhp( $squelette, $retour['donnees'] );
105
				$contenu   = $this->traiterSquelettePhp( $squelette, $retour['donnees'] );
107
			} else {
106
			} else {
108
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
107
				$this->messages[] = 'Les données à transmettre au squelette sont nulles.';
109
			}
108
			}
110
		}
109
		}
111
		$this->envoyer($contenu);
110
		$this->envoyer($contenu);
112
	}
111
	}
113
 
112
 
114
	private function executerManager() {
113
	private function executerManager() {
115
		$params = array();
114
		$params = array();
116
		$retour['squelette'] = 'manager';
115
		$retour['squelette'] = 'manager';
117
 
116
 
118
		foreach ( $this->parametres_autorises as $id => $pa ) {
117
		foreach ( $this->parametres_autorises as $id => $pa ) {
119
			if ( isset( $this->parametres[$pa] ) ) {
118
			if ( isset( $this->parametres[$pa] ) ) {
120
				$params[] = $pa . '=' . $this->parametres[$pa];
119
				$params[] = $pa . '=' . $this->parametres[$pa];
121
			}
120
			}
122
		}
121
		}
123
 
122
 
124
		$param = implode( $params, '&' );
123
		$param = implode( $params, '&' );
125
		$url   = $this->cel_url_tpl;
124
		$url   = $this->cel_url_tpl;
126
 
125
 
127
		if ( $param !== '' ) {
126
		if ( $param !== '' ) {
128
			$url .= '?' . $param;
127
			$url .= '?' . $param;
129
		}
128
		}
130
 
129
 
131
		$json = $this->getDao()->consulter( $url );
130
		$json = $this->getDao()->consulter( $url );
132
		$retour['donnees']['widget']        = (array) json_decode( $json, true );
131
		$retour['donnees']['widget']        = (array) json_decode( $json, true );
133
		$retour['donnees']['widgetUrlTpl']  = $this->config['manager']['widgetUrlTpl'];
132
		$retour['donnees']['widgetUrlTpl']  = $this->config['manager']['widgetUrlTpl'];
134
 
133
 
135
		return $retour;
134
		return $retour;
136
	}
135
	}
137
 
136
 
138
	private function executerCreation() {
137
	private function executerCreation() {
139
		//https://api.tela-botanica.org/service:cel:NomsChampsEtendus/cle
138
		//https://api.tela-botanica.org/service:cel:NomsChampsEtendus/cle
140
		$jsonlangue    = $this->getDao()->consulter( $this->config['manager']['languesUrl'] );
139
		$jsonlangue    = $this->getDao()->consulter( $this->config['manager']['languesUrl'] );
141
		$tableaulangue = (array) json_decode( $jsonlangue, true );
140
		$tableaulangue = (array) json_decode( $jsonlangue, true );
142
		$retour['squelette']          = 'creation';
141
		$retour['squelette']          = 'creation';
143
		$retour['donnees']['langues'] = $tableaulangue['resultat'] ;
142
		$retour['donnees']['langues'] = $tableaulangue['resultat'] ;
144
		$retour['donnees']['widget']  = array();
143
		$retour['donnees']['widget']  = array();
145
 
144
 
146
		if ( isset( $this->parametres['projet'] ) ) {
145
		if ( isset( $this->parametres['projet'] ) ) {
147
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'];
146
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'];
148
			$json    = $this->getDao()->consulter( $url );
147
			$json    = $this->getDao()->consulter( $url );
149
			$tableau = (array) json_decode( $json, true );
148
			$tableau = (array) json_decode( $json, true );
150
			$retour['donnees']['widget'] = $tableau[0];
149
			$retour['donnees']['widget'] = $tableau[0];
151
		}
150
		}
152
 
151
 
153
		$urltype     = $this->cel_url_tpl . '?esttype=1';
152
		$urltype     = $this->cel_url_tpl . '?esttype=1';
154
		$jsontype    = $this->getDao()->consulter( $urltype );
153
		$jsontype    = $this->getDao()->consulter( $urltype );
155
		$tableautype = (array) json_decode( $jsontype, true );
154
		$tableautype = (array) json_decode( $jsontype, true );
156
		$retour['donnees']['type'] = $tableautype;
155
		$retour['donnees']['type'] = $tableautype;
157
 
156
 
158
		return $retour;
157
		return $retour;
159
	}
158
	}
160
 
159
 
161
	private function executerModification() {
160
	private function executerModification() {
162
		$retour = array();
161
		$retour = array();
163
		if ( isset( $this->parametres['projet'] ) ) {
162
		if ( isset( $this->parametres['projet'] ) ) {
164
 
163
 
165
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'] . '&langue=' . $this->parametres['langue'];
164
			$url     = $this->cel_url_tpl . '?projet=' . $this->parametres['projet'] . '&langue=' . $this->parametres['langue'];
166
			$json    = $this->getDao()->consulter( $url );
165
			$json    = $this->getDao()->consulter( $url );
167
			$tableau = (array) json_decode( $json, true );
166
			$tableau = (array) json_decode( $json, true );
168
			$retour['squelette']         = 'creation';
167
			$retour['squelette']         = 'creation';
169
			$retour['donnees']['widget'] = $tableau[0];
168
			$retour['donnees']['widget'] = $tableau[0];
170
			// En prévision d'un service permettant la suppression/modification champs supp
169
			// En prévision d'un service permettant la suppression/modification champs supp
171
			$retour['donnees']['widget']['chpSupp'] = $this->rechercherChampsSupp();
170
			$retour['donnees']['widget']['chpSupp'] = $this->rechercherChampsSupp();
172
 
171
 
173
			$urltype     = $this->cel_url_tpl .'?esttype=1';
172
			$urltype     = $this->cel_url_tpl .'?esttype=1';
174
			$jsontype    = $this->getDao()->consulter( $urltype );
173
			$jsontype    = $this->getDao()->consulter( $urltype );
175
			$tableautype = (array) json_decode( $jsontype, true );
174
			$tableautype = (array) json_decode( $jsontype, true );
176
			$retour['donnees']['type'] = $tableautype;
175
			$retour['donnees']['type'] = $tableautype;
177
		}//print_r($retour['donnees']);
176
		}//print_r($retour['donnees']);
178
 
177
 
179
		return $retour;
178
		return $retour;
180
	}
179
	}
181
 
180
 
182
	private function traiterParametres() {
181
	private function traiterParametres() {
183
		$parametres_flux = '?';
182
		$parametres_flux = '?';
184
		$criteres        = array( 'projet', 'langue', 'titre' );
183
		$criteres        = array( 'projet', 'langue', 'titre' );
185
 
184
 
186
		foreach( $this->parametres as $nom_critere => $valeur_critere ) {
185
		foreach( $this->parametres as $nom_critere => $valeur_critere ) {
187
			if ( in_array( $nom_critere, $criteres ) ) {
186
			if ( in_array( $nom_critere, $criteres ) ) {
188
				$valeur_critere   = str_replace( ' ', '%20', $valeur_critere );
187
				$valeur_critere   = str_replace( ' ', '%20', $valeur_critere );
189
				$parametres_flux .= $nom_critere . '=' . $valeur_critere . '&';
188
				$parametres_flux .= $nom_critere . '=' . $valeur_critere . '&';
190
			}
189
			}
191
		}
190
		}
192
 
191
 
193
		$parametres_flux = ( $parametres_flux === '?' ) ? '' : rtrim( $parametres_flux, '&' );
192
		$parametres_flux = ( $parametres_flux === '?' ) ? '' : rtrim( $parametres_flux, '&' );
194
 
193
 
195
		return $parametres_flux;
194
		return $parametres_flux;
196
	}
195
	}
197
 
196
 
198
	private function traiterParametresModif() {
197
	private function traiterParametresModif() {
199
		$parametres_modif = array();
198
		$parametres_modif = array();
200
 
199
 
201
		foreach ( $_POST as $id => $parametres ) {
200
		foreach ( $_POST as $id => $parametres ) {
202
			if ($parametres !== '' ) {
201
			if ($parametres !== '' ) {
203
				$parametres_modif[$id] = addslashes($parametres);
202
				$parametres_modif[$id] = addslashes($parametres);
204
			} else {
203
			} else {
205
				$parametres_modif[$id] = ' ';
204
				$parametres_modif[$id] = ' ';
206
			}
205
			}
207
		}
206
		}
208
		return $parametres_modif;
207
		return $parametres_modif;
209
	}
208
	}
210
 
209
 
211
	private function traiterDonneesFiles() {
210
	private function traiterDonneesFiles() {
212
		$return = array();
211
		$return = array();
213
		$transmettre_donnees = false;
212
		$transmettre_donnees = false;
214
		$files_names = array();
213
		$files_names = array();
215
		$help_files_names = array();
214
		$help_files_names = array();
216
		$error =
215
		$error =
217
			"<div class=\"message-echec container\">Echec du téléchargement : ".
216
			"<div class=\"message-echec container\">Echec du téléchargement : ".
218
			"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
217
			"L\'extention de l\'image pour " . $nom . " n\'est pas bonne".
219
			", formats acceptés : png, gif, jpg, jpeg, csv, ou tsv.".
218
			", formats acceptés : png, gif, jpg, jpeg, csv, ou tsv.".
220
			"</div>";
219
			"</div>";
221
		$image_projet_langue = ( $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
220
		$image_projet_langue = ( $this->parametres['langue'] !== 'fr' ) ? '_' . $this->parametres['langue'] : '';
222
		$dossier_url = __DIR__ . '/squelettes/img/images_projets/' . $_POST['projet'] . $image_projet_langue . '/';
221
		$dossier_url = __DIR__ . '/squelettes/img/images_projets/' . $_POST['projet'] . $image_projet_langue . '/';
223
 
222
 
224
		foreach ( array_keys( $_FILES ) as $file ) {
223
		foreach ( array_keys( $_FILES ) as $file ) {
225
			if ( $_FILES[$file]['name'] !== '' ) {
224
			if ( $_FILES[$file]['name'] !== '' ) {
226
				$extension = $this->obtenirExtension( $_FILES[$file] );
225
				$extension = $this->obtenirExtension( $_FILES[$file] );
227
 
226
 
228
				if ( $extension ) {
227
				if ( $extension ) {
229
					$transmettre_donnees = true;
228
					$transmettre_donnees = true;
230
 
229
 
231
					if ( strstr( $file, 'help-') ) {
230
					if ( strstr( $file, 'help-') ) {
232
						// Pas besoin de $return :
231
						// Pas besoin de $return :
233
						// Type déjà transmis dans le json des champs supp
232
						// Type déjà transmis dans le json des champs supp
234
						$real_file_key = str_replace( 'help-', '', $file );
233
						$real_file_key = str_replace( 'help-', '', $file );
235
						$help_files_names[$real_file_key] = $real_file_key . '.' . $extension;
234
						$help_files_names[$real_file_key] = $real_file_key . '.' . $extension;
236
					} else {
235
					} else {
237
						$return[$file] = $_FILES[$file]['type'];
236
						$return[$file] = $_FILES[$file]['type'];
238
						$files_names[$file] = $file .'.' . $extension;
237
						$files_names[$file] = $file .'.' . $extension;
239
					}
238
					}
240
				} else {
239
				} else {
241
					echo $error;
240
					echo $error;
242
				}
241
				}
243
			}
242
			}
244
		}
243
		}
245
 
244
 
246
		if ( $transmettre_donnees ) {
245
		if ( $transmettre_donnees ) {
247
			if( !is_dir( $dossier_url ) ) {
246
			if( !is_dir( $dossier_url ) ) {
248
				mkdir( $dossier_url, 0755 );
247
				mkdir( $dossier_url, 0755 );
249
			}
248
			}
250
			// Téléversements
249
			// Téléversements
251
			if ( count( $files_names ) > 0 ) {
250
			if ( count( $files_names ) > 0 ) {
252
				foreach ( array_keys( $files_names ) as $file ) {
251
				foreach ( array_keys( $files_names ) as $file ) {
253
					$this->televerser( $file, $files_names[ $file ], $dossier_url );
252
					$this->televerser( $file, $files_names[ $file ], $dossier_url );
254
				}
253
				}
255
			}
254
			}
256
			if ( count( $help_files_names ) > 0 ) {
255
			if ( count( $help_files_names ) > 0 ) {
257
				foreach ( array_keys( $help_files_names ) as $file ) {
256
				foreach ( array_keys( $help_files_names ) as $file ) {
258
					$this->televerser( 'help-' . $file, $help_files_names[ $file ], $dossier_url );
257
					$this->televerser( 'help-' . $file, $help_files_names[ $file ], $dossier_url );
259
				}
258
				}
260
			}
259
			}
261
		}
260
		}
262
		return $return;
261
		return $return;
263
	}
262
	}
264
 
263
 
265
	private function televerser( $file, $full_name, $dossier_url ) {
264
	private function televerser( $file, $full_name, $dossier_url ) {
266
		$taille_maxi  = 5242880;
265
		$taille_maxi  = 5242880;
267
		$taille       = filesize( $_FILES[$file]['tmp_name'] );
266
		$taille       = filesize( $_FILES[$file]['tmp_name'] );
268
		$extension    = $this->obtenirExtension( $_FILES[$file] );
267
		$extension    = $this->obtenirExtension( $_FILES[$file] );
269
		$file_name    = str_replace( '.' . $extension, '', $full_name );
268
		$file_name    = str_replace( '.' . $extension, '', $full_name );
270
		$file_exists  = file_exists( $dossier_url . $full_name );
269
		$file_exists  = file_exists( $dossier_url . $full_name );
271
		$ex_file_name = $full_name;
270
		$ex_file_name = $full_name;
272
 
271
 
273
		// verifier l'existance d'un fichier avec une extention différente
272
		// verifier l'existance d'un fichier avec une extention différente
274
		// ex: logo.png vers logo.jpg
273
		// ex: logo.png vers logo.jpg
275
		if ( !$file_exists ) {
274
		if ( !$file_exists ) {
276
			switch ( $extension ) {
275
			switch ( $extension ) {
277
				case 'png':
276
				case 'png':
278
					$ex_file_name = $file_name . '.jpg';
277
					$ex_file_name = $file_name . '.jpg';
279
					break;
278
					break;
280
				case 'csv':
279
				case 'csv':
281
					$ex_file_name = $file_name . '.tsv';
280
					$ex_file_name = $file_name . '.tsv';
282
					break;
281
					break;
283
				case 'tsv':
282
				case 'tsv':
284
					$ex_file_name = $file_name . '.csv';
283
					$ex_file_name = $file_name . '.csv';
285
					break;
284
					break;
286
				case 'jpg':
285
				case 'jpg':
287
				default:
286
				default:
288
					$ex_file_name = $file_name . '.png';
287
					$ex_file_name = $file_name . '.png';
289
					break;
288
					break;
290
			}
289
			}
291
			$file_exists = file_exists( $dossier_url . $ex_file_name );
290
			$file_exists = file_exists( $dossier_url . $ex_file_name );
292
		}
291
		}
293
 
292
 
294
		//Début des vérifications de sécurité...
293
		//Début des vérifications de sécurité...
295
		if ( $file_exists ) {
294
		if ( $file_exists ) {
296
			if ( $this->parametres['mode'] === 'modification' ) {
295
			if ( $this->parametres['mode'] === 'modification' ) {
297
				// Le fichier existe déjà, c'est normal si on est en mode modification
296
				// Le fichier existe déjà, c'est normal si on est en mode modification
298
				unlink( $dossier_url . $ex_file_name );
297
				unlink( $dossier_url . $ex_file_name );
299
			} else {
298
			} else {
300
				$erreur =
299
				$erreur =
301
					"<div class=\"message-echec container\">Echec du téléchargement : ".
300
					"<div class=\"message-echec container\">Echec du téléchargement : ".
302
						"Un fichier pour \"" . $file_name.
301
						"Un fichier pour \"" . $file_name.
303
						"\", existe déjà dans un projet nommé \"" . $_POST['projet'] . "\".".
302
						"\", existe déjà dans un projet nommé \"" . $_POST['projet'] . "\".".
304
						"<br>Vérifiez que le nom du projet n'est pas déjà pris, ".
303
						"<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.".
304
						"ou qu'un fichier \"" . $full_name . "\" n'ait pas déjà été téléchargé pour ce projet.".
306
					"</div>";
305
					"</div>";
307
			}
306
			}
308
		}
307
		}
309
 
308
 
310
		if ( !$extension ) {
309
		if ( !$extension ) {
311
			//Si le format n'est pas bon
310
			//Si le format n'est pas bon
312
			$erreur =
311
			$erreur =
313
				"<div class=\"message-echec container\">".
312
				"<div class=\"message-echec container\">".
314
					"Echec du téléchargement pour ".
313
					"Echec du téléchargement pour ".
315
					"\"" . $file_name . "\" ".
314
					"\"" . $file_name . "\" ".
316
					", formats acceptés : png, gif, jpg, jpeg, csv, ou tsv".
315
					", formats acceptés : png, gif, jpg, jpeg, csv, ou tsv".
317
				"</div>";
316
				"</div>";
318
		}
317
		}
319
 
318
 
320
		if ( $taille > $taille_maxi ) {
319
		if ( $taille > $taille_maxi ) {
321
			$erreur =
320
			$erreur =
322
				"<div class=\"message-echec container\">".
321
				"<div class=\"message-echec container\">".
323
					"Echec du téléchargement pour ".
322
					"Echec du téléchargement pour ".
324
					"\"" . $file_name . "\" ".
323
					"\"" . $file_name . "\" ".
325
					": Max 5Mo".
324
					": Max 5Mo".
326
				"</div>";
325
				"</div>";
327
		}
326
		}
328
 
327
 
329
		if ( isset( $erreur ) ) {
328
		if ( isset( $erreur ) ) {
330
			echo $erreur;
329
			echo $erreur;
331
		} else {
330
		} else {
332
			$dest_file = $dossier_url . $this->remove_accents( $full_name );
331
			$dest_file = $dossier_url . $this->remove_accents( $full_name );
333
			if ( !move_uploaded_file( $_FILES[$file]['tmp_name'], $dest_file ) ) {
332
			if ( !move_uploaded_file( $_FILES[$file]['tmp_name'], $dest_file ) ) {
334
			// move_uploaded_file() renvoie false si l'upload a échoué
333
			// move_uploaded_file() renvoie false si l'upload a échoué
335
				echo
334
				echo
336
					"<div class=\"message-echec container\">".
335
					"<div class=\"message-echec container\">".
337
						"Erreur du téléchargement pour ".
336
						"Erreur du téléchargement pour ".
338
						"\"" . $file_name . "\"".
337
						"\"" . $file_name . "\"".
339
					"</div>";
338
					"</div>";
340
			} else {
339
			} else {
341
				chmod($dest_file, 0666);
340
				chmod($dest_file, 0666);
342
			}
341
			}
343
		}
342
		}
344
	}
343
	}
345
 
344
 
346
	private function obtenirExtension( $files ) {
345
	private function obtenirExtension( $files ) {
347
		$type = exif_imagetype( $files['tmp_name'] );
346
		$type = exif_imagetype( $files['tmp_name'] );
348
 
347
 
349
		//une vérif pas mal pour les types image
348
		//une vérif pas mal pour les types image
350
		if ( $type == ( IMAGETYPE_PNG || IMAGETYPE_JPEG || IMAGETYPE_GIF ) ) {
349
		if ( $type == ( IMAGETYPE_PNG || IMAGETYPE_JPEG || IMAGETYPE_GIF ) ) {
351
			switch ( $type ) {
350
			switch ( $type ) {
352
				case '1' :
351
				case '1' :
353
					$format = 'gif';
352
					$format = 'gif';
354
					break;
353
					break;
355
			 	case '2' :
354
			 	case '2' :
356
					$format = 'jpg';
355
					$format = 'jpg';
357
					break;
356
					break;
358
			 	case '3' :
357
			 	case '3' :
359
					$format = 'png';
358
					$format = 'png';
360
					break;
359
					break;
361
				default :
360
				default :
362
					break;
361
					break;
363
			}
362
			}
364
		} elseif ( str_replace( '.csv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'csv' ) {
363
		} elseif ( str_replace( '.csv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'csv' ) {
365
			// Pas trouvé mieux pour csv :
364
			// Pas trouvé mieux pour csv :
366
			// Les fonctions qui pourraient utiliser $_FILES[file]["tmp_path"] me répondent "text/plain"...
365
			// Les fonctions qui pourraient utiliser $_FILES[file]["tmp_path"] me répondent "text/plain"...
367
			$format = 'csv';
366
			$format = 'csv';
368
		} elseif ( str_replace( '.tsv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'tab-separated-values' ) {
367
		} elseif ( str_replace( '.tsv' , '', $files['name'] ) && substr( strrchr($files['type'], '/' ), 1 ) === 'tab-separated-values' ) {
369
			$format = 'tsv';
368
			$format = 'tsv';
370
		} else {
369
		} else {
371
			return false;
370
			return false;
372
		}
371
		}
373
		return $format;
372
		return $format;
374
	}
373
	}
375
 
374
 
376
	// En prévision d'un service permettant la suppression/modification champs supp
375
	// En prévision d'un service permettant la suppression/modification champs supp
377
	/* Recherche si un projet a des champs de saisie supplémentaire */
376
	/* Recherche si un projet a des champs de saisie supplémentaire */
378
	private function rechercherChampsSupp() {
377
	private function rechercherChampsSupp() {
379
		$retour = array();
378
		$retour = array();
380
		$projet = $this->parametres['projet'];
379
		$projet = $this->parametres['projet'];
381
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
380
		$url = $this->config['manager']['celChpSupTpl'] .'?projet=' . $projet . '&langue=' . $this->parametres['langue'];
382
		$json = $this->getDao()->consulter($url);
381
		$json = $this->getDao()->consulter($url);
383
		$retour = (array) json_decode($json, true);
382
		$retour = (array) json_decode($json, true);
384
 
383
 
385
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
384
		foreach ( $retour[$projet]['champs-supp'] as $key => $chsup ) {
386
 
385
 
387
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
386
			$retour[$projet]['champs-supp'][$key]['name'] = $this->clean_string( $chsup['name'] );
388
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
387
			$retour[$projet]['champs-supp'][$key]['description'] = $this->clean_string( $chsup['description']);
389
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
388
			$retour[$projet]['champs-supp'][$key]['unit'] = $this->clean_string( $chsup['unit'] );
390
 
389
 
391
			if ( isset( $chsup['fieldValues'] ) ) {
390
			if ( isset( $chsup['fieldValues'] ) ) {
392
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $this->clean_string( $chsup['fieldValues'] ), true );
391
				$retour[$projet]['champs-supp'][$key]['fieldValues'] = json_decode( $this->clean_string( $chsup['fieldValues'] ), true );
393
 
392
 
394
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
393
				if ( isset( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] ) ) {
395
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
394
					foreach( $retour[$projet]['champs-supp'][$key]['fieldValues']['listValue'] as $list_key => $list_value_array ) {
396
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
395
						// Obtenir une liste de valeurs utilisables dans les attributs for id ou name par exemple
397
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = ($list_value_array !== 'other') ? 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( strtolower($list_value_array[0] ) ) ) : '';
396
						$retour[$projet]['champs-supp'][$key]['fieldValues']['cleanListValue'][] = ($list_value_array !== 'other') ? 'val-' . preg_replace( '/[^A-Za-z0-9_\-]/', '', $this->remove_accents( strtolower($list_value_array[0] ) ) ) : '';
398
					}
397
					}
399
				}
398
				}
400
			}
399
			}
401
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
400
			$retour[$projet]['champs-supp'][$key]['mandatory'] = intval( $chsup['mandatory'] );
402
		}
401
		}
403
		return $retour;
402
		return $retour;
404
	}
403
	}
405
}
404
}