3 # This file is part of Koha.
5 # Copyright 2014 Jacek Ablewicz
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
26 Manage files associated with invoice
36 use Koha
::Misc
::Files
;
39 my ( $template, $loggedinuser, $cookie, $flags ) = get_template_and_user
(
41 template_name
=> 'acqui/invoice-files.tt',
45 flagsrequired
=> { 'acquisition' => '*' },
50 my $invoiceid = $input->param('invoiceid') // '';
51 my $op = $input->param('op') // '';
54 my $mf = Koha
::Misc
::Files
->new( tabletag
=> 'aqinvoices', recordid
=> $invoiceid );
55 defined($mf) || do { $op = 'none'; $errors{'invalid_parameter'} = 1; };
57 if ( $op eq 'download' ) {
58 my $file_id = $input->param('file_id');
59 my $file = $mf->GetFile( id
=> $file_id );
61 my $fname = $file->{'file_name'};
62 my $ftype = $file->{'file_type'};
63 if ($input->param('view') && ($ftype =~ m
|^image
/|i || $fname =~ /\
.pdf
/i
)) {
64 $fname =~ /\.pdf/i && do { $ftype='application/pdf'; };
71 -type
=> $file->{'file_type'},
73 -attachment
=> $file->{'file_name'}
76 print $file->{'file_content'};
79 my $details = GetInvoiceDetails
($invoiceid);
81 invoiceid
=> $details->{'invoiceid'},
82 invoicenumber
=> $details->{'invoicenumber'},
83 suppliername
=> $details->{'suppliername'},
84 booksellerid
=> $details->{'booksellerid'},
85 datereceived
=> $details->{'datereceived'},
88 if ( $op eq 'upload' ) {
89 my $uploaded_file = $input->upload('uploadfile');
92 my $filename = $input->param('uploadfile');
93 my $mimetype = $input->uploadInfo($filename)->{'Content-Type'};
95 $errors{'empty_upload'} = 1 if ( -z
$uploaded_file );
97 my $file_content = do { local $/; <$uploaded_file>; };
98 if ($mimetype =~ /^application\/(force
-download
|unknown
)$/i && $filename =~ /\
.pdf
$/i
) {
99 $mimetype = 'application/pdf';
104 content
=> $file_content,
105 description
=> scalar $input->param('description')
110 $errors{'no_file'} = 1;
112 } elsif ( $op eq 'delete' ) {
113 $mf->DelFile( id
=> scalar $input->param('file_id') );
117 files
=> (defined($mf)?
$mf->GetFilesInfo(): undef),
120 output_html_with_http_headers
$input, $cookie, $template->output;