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