Bug 15208: Ease translation for shelves messages
[koha.git] / tools / upload.pl
blob5d9c8e7719afd0bae298617ca58d24266a9719bd
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
21 use CGI qw/-utf8/;
22 use JSON;
24 use C4::Auth;
25 use C4::Output;
26 use Koha::Upload;
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",
38 query => $input,
39 type => "intranet",
40 authnotrequired => 0,
41 flagsrequired => { editcatalogue => '*' },
45 $template->param(
46 plugin => $plugin,
47 index => $index,
50 my $upar = $plugin ? { public => 1 } : {};
51 if ( $op eq 'new' ) {
52 $template->param(
53 mode => 'new',
54 uploadcategories => Koha::Upload->getCategories,
56 output_html_with_http_headers $input, $cookie, $template->output;
57 } elsif ( $op eq 'search' ) {
58 my $h = $id ? { id => $id } : { term => $term };
59 my @uploads = Koha::Upload->new($upar)->get($h);
60 $template->param(
61 mode => 'report',
62 msg => $msg,
63 uploads => \@uploads,
65 output_html_with_http_headers $input, $cookie, $template->output;
66 } elsif ( $op eq 'delete' ) {
68 # delete only takes the id parameter
69 my $upl = Koha::Upload->new($upar);
70 my ($fn) = $upl->delete( { id => $id } );
71 my $e = $upl->err;
72 my $msg =
73 $fn ? JSON::to_json( { $fn => 6 } )
74 : $e ? JSON::to_json($e)
75 : undef;
76 $template->param(
77 mode => 'deleted',
78 msg => $msg,
79 uploadcategories => $upl->getCategories,
81 output_html_with_http_headers $input, $cookie, $template->output;
82 } elsif ( $op eq 'download' ) {
83 my $upl = Koha::Upload->new($upar);
84 my $rec = $upl->get( { id => $id, filehandle => 1 } );
85 my $fh = $rec->{fh};
86 if ( !$rec || !$fh ) {
87 $template->param(
88 mode => 'new',
89 msg => JSON::to_json( { $id => 5 } ),
90 uploadcategories => $upl->getCategories,
92 output_html_with_http_headers $input, $cookie, $template->output;
93 } else {
94 my @hdr = $upl->httpheaders( $rec->{name} );
95 print Encode::encode_utf8( $input->header(@hdr) );
96 while (<$fh>) {
97 print $_;
99 $fh->close;