+
+ print("</body></html>");
+
+ $main::lxdebug->leave_sub();
+}
+
+sub download {
+ $main::lxdebug->enter_sub();
+
+ my $form = $main::form;
+ my $locale = $main::locale;
+
+ $main::auth->assert('datev_export');
+
+ my $tmp_name = Common->tmpname();
+ my $zip_name = strftime("lx-office-datev-export-%Y%m%d.zip", localtime(time()));
+
+ my $cwd = getcwd();
+
+ my $path = DATEV::get_path_for_download_token($form->{download_token});
+ if (!$path) {
+ $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
+ }
+
+ chdir($path) || die("chdir $path");
+
+ my @filenames = glob "*";
+
+ if (!@filenames) {
+ chdir($cwd);
+ DATEV::clean_temporary_directories();
+ $form->error($locale->text("Your download does not exist anymore. Please re-run the DATEV export assistant."));
+ }
+
+ my $zip = Archive::Zip->new();
+ map { $zip->addFile($_); } @filenames;
+ $zip->writeToFileNamed($tmp_name);
+
+ chdir($cwd);
+
+ open(IN, $tmp_name) || die("open $tmp_name");
+ print("Content-Type: application/zip\n");
+ print("Content-Disposition: attachment; filename=\"${zip_name}\"\n\n");
+ while (<IN>) {
+ print($_);
+ }
+ close(IN);
+
+ unlink($tmp_name);
+
+ DATEV::clean_temporary_directories();
+
+ $main::lxdebug->leave_sub();