3 # This file is part of Koha.
5 # Copyright (C) 2020 Fenway Library Organization
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>.
23 use List::MoreUtils qw( uniq );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Output qw( output_html_with_http_headers );
27 use C4::CourseReserves qw( GetCourse GetCourseItem GetItemCourseReservesInfo DelCourse DelCourseReserve );
33 my $action = $cgi->param('action') || q{};
34 my $barcodes = $cgi->param('barcodes') || q{};
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "course_reserves/batch_rm_items.tt",
41 flagsrequired => { coursereserves => 'delete_reserves' },
46 $template->param( action => 'display_form' );
49 elsif ( $action eq 'batch_rm' ) {
50 my @barcodes = uniq( split (/\s\n/, $barcodes ) );
54 foreach my $bar (@barcodes) {
55 my $item = Koha::Items->find( { barcode => $bar } );
57 my $courseitem = GetCourseItem(itemnumber => $item->id);
60 my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
62 my $no_of_res = @$res_info;
64 my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res};
65 push ( @item_and_count, $delitemcount );
67 foreach my $cr (@$res_info) {
69 DelCourseReserve('cr_id' => $cr->{cr_id});
74 push( @invalid_barcodes, $bar);
78 push( @invalid_barcodes, $bar );
84 action => 'display_results',
85 invalid_barcodes => \@invalid_barcodes,
86 item_and_count => \@item_and_count,
90 output_html_with_http_headers $cgi, $cookie, $template->output;