Auftrags-Controller: Webdav
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 11 Nov 2015 12:20:51 +0000 (13:20 +0100)
committerG. Richardson <information@kivitendo-premium.de>
Mon, 16 Nov 2015 15:15:59 +0000 (16:15 +0100)
SL/Controller/Order.pm

index 6f42213..9310f91 100644 (file)
@@ -9,6 +9,7 @@ use SL::Locale::String;
 use SL::SessionFile::Random;
 use SL::PriceSource;
 use SL::Form;
+use SL::Webdav;
 
 use SL::DB::Order;
 use SL::DB::Customer;
@@ -134,6 +135,24 @@ sub action_create_pdf {
 
   my $pdf_filename = $form->generate_attachment_filename();
 
+  # copy file to webdav folder
+  if ($self->order->ordnumber && $::instance_conf->get_webdav_documents) {
+    my $webdav = SL::Webdav->new(
+      type     => $self->type,
+      number   => $self->order->ordnumber,
+    );
+    my $webdav_file = SL::Webdav::File->new(
+      webdav   => $webdav,
+      filename => $pdf_filename,
+    );
+    eval {
+      $webdav_file->store(data => \$pdf);
+      1;
+    } or do {
+      $self->js->flash('error', t8('Storing PDF to webdav folder failed: #1', $@));
+    }
+  }
+
   $self->js
     ->run('download_pdf', $pdf_filename, $key)
     ->flash('info', t8('The PDF has been created'))->render($self);
@@ -669,6 +688,19 @@ sub _pre_render {
 
   }
 
+  if ($self->order->ordnumber && $::instance_conf->get_webdav) {
+    my $webdav = SL::Webdav->new(
+      type     => $self->type,
+      number   => $self->order->ordnumber,
+    );
+    my $webdav_path = $webdav->webdav_path;
+    my @all_objects = $webdav->get_all_objects;
+    @{ $self->{template_args}->{WEBDAV} } = map { { name => $_->filename,
+                                                    type => t8('File'),
+                                                    link => File::Spec->catdir($webdav_path, $_->filename),
+                                                } } @all_objects;
+  }
+
   $::request->{layout}->use_javascript("${_}.js")  for qw(ckeditor/ckeditor ckeditor/adapters/jquery);
 }