416 |
aurelien |
1 |
<?php
|
985 |
aurelien |
2 |
//TODO migrer cette classe lorsqu'elle deviendra utile à nouveau
|
1477 |
aurelien |
3 |
/****
|
|
|
4 |
*
|
|
|
5 |
* Attention classe non migrée !!!!
|
|
|
6 |
*/
|
416 |
aurelien |
7 |
Class InventoryImageExport extends DBAccessor {
|
|
|
8 |
|
|
|
9 |
private $extendSpreadsheetProductor;
|
|
|
10 |
|
|
|
11 |
private $archive;
|
|
|
12 |
private $workbook;
|
|
|
13 |
private $worksheet;
|
|
|
14 |
private $chemin_export_liste;
|
|
|
15 |
|
|
|
16 |
function InventoryImageExport($config) {
|
|
|
17 |
|
|
|
18 |
parent::__construct($config);
|
|
|
19 |
|
|
|
20 |
$this->config=$config;
|
|
|
21 |
$this->extendSpreadsheetProductor = new SpreadsheetProductor();
|
|
|
22 |
$this->extendSpreadsheetProductor->initSpreadsheet();
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
function getElement($uid){
|
|
|
26 |
|
|
|
27 |
$this->authentifier();
|
|
|
28 |
|
|
|
29 |
$tableau = array();
|
|
|
30 |
$tag = $uid[0];
|
|
|
31 |
|
|
|
32 |
$limite = 0;
|
|
|
33 |
$pas = 0;
|
|
|
34 |
|
|
|
35 |
//ini_set('max_execution_time',120);
|
|
|
36 |
|
|
|
37 |
/*if(isset($uid[1]) && isset($uid[2])) {
|
|
|
38 |
$limite = $uid[]
|
|
|
39 |
}*/
|
|
|
40 |
|
|
|
41 |
$taille_archive_courante = 0;
|
|
|
42 |
$index_archive_courante = 0;
|
1391 |
aurelien |
43 |
$taille_max_archive = $this->config['cel']['taille_max_archive'];
|
416 |
aurelien |
44 |
$liens_archives = array();
|
|
|
45 |
|
1391 |
aurelien |
46 |
$DB=$this->connectDB($this->config,'cel');
|
416 |
aurelien |
47 |
|
|
|
48 |
$query_id_id_img = 'SELECT cmc_id_mot_cle_utilisateur, cmc_id_proprietaire FROM cel_mots_cles_images WHERE cmc_id_mot_cle_general = md5("'.$DB->escapeSimple($tag).'")' ;
|
|
|
49 |
|
|
|
50 |
$res =& $DB->query($query_id_id_img);
|
|
|
51 |
|
|
|
52 |
if (DB::isError($res)) {
|
|
|
53 |
$this->logger("InventoryImageExport",'Erreur de requete '.$query_id_id_img);
|
|
|
54 |
die($res->getMessage());
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
$query='SELECT * FROM cel_images';
|
|
|
59 |
|
|
|
60 |
$premier_item = true ;
|
|
|
61 |
while ($row =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
62 |
|
|
|
63 |
$tableau['mots cles'] = array('utilisateur' => $row['cmc_id_proprietaire'], 'mot cle' => $row['cmc_id_mot_cle_utilisateur']);
|
|
|
64 |
|
|
|
65 |
if($premier_item) {
|
|
|
66 |
$query .= ' WHERE ';
|
|
|
67 |
$premier_item = false ;
|
|
|
68 |
}
|
|
|
69 |
else{
|
|
|
70 |
$query .= ' OR ';
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
$query .= '(ci_meta_mots_cles LIKE "%'.$row['cmc_id_mot_cle_utilisateur'].'%" AND ci_ce_utilisateur ="'.$row['cmc_id_proprietaire'].'")' ;
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$query .= ' ORDER BY ci_meta_date_ajout' ;
|
|
|
77 |
|
|
|
78 |
$res =& $DB->query($query);
|
|
|
79 |
|
|
|
80 |
if (DB::isError($res)) {
|
|
|
81 |
die($res->getMessage());
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
$this->logger('Requetes',$query);
|
|
|
85 |
|
|
|
86 |
// création d'un objet 'zipfile'
|
|
|
87 |
$this->archive = new zipfile();
|
|
|
88 |
|
|
|
89 |
$i = 1;
|
|
|
90 |
|
|
|
91 |
$this->initialiserWorkBook($index_archive_courante);
|
|
|
92 |
|
|
|
93 |
while ($image =& $res->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
94 |
|
|
|
95 |
$image['ci_nom_original'] = htmlspecialchars($image['ci_nom_original']);
|
|
|
96 |
$image['ci_id_image'] = htmlspecialchars($image['ci_id_image']);
|
|
|
97 |
$image['ci_meta_date_ajout'] = htmlspecialchars($image['ci_meta_date_ajout']);
|
|
|
98 |
$image['ci_ce_utilisateur'] = htmlspecialchars($image['ci_ce_utilisateur']);
|
|
|
99 |
$image['ci_meta_user_comment'] = htmlspecialchars($image['ci_meta_user_comment']);
|
|
|
100 |
$image['ci_note_image'] = htmlspecialchars($image['ci_note_image']);
|
|
|
101 |
|
|
|
102 |
$id = $image['ci_id_image'];
|
|
|
103 |
|
|
|
104 |
$tableau[$id]['image'] = $image;
|
|
|
105 |
|
|
|
106 |
if($filename = $this->renvoyerCheminSurServeur($id,false)) {
|
|
|
107 |
|
|
|
108 |
// appel de la classe
|
|
|
109 |
// nom du fichier à ajouter dans l'archive
|
|
|
110 |
// contenu du fichier
|
|
|
111 |
$fp = fopen ($filename, 'r');
|
|
|
112 |
$content = fread($fp, filesize($filename));
|
|
|
113 |
fclose ($fp);
|
|
|
114 |
|
|
|
115 |
// ajout du fichier dans cet objet
|
|
|
116 |
if(preg_match('/\.(?:jpg|jpeg)$/i',$image['ci_nom_original'])) {
|
|
|
117 |
$nom_fichier_image = preg_replace('/\.(?:jpg|jpeg)$/i','_'.$id.'.jpg', $image['ci_nom_original']);
|
|
|
118 |
} else {
|
|
|
119 |
$nom_fichier_image = $image['ci_nom_original'].'_'.$id.'.jpg';
|
|
|
120 |
}
|
|
|
121 |
|
1391 |
aurelien |
122 |
$chemin_sur_serveur = $this->config['cel']['url_images'];
|
416 |
aurelien |
123 |
|
|
|
124 |
$id = sprintf('%09s', $id) ;
|
|
|
125 |
$id = wordwrap($id, 3 , '_', true) ;
|
996 |
aurelien |
126 |
$niveauDossier = explode("_", $id) ;
|
416 |
aurelien |
127 |
|
|
|
128 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
129 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
130 |
|
|
|
131 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
|
|
132 |
|
666 |
aurelien |
133 |
$chemin_fichier = $chemin_sur_serveur_final.'/O/'.$id."_O.jpg" ;
|
416 |
aurelien |
134 |
|
|
|
135 |
$obs_liee['url_image_liee'] = $chemin_fichier;
|
|
|
136 |
|
|
|
137 |
$taille_fichier = filesize($filename);
|
|
|
138 |
|
|
|
139 |
$req_liaison = 'SELECT * FROM cel_inventory WHERE ordre IN (SELECT coi_ce_observation FROM cel_obs_images WHERE coi_ce_image = "'.$image['ci_id_image'].'") AND identifiant = "'.$image['ci_ce_utilisateur'].'"' ;
|
|
|
140 |
$res_liaison =& $DB->query($req_liaison);
|
|
|
141 |
|
|
|
142 |
if (DB::isError($res_liaison)) {
|
|
|
143 |
die($res_liaison->getMessage());
|
|
|
144 |
}
|
|
|
145 |
|
|
|
146 |
if (DB::isError($res_liaison)) {
|
|
|
147 |
die($res_liaison->getMessage());
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
while($obs_liee = & $res_liaison->fetchrow(DB_FETCHMODE_ASSOC)) {
|
|
|
151 |
|
|
|
152 |
$tableau[$id]['obs'] = $obs_liee;
|
|
|
153 |
$obs_liee['nom_image_liee'] = $nom_fichier_image;
|
|
|
154 |
$obs_liee['url_image_liee'] = $chemin_fichier;
|
|
|
155 |
|
|
|
156 |
$this->ecrireLigneWorkBook($i,$obs_liee);
|
|
|
157 |
|
|
|
158 |
$i++;
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
//$this->archive->addfile($content, $nom_fichier_image);
|
|
|
162 |
//$taille_archive_courante += $taille_fichier;
|
|
|
163 |
|
|
|
164 |
if($taille_archive_courante <= $taille_max_archive) {
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
} else {
|
|
|
168 |
|
|
|
169 |
// fermeture du workbook
|
|
|
170 |
$this->workbook->close();
|
|
|
171 |
$i = 1;
|
|
|
172 |
|
|
|
173 |
// ajout du fichier liste dans cet objet
|
|
|
174 |
// contenu du fichier
|
|
|
175 |
$fp = fopen($this->chemin_export_liste, 'r');
|
|
|
176 |
$contenu = fread($fp, filesize($this->chemin_export_liste));
|
|
|
177 |
fclose ($fp);
|
|
|
178 |
|
|
|
179 |
$this->archive->addfile($contenu,'liste.'.md5($tag).'_'.$index_archive_courante.'.xls');
|
|
|
180 |
|
|
|
181 |
$liens_archives[] = $this->enregistrerArchive($this->archive,$index_archive_courante,$tag);
|
|
|
182 |
$index_archive_courante++;
|
|
|
183 |
$taille_archive_courante = 0;
|
|
|
184 |
|
|
|
185 |
$this->archive = new zipfile();
|
|
|
186 |
$this->initialiserWorkBook($index_archive_courante);
|
|
|
187 |
}
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
//$this->verifierOuRelancerExecution();
|
|
|
191 |
//$this->logger('InventoryImageExport'," Temps d'éxécution à l'image ".$id." : ".$this->getTempsEcoule());
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
// fermeture du workbook
|
|
|
195 |
$this->workbook->close();
|
|
|
196 |
$i = 1;
|
|
|
197 |
|
|
|
198 |
// ajout du fichier liste dans cet objet
|
|
|
199 |
// contenu du fichier
|
|
|
200 |
$fp = fopen($this->chemin_export_liste, 'r');
|
|
|
201 |
$contenu = fread($fp, filesize($this->chemin_export_liste));
|
|
|
202 |
fclose ($fp);
|
|
|
203 |
|
|
|
204 |
$this->archive->addfile($contenu,'liste.'.md5($tag).'_'.$index_archive_courante.'.xls');
|
|
|
205 |
|
|
|
206 |
$liens_archives[] = $this->enregistrerArchive($this->archive,$index_archive_courante,$tag);
|
|
|
207 |
$index_archive_courante++;
|
|
|
208 |
|
|
|
209 |
$j = 1;
|
|
|
210 |
$sortie = '<div><ul>';
|
|
|
211 |
foreach($liens_archives as $lien) {
|
|
|
212 |
$sortie .= '<li> <a href = "'.$lien.'"> Partie '.$j.'</a></li>';
|
|
|
213 |
$j++;
|
|
|
214 |
}
|
|
|
215 |
|
|
|
216 |
$sortie .= '</div></ul>';
|
|
|
217 |
|
|
|
218 |
//$this->logger('InventoryImageExport',count($tableau));
|
|
|
219 |
|
|
|
220 |
//$this->logger('InventoryImageExport',print_r($tableau,true));
|
|
|
221 |
|
|
|
222 |
header('Content-Type: text/html');
|
|
|
223 |
echo $sortie;
|
|
|
224 |
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
|
|
|
228 |
function getRessource(){
|
|
|
229 |
//$this->getElement();
|
|
|
230 |
}
|
|
|
231 |
|
|
|
232 |
public function authentifier() {
|
|
|
233 |
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
|
234 |
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
|
|
|
235 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
236 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
237 |
echo 'Accès interdit';
|
|
|
238 |
exit;
|
|
|
239 |
} else {
|
|
|
240 |
if($this->verifierAcces($_SERVER['PHP_AUTH_USER'])) {
|
|
|
241 |
return ;
|
|
|
242 |
}
|
|
|
243 |
else
|
|
|
244 |
{
|
|
|
245 |
header('WWW-Authenticate: Basic realm="www.tela-botanica.org"');
|
|
|
246 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
247 |
header('Content-type: text/html; charset=UTF-8');
|
|
|
248 |
echo 'Accès interdit';
|
|
|
249 |
exit ;
|
|
|
250 |
}
|
|
|
251 |
}
|
|
|
252 |
}
|
|
|
253 |
|
|
|
254 |
public function verifierAcces($id) {
|
|
|
255 |
|
|
|
256 |
$DB=$this->connectDB($this->config,'database_ident');
|
|
|
257 |
$query="SELECT ".$this->config['database_ident']['ann_id']." as name FROM ".$this->config['database_ident']['annuaire']." WHERE ".$this->config['database_ident']['ann_id']." ='".$DB->escapeSimple($id)
|
|
|
258 |
."' AND ".$this->config['database_ident']['ann_pwd']." = ".$this->config['database_ident']['pass_crypt_funct']."('".$DB->escapeSimple($_SERVER['PHP_AUTH_PW'])."')" ;
|
|
|
259 |
|
|
|
260 |
$res =& $DB->getOne($query);
|
|
|
261 |
|
|
|
262 |
if($res == "") {
|
|
|
263 |
return false ;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
if (DB::isError($res)) {
|
|
|
267 |
die($res->getMessage());
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
return $this->isAdmin($id) ;
|
|
|
271 |
|
|
|
272 |
}
|
|
|
273 |
|
|
|
274 |
private function renvoyerCheminSurServeur($id,$url = true) {
|
|
|
275 |
|
|
|
276 |
if($url) {
|
1391 |
aurelien |
277 |
$chemin_sur_serveur = $this->config['cel']['url_images'];
|
416 |
aurelien |
278 |
} else {
|
1391 |
aurelien |
279 |
$chemin_sur_serveur = $this->config['cel']['chemin_images'];
|
416 |
aurelien |
280 |
}
|
|
|
281 |
|
|
|
282 |
$id = sprintf('%09s', $id) ;
|
|
|
283 |
$id = wordwrap($id, 3 , '_', true) ;
|
|
|
284 |
|
|
|
285 |
$id_fichier = $id.".jpg" ;
|
|
|
286 |
|
996 |
aurelien |
287 |
$niveauDossier = explode("_", $id) ;
|
416 |
aurelien |
288 |
|
|
|
289 |
$dossierNiveau1 = $niveauDossier[0] ;
|
|
|
290 |
$dossierNiveau2 = $niveauDossier[1] ;
|
|
|
291 |
|
|
|
292 |
$chemin_sur_serveur_final = $chemin_sur_serveur.'/'.$dossierNiveau1.'/'.$dossierNiveau2 ;
|
|
|
293 |
|
|
|
294 |
$chemin_fichier = $chemin_sur_serveur_final.'/L/'.$id."_L.jpg" ;
|
|
|
295 |
|
|
|
296 |
return $chemin_fichier;
|
|
|
297 |
}
|
|
|
298 |
|
|
|
299 |
private function renvoyerCheminExport($url = true) {
|
|
|
300 |
if($url) {
|
1391 |
aurelien |
301 |
return $this->config['cel']['url_export'];
|
416 |
aurelien |
302 |
} else {
|
1391 |
aurelien |
303 |
return $this->config['cel']['chemin_export'];
|
416 |
aurelien |
304 |
}
|
|
|
305 |
}
|
|
|
306 |
|
|
|
307 |
private function enregistrerArchive($zip,$index,$tag) {
|
|
|
308 |
|
|
|
309 |
// production de l'archive' Zip
|
|
|
310 |
$this->archive = $zip->file();
|
|
|
311 |
$chemin_export = $this->renvoyerCheminExport(false);
|
|
|
312 |
$url_export = $this->renvoyerCheminExport(true);
|
|
|
313 |
|
|
|
314 |
$chemin_archive = $chemin_export.'/'.md5($tag).'_'.$index.'.zip';
|
|
|
315 |
$url_archive = $url_export.'/'.md5($tag).'_'.$index.'.zip';
|
|
|
316 |
|
|
|
317 |
$fp = fopen($chemin_archive,'w+');
|
|
|
318 |
$ecriture = fwrite($fp,$this->archive);
|
|
|
319 |
fclose($fp);
|
|
|
320 |
|
|
|
321 |
if($ecriture) {
|
|
|
322 |
return $url_archive;
|
|
|
323 |
} else {
|
|
|
324 |
return false;
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
}
|
|
|
328 |
|
|
|
329 |
private function initialiserWorkBook($index) {
|
|
|
330 |
|
|
|
331 |
// Creating a workbook
|
|
|
332 |
$this->chemin_export_liste = $this->renvoyerCheminExport(false).'/liste'.$index.'.xls';
|
|
|
333 |
$this->workbook = new Spreadsheet_Excel_Writer($this->chemin_export_liste);
|
|
|
334 |
|
|
|
335 |
// Creating a worksheet
|
|
|
336 |
$this->worksheet = $this->workbook->addWorksheet('Liste');
|
|
|
337 |
|
|
|
338 |
$this->worksheet->write(0,0,'url de l\'image');
|
|
|
339 |
$this->worksheet->write(0,1,'Nom original de l\'image');
|
|
|
340 |
//$this->worksheet->write(0,1,'Nom saisi');
|
|
|
341 |
//$this->worksheet->write(0,2,'Numero nomenclatural');
|
|
|
342 |
$this->worksheet->write(0,2,'Nom retenu');
|
|
|
343 |
$this->worksheet->write(0,3,'Numero nomenclatural nom retenu');
|
|
|
344 |
$this->worksheet->write(0,4,'Numero taxonomique');
|
|
|
345 |
$this->worksheet->write(0,5,'Famille');
|
|
|
346 |
//$this->worksheet->write(0,7,'Commune');
|
|
|
347 |
//$this->worksheet->write(0,8,'Identifiant Commune');
|
|
|
348 |
$this->worksheet->write(0,6,'Date Observation');
|
|
|
349 |
// $this->worksheet->write(0,10,'Lieu dit');
|
|
|
350 |
//$this->worksheet->write(0,11,'Station');
|
|
|
351 |
//$this->worksheet->write(0,12,'Milieu');
|
|
|
352 |
$this->worksheet->write(0,7,'Contributeur');
|
|
|
353 |
$this->worksheet->write(0,8,'Commentaire');
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
private function ecrireLigneWorkBook($index, $observation) {
|
|
|
357 |
|
|
|
358 |
$this->worksheet->write($index,0,$observation['url_image_liee']);
|
|
|
359 |
$this->worksheet->write($index,1,$observation['nom_image_liee']);
|
|
|
360 |
//$this->worksheet->write($index,1,$observation['nom_sel']);
|
|
|
361 |
//$this->worksheet->write($index,2,$observation['num_nom_sel']);
|
|
|
362 |
$this->worksheet->write($index,2,$observation['nom_ret']);
|
|
|
363 |
$this->worksheet->write($index,3,$observation['num_nom_ret']);
|
|
|
364 |
$this->worksheet->write($index,4,$observation['num_taxon']);
|
|
|
365 |
$this->worksheet->write($index,5,$observation['famille']);
|
|
|
366 |
//$this->worksheet->write($index,7,$observation['location']);
|
|
|
367 |
//$this->worksheet->write($index,8,$observation['id_location']);
|
|
|
368 |
$this->worksheet->write($index,6,$observation['date_observation']);
|
|
|
369 |
//$this->worksheet->write($index,10,$observation['lieudit']);
|
|
|
370 |
//$this->worksheet->write($index,11,$observation['station']);
|
|
|
371 |
//$this->worksheet->write($index,12,$observation['milieu']);
|
|
|
372 |
$this->worksheet->write($index,7,$observation['identifiant']);
|
|
|
373 |
$this->worksheet->write($index,8,$observation['commentaire']);
|
|
|
374 |
}
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
|
|
|
378 |
/* +--Fin du code ---------------------------------------------------------------------------------------+
|
|
|
379 |
* $Log$
|
|
|
380 |
* Revision 1.5 2008-11-13 11:29:12 ddelon
|
|
|
381 |
* Reecriture gwt-ext
|
|
|
382 |
*
|
|
|
383 |
* Revision 1.4 2007-06-06 13:31:16 ddelon
|
|
|
384 |
* v0.09
|
|
|
385 |
*
|
|
|
386 |
* Revision 1.3 2007-05-22 12:54:09 ddelon
|
|
|
387 |
* Securisation acces utilisateur
|
|
|
388 |
*
|
|
|
389 |
*
|
|
|
390 |
*
|
|
|
391 |
*/
|
|
|
392 |
|
|
|
393 |
?>
|