#!/bin/perl
# pics.pl

use strict;
use Archive::Zip;

use CGI qw(:standard);
use myHTML;
ins_dirs;

#print header();

my $act  = param('act');

my $temp      = my_tmp_path();
my $data      = my_dat_path();
my $archiv    = "$temp$act.zip";
my $directory = $dirs{"$act"};
my $files     = $directory . '/*.jpg';

p "<html>";
p "<head>";
p "<title>Download $act.zip</title>";
#p "<script language='JavaScript' type='text/javascript'>";
p "</head>";
p "<body>";

p2 "Das Archiv kann jetzt heruntergeladen werden.<br><br>",
   "Falls ihr eine Fehlermeldung bekommt, was besonders bei einem grossen<br>",
   "Archiv passieren kann, versucht es einfach noch einmal.<br><br>";

unless (-e $archiv) {
   # write_log("download","new $act");
   #`cd \"$directory/\" ; zip -z -r -D \"../$archiv\" * -x content < ../$data/zip_comment`;
   chdir("../bilder");
   my @filesjpg=glob("\"$act/*.jpg\"");
   my @filesjpeg=glob("\"$act/*.jpeg\"");
   my @filesbmp=glob("\"$act/*.bmp\"");
   my @filesgif=glob("\"$act/*.gif\"");
   my @allfiles=(@filesjpg,@filesjpeg,@filesbmp,@filesgif);
   my $zip = Archive::Zip->new();
   foreach (@allfiles) {
      $zip->addFile($_);
   }
   $zip->writeToFileNamed($archiv);
   chdir("../scripts");
}
else {
   # write_log("download","existing $act");
}

p2 "Download <a href='$archiv'>$act.zip<br></a>";

p "</body>";
p "</html>";



