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