Bug 33568: Fix columns shift when pref are off
[koha.git] / svc / creator_batches
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Copyright 2017 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( encode_json );
23 use CGI;
24 use C4::Service;
25 use C4::Context;
26 use C4::Auth qw( check_cookie_auth );
27 use C4::Output qw( is_ajax output_with_http_headers );
28 use C4::Patroncards::Batch;
29 use C4::Labels::Batch;
30
31 =head1 NAME
32
33 svc/creator_batches - Web service for managing AJAX functionality for patroncards and label batches
34
35 =head1 DESCRIPTION
36
37 =cut
38
39 # AJAX requests
40 my $is_ajax = is_ajax();
41 my $cgi = CGI->new;
42 my ( $auth_status ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
43 if ( $auth_status ne "ok" ) {
44     exit 0;
45 }
46
47 my $op = $cgi->param('op') || q{};
48 if ($is_ajax && $op eq 'cud-set_permission') {
49     my $batch_id = $cgi->param('batch_id');
50     my $description = $cgi->param('newdescription');
51     my $dbh = C4::Context->dbh;
52     my $status = 'success';
53     eval {
54         my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
55         my $sth = $dbh->prepare($query);
56         $sth->execute($description, $batch_id);
57     };
58     if ($@) {
59         warn $@;
60         undef $status;
61     }
62
63     my $json = encode_json ( { status => $status, newdesc => $description } );
64     output_with_http_headers $cgi, undef, $json, 'js';
65     exit;
66 } else {
67     # FIXME be nicer
68     exit 0;
69 }