Koha/svc/recall
Lucas Gass 17466e99fe
Bug 36418: Catch more cases where header response should be application/json
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
2024-04-02 17:59:04 +02:00

92 lines
2.6 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI;
use JSON qw(encode_json);
use C4::Context;
use C4::Auth qw(check_cookie_auth);
use C4::Output qw(output_with_http_headers);
use C4::Circulation qw(AddReturn);
use Koha::Recalls;
my $input = CGI->new;
my $json = encode_json({ success => 0 });
my ( $auth_status, $sessionID ) = check_cookie_auth( $input->cookie('CGISESSID'), { recall => 'manage_recalls' } );
if ( $auth_status ne "ok" ) {
print $input->header(-type => 'application/json', -status => '403 Forbidden');
exit 0;
}
my $recall_id = $input->param('recall_id');
my $recall = Koha::Recalls->find( $recall_id );
unless ( $recall ) {
my $json = encode_json({ success => 0 });
output_with_http_headers( $input, undef, $json, "json" );
exit;
}
my $op = $input->param('op');
if ( $op eq 'cud-cancel' ) {
# cancel recall
$recall->set_cancelled;
if ( $recall->cancelled ){
$json = encode_json({ success => 1 });
}
} elsif ( $op eq 'cud-expire' ) {
# expire recall
$recall->set_expired({ interface => 'INTRANET' });
if ( $recall->expired ){
$json = encode_json({ success => 1 });
}
} elsif ( $op eq 'cud-revert' ) {
# revert recall waiting status
$recall->revert_waiting;
if ( $recall->requested ){
$json = encode_json({ success => 1 });
}
} elsif ( $op eq 'cud-overdue' ) {
# mark recall as overdue
$recall->set_overdue({ interface => 'INTRANET' });
if ( $recall->overdue ){
$json = encode_json({ success => 1 });
}
} elsif ( $op eq 'cud-transit' ) {
# cancel recall and return item to home library
if ( $recall->in_transit ) {
C4::Items::ModItemTransfer(
$recall->item->itemnumber, $recall->item->holdingbranch,
$recall->item->homebranch, 'RecallCancellation'
);
}
$recall->set_cancelled;
if ( $recall->cancelled ){
$json = encode_json({ success => 1 });
}
}
output_with_http_headers( $input, undef, $json, "json" );