Deutliche Beschleunigung der USTVA-Berechnung durch Einschränkung der betrachteten...
[kivitendo-erp.git] / SL / Common.pm
index fdf2b28..43b9aaa 100644 (file)
@@ -260,7 +260,7 @@ sub webdav_folder {
 
   my ($path, $number);
 
-  $form->{WEBDAV} = {};
+  $form->{WEBDAV} = [];
 
   if ($form->{type} eq "sales_quotation") {
     ($path, $number) = ("angebote", $form->{quonumber});
@@ -280,6 +280,8 @@ sub webdav_folder {
 
   return $main::lxdebug->leave_sub() unless ($path && $number);
 
+  $number =~ s|[/\\]|_|g;
+
   $path = "webdav/${path}/${number}";
 
   if (!-d $path) {
@@ -288,13 +290,28 @@ sub webdav_folder {
   } else {
     my $base_path = substr($ENV{'SCRIPT_NAME'}, 1);
     $base_path =~ s|[^/]+$||;
+    $base_path =~ s|/$||;
+
+    if (opendir $dir, $path) {
+      foreach my $file (sort { lc $a cmp lc $b } readdir $dir) {
+        next if (($file eq '.') || ($file eq '..'));
+
+        my $fname = $file;
+        $fname  =~ s|.*/||;
+
+        my $is_directory = -d "$path/$file";
+
+        $file  = join('/', map { $form->escape($_) } grep { $_ } split m|/+|, "$path/$file");
+        $file .=  '/' if ($is_directory);
 
-    foreach my $file (<$path/*>) {
-      my $fname = $file;
-      $fname =~ s|.*/||;
-      $form->{WEBDAV}{$fname} =
-        ($ENV{"HTTPS"} ? "https://" : "http://") .
-        $ENV{'SERVER_NAME'} . "/" . $base_path . $file;
+        push @{ $form->{WEBDAV} }, {
+          'name' => $fname,
+          'link' => ($ENV{"HTTPS"} ? "https://" : "http://") . $ENV{'SERVER_NAME'} . "/$base_path/$file",
+          'type' => $is_directory ? $main::locale->text('Directory') : $main::locale->text('File'),
+        };
+      }
+
+      closedir $dir;
     }
   }
 
@@ -367,4 +384,66 @@ sub get_shipto_by_id {
   $main::lxdebug->leave_sub();
 }
 
+sub save_email_status {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form) = @_;
+
+  my ($table, $query, $dbh);
+
+  if ($form->{script} eq 'oe.pl') {
+    $table = 'oe';
+
+  } elsif ($form->{script} eq 'is.pl') {
+    $table = 'ar';
+
+  } elsif ($form->{script} eq 'ir.pl') {
+    $table = 'ap';
+
+  }
+
+  return $main::lxdebug->leave_sub() if (!$form->{id} || !$table || !$form->{formname});
+
+  $dbh = $form->get_standard_dbh($myconfig);
+
+  my ($intnotes) = selectrow_query($form, $dbh, qq|SELECT intnotes FROM $table WHERE id = ?|, $form->{id});
+
+  $intnotes =~ s|\r||g;
+  $intnotes =~ s|\n$||;
+
+  $intnotes .= "\n\n" if ($intnotes);
+
+  my $cc  = $main::locale->text('Cc') . ": $form->{cc}\n"   if $form->{cc};
+  my $bcc = $main::locale->text('Bcc') . ": $form->{bcc}\n" if $form->{bcc};
+  my $now = scalar localtime;
+
+  $intnotes .= $main::locale->text('[email]') . "\n"
+    . $main::locale->text('Date') . ": $now\n"
+    . $main::locale->text('To (email)') . ": $form->{email}\n"
+    . "${cc}${bcc}"
+    . $main::locale->text('Subject') . ": $form->{subject}\n\n"
+    . $main::locale->text('Message') . ": $form->{message}";
+
+  $intnotes =~ s|\r||g;
+
+  do_query($form, $dbh, qq|UPDATE $table SET intnotes = ? WHERE id = ?|, $intnotes, $form->{id});
+
+  $form->save_status($dbh);
+
+  $dbh->commit();
+
+  $main::lxdebug->leave_sub();
+}
+
+sub check_params {
+  my $params = shift;
+
+  foreach my $key (@_) {
+    if (!defined $params->{$key}) {
+      my $subroutine = (caller(1))[3];
+      $main::form->error($main::locale->text("Missing parameter #1 in call to sub #2.", $key, $subroutine));
+    }
+  }
+}
+
 1;