Bug 25898: Prohibit indirect object notation
[koha.git] / svc / cover_images
blob82e68f2ee5f8a54826509ff659fb8554ec04ce24
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2013 Universidad Nacional de Cordoba
6 # Tomas Cohen Arazi
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.
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.
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>.
21 use Modern::Perl;
23 use CGI qw ( -utf8 );
24 use C4::Auth qw/check_cookie_auth/;
25 use Koha::CoverImages;
26 use JSON qw/to_json/;
28 my $input = CGI->new;
30 my ( $auth_status, $sessionID ) =
31 check_cookie_auth(
32 $input->cookie('CGISESSID'),
33 { tools => 'upload_local_cover_images' } );
35 if ( $auth_status ne "ok" ) {
36 exit 0;
39 my $action = $input->param('action');
40 my @imagenumbers = $input->param('imagenumber');
42 # Array to store the reponse JSON
43 my $response = [];
45 if ( $action eq "delete" ) {
47 foreach my $imagenumber ( @imagenumbers ) {
48 eval {
49 Koha::CoverImages->find($imagenumber)->delete;
51 if ( $@ ) {
52 push @$response, {
53 imagenumber => $imagenumber,
54 deleted => 0,
55 error => "MSG_INVALID_IMAGENUMBER"
57 } else {
58 push @$response, {
59 imagenumber => $imagenumber,
60 deleted => 1
64 } else {
65 # invalid action
66 exit 0;
69 binmode STDOUT, ":encoding(UTF-8)";
70 print $input->header(
71 -type => 'application/json',
72 -charset => 'UTF-8'
75 print to_json( $response );