3 # This file is part of Koha.
5 # Copyright (C) 2015 Rijksmuseum
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 use Koha
::UploadedFiles
;
28 my $input = CGI
::->new;
29 my $op = $input->param('op') // 'new';
30 my $plugin = $input->param('plugin');
31 my $index = $input->param('index'); # MARC editor input field id
32 my $term = $input->param('term');
33 my $id = $input->param('id');
34 my $msg = $input->param('msg');
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
37 { template_name
=> "tools/upload.tt",
41 flagsrequired
=> { tools
=> 'upload_general_files' },
47 owner
=> $loggedinuser,
49 uploadcategories
=> Koha
::UploadedFiles
->getCategories,
56 output_html_with_http_headers
$input, $cookie, $template->output;
58 } elsif ( $op eq 'search' ) {
61 my $rec = Koha
::UploadedFiles
->find( $id );
62 undef $rec if $rec && $plugin && !$rec->public;
63 push @
$uploads, $rec->unblessed if $rec;
65 $uploads = Koha
::UploadedFiles
->search_term({
67 $plugin?
(): ( include_private
=> 1 ),
76 output_html_with_http_headers
$input, $cookie, $template->output;
78 } elsif ( $op eq 'delete' ) {
79 # delete only takes the id parameter
80 my $rec = Koha
::UploadedFiles
->find($id);
81 undef $rec if $rec && $plugin && !$rec->public;
82 my $fn = $rec ?
$rec->filename : '';
83 my $delete = $rec ?
$rec->delete : undef;
84 #TODO Improve error handling
86 ? JSON
::to_json
({ $fn => 6 })
88 ? JSON
::to_json
({ $fn || $id, 7 })
94 output_html_with_http_headers
$input, $cookie, $template->output;
96 } elsif ( $op eq 'download' ) {
97 my $rec = Koha
::UploadedFiles
->find( $id );
98 undef $rec if $rec && $plugin && !$rec->public;
99 my $fh = $rec?
$rec->file_handle: undef;
100 if ( !$rec || !$fh ) {
103 msg
=> JSON
::to_json
( { $id => 5 } ),
105 output_html_with_http_headers
$input, $cookie, $template->output;
107 print Encode
::encode_utf8
( $input->header( $rec->httpheaders ) );