Bug 33568: Fix popup behaviour for SpineLabelShowPrintOnBibDetails
[koha.git] / svc / problem_reports
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2020 Aleisha Amohia <aleisha@catalyst.net.nz>
6 #
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.
11 #
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.
16 #
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>.
19
20 use Modern::Perl;
21
22 use JSON qw( to_json );
23 use CGI;
24 use C4::Auth qw( check_cookie_auth );
25 use C4::Output qw( is_ajax output_with_http_headers );
26 use Koha::ProblemReports;
27
28 =head1 NAME
29
30 svc/problem_reports - Web service for managing OPAC problem reports
31
32 =head1 DESCRIPTION
33
34 =cut
35
36 # AJAX requests
37 my $is_ajax = is_ajax();
38 my $query = CGI->new;
39 my ( $auth_status ) = check_cookie_auth( $query->cookie('CGISESSID'), { problem_reports => 1 } );
40 if ( $auth_status ne "ok" ) {
41     exit 0;
42 }
43 my $op = $query->param('op') || q{};
44 if ($is_ajax) {
45     my $report_id = $query->param('report_id');
46     my $report = Koha::ProblemReports->find($report_id);
47     if ( $op eq 'cud-viewed' ) {
48         $report->set({ status => 'Viewed' })->store;
49     } elsif ( $op eq 'cud-closed' ) {
50         $report->set({ status => 'Closed' })->store;
51     } elsif ( $op eq 'cud-new' ) {
52         $report->set({ status => 'New' })->store;
53     }
54     my $json = to_json ( { status => $report->status } );
55     output_with_http_headers $query, undef, $json, 'js';
56     exit;
57 }