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