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},
 
  35     print_variant => $form->{formname},
 
  39 # This method also needed by $form to append all general pdf attachments
 
  41 sub append_general_pdf_attachments {
 
  42   my ($self, %params) = @_;
 
  43   return 0 unless $::instance_conf->get_doc_storage;
 
  44   return 0 if !$params{filepath} || !$params{type};
 
  46   my @files = SL::File->get_all(
 
  48     object_type => $params{type},
 
  49     mime_type   => 'application/pdf'
 
  51   return 0 if $#files < 0;
 
  53   my @pdf_file_names = ($params{filepath});
 
  54   foreach my $file (@files) {
 
  55     my $path = $file->get_file;
 
  56     push @pdf_file_names, $path if $path;
 
  59   #TODO immer noch das alte Problem:
 
  60   #je nachdem von woher der Aufruf kommt ist man in ./users oder .
 
  61   my $savedir = POSIX::getcwd();
 
  62   chdir("$self->{cwd}");
 
  64     file_names => \@pdf_file_names,
 
  65     out_path   => $params{filepath}
 
  80 SL::Helper::File - Helper for $::Form to store generated PDF-Documents
 
  84 # This Helper is used by SL::Form to store new generated PDF-Files and append general attachments to this documents.
 
  88  $self->store_pdf($self);
 
  90  $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type}) if ( $ext_for_format eq 'pdf' );
 
  92 #It is also used in MassPrint Helper
 
  97 The files with file_type "generated" are stored.
 
 106 Copy generated PDF-File to File destination.
 
 107 This method is need from SL::Form after LaTeX-PDF Generation
 
 119 =item C<form.formname>
 
 121 if no type is set this is used as type
 
 123 =item C<form.attachment_id>
 
 125 if no id is set this is used as id
 
 127 =item C<form.tmpfile>
 
 129 The path of the generated PDF-file
 
 131 =item C<form.attachment_filename>
 
 133 The generated filename which is used as new filename (without timestamp)
 
 137 =head2 C<append_general_pdf_attachments PARAMS>
 
 139 This method also needed by SL::Form to append all general pdf attachments
 
 151 Name of file to which the general attachments must be added
 
 157 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>