3 # Copyright 2013 BibLibre
5 # This file is part of Koha
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use C4::Auth qw( check_cookie_auth );
24 use JSON qw( to_json );
25 use Koha::List::Patron;
29 my ( $auth_status, $sessionID ) = check_cookie_auth(
30 $input->cookie('CGISESSID'),
31 { tools => 'manage_patron_lists' },
34 exit 0 if $auth_status ne "ok";
35 my $add_to_patron_list = $input->param('add_to_patron_list');
36 my $new_patron_list = $input->param('new_patron_list');
37 my @borrowernumbers = $input->param('borrowernumbers[]');
40 if ($add_to_patron_list) {
43 if ( $add_to_patron_list eq 'new' ) {
44 $patron_list = AddPatronList( { name => $new_patron_list } );
48 [ GetPatronLists( { patron_list_id => $add_to_patron_list } ) ]->[0];
51 my @patrons_added_to_list = AddPatronsToList( { list => $patron_list, borrowernumbers => \@borrowernumbers } );
53 $response->{patron_list} = { patron_list_id => $patron_list->patron_list_id, name => $patron_list->name };
54 $response->{patrons_added_to_list} = scalar( @patrons_added_to_list );
57 binmode STDOUT, ":encoding(UTF-8)";
59 -type => 'application/json',
63 print to_json( $response );