Bug 36511: Some scripts missing a dependency following Bug 24879
[koha.git] / svc / cover_images
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2013 Universidad Nacional de Cordoba
6 #                Tomas Cohen Arazi
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use CGI qw ( -utf8 );
24 use C4::Auth qw/check_cookie_auth/;
25 use Koha::CoverImages;
26 use JSON qw/to_json/;
27
28 my $input = CGI->new;
29
30 my ( $auth_status ) =
31         check_cookie_auth(
32             $input->cookie('CGISESSID'),
33             { tools => 'upload_local_cover_images' } );
34
35 if ( $auth_status ne "ok" ) {
36     exit 0;
37 }
38
39 my $op           = $input->param('op') || q{};
40 my $imagenumber = $input->param('imagenumber');
41
42 my $response = q{};
43
44 if ( $op eq "cud-delete" ) {
45
46     eval {
47         Koha::CoverImages->find($imagenumber)->delete;
48     };
49     if ( $@ ) {
50         $response = {
51             imagenumber => $imagenumber,
52             deleted => 0,
53             error => "MSG_INVALID_IMAGENUMBER"
54         };
55     } else {
56         $response = {
57             imagenumber => $imagenumber,
58             deleted => 1
59         };
60     }
61 } else {
62     # FIXME be nicer!
63     # invalid op
64     exit 0;
65 }
66
67 binmode STDOUT, ":encoding(UTF-8)";
68 print $input->header(
69     -type => 'application/json',
70     -charset => 'UTF-8'
71 );
72
73 print to_json( $response );