Changelog-Eintrag zu Gewicht in Verkaufsbericht
[kivitendo-erp.git] / bin / mozilla / io.pl
index 5050e6a..e25f963 100644 (file)
@@ -38,6 +38,7 @@
 
 use Carp;
 use CGI;
+use List::MoreUtils qw(uniq);
 use List::Util qw(min max first);
 
 use SL::CVar;
@@ -962,6 +963,9 @@ sub edit_e_mail {
     $form->{"email"} = $form->{"cp_email"} if $form->{"cp_email"};
   }
 
+  $form->{language} = $form->get_template_language(\%myconfig);
+  $form->{language} = "_" . $form->{language} if $form->{language};
+
   my $title = $locale->text('E-mail') . " " . $form->get_formname_translation();
 
   $form->{oldmedia} = $form->{media};
@@ -1501,14 +1505,8 @@ sub print_form {
   push @template_files, "$form->{formname}$form->{language}$printer_code.$extension";
   push @template_files, "$form->{formname}.$extension";
   push @template_files, "default.$extension";
-
-  $form->{IN} = undef;
-  for my $filename (@template_files) {
-    if (-f "$myconfig{templates}/$filename") {
-      $form->{IN} = $filename;
-      last;
-    }
-  }
+  @template_files = uniq @template_files;
+  $form->{IN}     = first { -f "$myconfig{templates}/$_" } @template_files;
 
   if (!defined $form->{IN}) {
     $::form->error($::locale->text('Cannot find matching template for this print request. Please contact your template maintainer. I tried these: #1.', join ', ', map { "'$_'"} @template_files));
@@ -1537,22 +1535,31 @@ sub print_form {
     my %queued = map { s|.*/|| } split / /, $form->{queued};
 
     my $filename;
+    my $suffix = ($form->{postscript}) ? '.ps' : '.pdf';
     if ($filename = $queued{ $form->{formname} }) {
       $form->{queued} =~ s/\Q$form->{formname} $filename\E//;
       unlink $::lx_office_conf{paths}->{spool} . "/$filename";
       $filename =~ s/\..*$//g;
+      $filename .= $suffix;
+      $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
+      $form->{OUT_MODE} = '>';
     } else {
-      $filename = time;
-      $filename .= $$;
+      my $temp_fh;
+      ($temp_fh, $filename) = File::Temp::tempfile(
+        'kivitendo-spoolXXXXXX',
+        SUFFIX => "$suffix",
+        DIR => $::lx_office_conf{paths}->{spool},
+      );
+      close $temp_fh;
+      $form->{OUT} = "$filename";
+      # use >> for OUT_MODE because file is already created by File::Temp
+      $form->{OUT_MODE} = '>>';
+      # strip directory so that only filename is stored in table status
+      ($filename) = $filename =~ /^$::lx_office_conf{paths}->{spool}\/(.*)/;
     }
 
-    $filename .= ($form->{postscript}) ? '.ps' : '.pdf';
-    $form->{OUT} = $::lx_office_conf{paths}->{spool} . "/$filename";
-    $form->{OUT_MODE} = '>';
-
     # add type
     $form->{queued} .= " $form->{formname} $filename";
-
     $form->{queued} =~ s/^ //;
   }
   my $queued = $form->{queued};