]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/Common.pm
Kosmetik
[kivitendo-erp.git] / SL / Common.pm
index 4cd1d35ed5d3b2543b5c9c807af68a9b376edcbe..5ac63c6952ca6f60697d3629084d712a14c012bb 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;
     }
   }
 
@@ -348,4 +365,23 @@ sub get_vc_details {
   return 1;
 }
 
+sub get_shipto_by_id {
+  $main::lxdebug->enter_sub();
+
+  my ($self, $myconfig, $form, $shipto_id, $prefix) = @_;
+
+  $prefix ||= "";
+
+  my $dbh = $form->dbconnect($myconfig);
+
+  my $query = qq|SELECT * FROM shipto WHERE shipto_id = ?|;
+  my $ref   = selectfirst_hashref_query($form, $dbh, $query, $shipto_id);
+
+  map { $form->{"${prefix}${_}"} = $ref->{$_} } keys %{ $ref } if $ref;
+
+  $dbh->disconnect();
+
+  $main::lxdebug->leave_sub();
+}
+
 1;