X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FFile.pm;fp=SL%2FHelper%2FFile.pm;h=e658b05e949a7d8f15ed77f931ddac530adcbe6e;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hp=0000000000000000000000000000000000000000;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44;p=kivitendo-erp.git diff --git a/SL/Helper/File.pm b/SL/Helper/File.pm new file mode 100644 index 000000000..e658b05e9 --- /dev/null +++ b/SL/Helper/File.pm @@ -0,0 +1,160 @@ +package SL::Helper::File; + +use strict; + +use Exporter 'import'; +our @EXPORT_OK = qw(store_pdf append_general_pdf_attachments doc_storage_enabled); +our %EXPORT_TAGS = (all => \@EXPORT_OK,); +use SL::File; + +sub doc_storage_enabled { + return 0 unless $::instance_conf->get_doc_storage; + return 1 if $::instance_conf->get_doc_storage_for_documents eq 'Filesystem' && $::instance_conf->get_doc_files; + return 1 if $::instance_conf->get_doc_storage_for_documents eq 'Webdav' && $::instance_conf->get_doc_webdav; + return 0; +} + +sub store_pdf { + my ($self, $form) = @_; + return unless $self->doc_storage_enabled; + my $type = $form->{type}; + $type = $form->{formname} if $form->{formname} && !$form->{type}; + $type = $form->{attachment_type} if $form->{attachment_type}; + my $id = $form->{id}; + $id = $form->{attachment_id} if $form->{attachment_id} && !$form->{id}; + return if !$id || !$type; + + SL::File->save( + object_id => $id, + object_type => $type, + mime_type => 'application/pdf', + source => 'created', + file_type => 'document', + file_name => $form->{attachment_filename}, + file_path => $form->{tmpfile}, + print_variant => $form->{formname}, + ); +} + +# This method also needed by $form to append all general pdf attachments +# +sub append_general_pdf_attachments { + my ($self, %params) = @_; + return 0 unless $::instance_conf->get_doc_storage; + return 0 if !$params{filepath} || !$params{type}; + + my @files = SL::File->get_all( + object_id => 0, + object_type => $params{type}, + mime_type => 'application/pdf' + ); + return 0 if $#files < 0; + + my @pdf_file_names = ($params{filepath}); + foreach my $file (@files) { + my $path = $file->get_file; + push @pdf_file_names, $path if $path; + } + + #TODO immer noch das alte Problem: + #je nachdem von woher der Aufruf kommt ist man in ./users oder . + my $savedir = POSIX::getcwd(); + chdir("$self->{cwd}"); + $self->merge_pdfs( + file_names => \@pdf_file_names, + out_path => $params{filepath} + ); + chdir("$savedir"); + + return 0; +} + +1; + +__END__ + +=encoding utf-8 + +=head1 NAME + +SL::Helper::File - Helper for $::Form to store generated PDF-Documents + +=head1 SYNOPSIS + +# This Helper is used by SL::Form to store new generated PDF-Files and append general attachments to this documents. +# +# in SL::Form.pm: + + $self->store_pdf($self); + + $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type}) if ( $ext_for_format eq 'pdf' ); + +#It is also used in MassPrint Helper +# + +=head1 DESCRIPTION + +The files with file_type "generated" are stored. + +See also L. + +=head1 METHODS + + +=head2 C + +Copy generated PDF-File to File destination. +This method is need from SL::Form after LaTeX-PDF Generation + +=over 4 + +=item C + +ID of ERP-Document + +=item C + +type of ERP-document + +=item C + +if no type is set this is used as type + +=item C + +if no id is set this is used as id + +=item C + +The path of the generated PDF-file + +=item C + +The generated filename which is used as new filename (without timestamp) + +=back + +=head2 C + +This method also needed by SL::Form to append all general pdf attachments + +needed C: + +=over 4 + +=item C + +type of ERP-document + +=item C + +Name of file to which the general attachments must be added + +=back + +=head1 AUTHOR + +Martin Helmling Emartin.helmling@opendynamic.deE + + +=cut