1 package SL::Helper::File;
 
   6 our @EXPORT_OK = qw(store_pdf append_general_pdf_attachments doc_storage_enabled);
 
   7 our %EXPORT_TAGS = (all => \@EXPORT_OK,);
 
  10 sub doc_storage_enabled {
 
  11   return 0 unless $::instance_conf->get_doc_storage;
 
  12   return 1 if     $::instance_conf->get_doc_storage_for_documents eq 'Filesystem' && $::instance_conf->get_doc_files;
 
  13   return 1 if     $::instance_conf->get_doc_storage_for_documents eq 'Webdav'     && $::instance_conf->get_doc_webdav;
 
  18   my ($self, $form) = @_;
 
  19   return unless $self->doc_storage_enabled;
 
  20   my $type = $form->{type};
 
  21   $type = $form->{formname}        if $form->{formname} && !$form->{type};
 
  22   $type = $form->{attachment_type} if $form->{attachment_type};
 
  24   $id = $form->{attachment_id} if $form->{attachment_id} && !$form->{id};
 
  25   return if !$id || !$type;
 
  30     mime_type   => 'application/pdf',
 
  32     file_type   => 'document',
 
  33     file_name   => $form->{attachment_filename},
 
  34     file_path   => $form->{tmpfile},
 
  38 # This method also needed by $form to append all general pdf attachments
 
  40 sub append_general_pdf_attachments {
 
  41   my ($self, %params) = @_;
 
  42   return 0 unless $::instance_conf->get_doc_storage;
 
  43   return 0 if !$params{filepath} || !$params{type};
 
  45   my @files = SL::File->get_all(
 
  47     object_type => $params{type},
 
  48     mime_type   => 'application/pdf'
 
  50   return 0 if $#files < 0;
 
  52   my @pdf_file_names = ($params{filepath});
 
  53   foreach my $file (@files) {
 
  54     my $path = $file->get_file;
 
  55     push @pdf_file_names, $path if $path;
 
  58   #TODO immer noch das alte Problem:
 
  59   #je nachdem von woher der Aufruf kommt ist man in ./users oder .
 
  60   my $savedir = POSIX::getcwd();
 
  61   chdir("$self->{cwd}");
 
  63     file_names => \@pdf_file_names,
 
  64     out_path   => $params{filepath}
 
  79 SL::Helper::File - Helper for $::Form to store generated PDF-Documents
 
  83 # This Helper is used by SL::Form to store new generated PDF-Files and append general attachments to this documents.
 
  87  $self->store_pdf($self);
 
  89  $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type}) if ( $ext_for_format eq 'pdf' );
 
  91 #It is also used in MassPrint Helper
 
  96 The files with file_type "generated" are stored.
 
 105 Copy generated PDF-File to File destination.
 
 106 This method is need from SL::Form after LaTeX-PDF Generation
 
 118 =item C<form.formname>
 
 120 if no type is set this is used as type
 
 122 =item C<form.attachment_id>
 
 124 if no id is set this is used as id
 
 126 =item C<form.tmpfile>
 
 128 The path of the generated PDF-file
 
 130 =item C<form.attachment_filename>
 
 132 The generated filename which is used as new filename (without timestamp)
 
 136 =head2 C<append_general_pdf_attachments PARAMS>
 
 138 This method also needed by SL::Form to append all general pdf attachments
 
 150 Name of file to which the general attachments must be added
 
 156 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>