1 package SL::Helper::File;
6 our @EXPORT_OK = qw(store_pdf append_general_pdf_attachments);
7 our %EXPORT_TAGS = (all => \@EXPORT_OK,);
11 my ($self, $form) = @_;
12 return unless $::instance_conf->get_doc_storage;
13 my $type = $form->{type};
14 $type = $form->{formname} if $form->{formname} && !$form->{type};
16 $id = $form->{attachment_id} if $form->{attachment_id} && !$form->{id};
17 return if !$id || !$type;
18 my $prefix = $form->get_number_prefix_for_type();
22 mime_type => 'application/pdf',
24 file_type => 'document',
25 file_name => $form->{attachment_filename},
26 file_path => $form->{tmpfile},
27 file_number => $form->{"${prefix}number"},
31 # This method also needed by $form to append all general pdf attachments
33 sub append_general_pdf_attachments {
34 my ($self, %params) = @_;
35 return 0 unless $::instance_conf->get_doc_storage;
36 return 0 if !$params{filepath} || !$params{type};
38 my @files = SL::File->get_all(
40 object_type => $params{type},
41 mime_type => 'application/pdf'
43 return 0 if $#files < 0;
45 my @pdf_file_names = ($params{filepath});
46 foreach my $file (@files) {
47 my $path = $file->get_file;
48 push @pdf_file_names, $path if $path;
51 #TODO immer noch das alte Problem:
52 #je nachdem von woher der Aufruf kommt ist man in ./users oder .
53 my $savedir = POSIX::getcwd();
54 chdir("$self->{cwd}");
56 file_names => \@pdf_file_names,
57 out_path => $params{filepath}
72 SL::Helper::File - Helper for $::Form to store generated PDF-Documents
77 # This Helper is used by SL::Form to store new generated PDF-Files and append general attachments to this documents.
81 $self->store_pdf($self);
83 $self->append_general_pdf_attachments(filepath => $pdf_filename, type => $form->{type}) if ( $ext_for_format eq 'pdf' );
85 #It is also used in MassPrint Helper
90 The files with file_type "generated" are stored.
99 Copy generated PDF-File to File destination.
100 This method is need from SL::Form after LaTeX-PDF Generation
112 =item C<form.formname>
114 if no type is set this is used as type
116 =item C<form.attachment_id>
118 if no id is set this is used as id
120 =item C<form.tmpfile>
122 The path of the generated PDF-file
124 =item C<form.attachment_filename>
126 The generated filename which is used as new filename (without timestamp)
130 =head2 C<append_general_pdf_attachments PARAMS>
132 This method also needed by SL::Form to append all general pdf attachments
144 Name of file to which the general attachments must be added
150 Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>