3 # This file is part of Koha.
5 # Copyright 2017 Aleisha Amohia <aleisha@catalyst.net.nz>
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.
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.
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>.
22 use JSON qw( encode_json );
26 use C4::Auth qw /check_cookie_auth/;
27 use C4::Output qw(:DEFAULT :ajax);
28 use C4::Patroncards::Batch;
29 use C4::Labels::Batch;
33 svc/creator_batches - Web service for managing AJAX functionality for patroncards and label batches
40 my $is_ajax = is_ajax();
42 my ( $auth_status, $sessionID ) = check_cookie_auth( $cgi->cookie('CGISESSID'), { catalogue => 1 } );
43 if ( $auth_status ne "ok" ) {
48 my $batch_id = $cgi->param('batch_id');
49 my $description = $cgi->param('newdescription');
51 my $dbh = C4::Context->dbh;
52 my $query = "UPDATE creator_batches SET description = ? WHERE batch_id = ?";
53 my $sth = $dbh->prepare($query);
54 $sth->execute($description, $batch_id);
57 my $creator = $cgi->param('creator');
58 if ( $creator eq 'patroncard' ) {
59 my $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);
60 if ( $batch->{description} eq $description ) {
63 } elsif ( $creator eq 'label' ) {
64 my $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);
65 if ( $batch->{description} eq $description ) {
70 my $json = encode_json ( { status => $status, newdesc => $description } );
71 output_with_http_headers $cgi, undef, $json, 'js';