|
Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Copyright (C) 2020 Fenway Library Organization |
| 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 CGI qw( -utf8 ); |
| 23 |
use List::MoreUtils qw( uniq ); |
| 24 |
|
| 25 |
use C4::Auth; |
| 26 |
use C4::Output; |
| 27 |
use C4::CourseReserves qw(GetItemCourseReservesInfo DelCourseReserve GetCourseItem); |
| 28 |
|
| 29 |
use Koha::Items; |
| 30 |
|
| 31 |
my $cgi = new CGI; |
| 32 |
|
| 33 |
my $action = $cgi->param('action') || q{}; |
| 34 |
my $barcodes = $cgi->param('barcodes') || q{}; |
| 35 |
|
| 36 |
my ( $template, $loggedinuser, $cookie ) = get_template_and_user( |
| 37 |
{ |
| 38 |
template_name => "course_reserves/batch_rm_items.tt", |
| 39 |
query => $cgi, |
| 40 |
type => "intranet", |
| 41 |
flagsrequired => { coursereserves => 'delete_reserves' }, |
| 42 |
} |
| 43 |
); |
| 44 |
|
| 45 |
if ( !$action ) { |
| 46 |
$template->param( action => 'display_form' ); |
| 47 |
} |
| 48 |
|
| 49 |
elsif ( $action eq 'batch_rm' ) { |
| 50 |
my @barcodes = uniq( split (/\s\n/, $barcodes ) ); |
| 51 |
my @invalid_barcodes; |
| 52 |
my @item_and_count; |
| 53 |
|
| 54 |
foreach my $bar (@barcodes) { |
| 55 |
my $item = Koha::Items->find( { barcode => $bar } ); |
| 56 |
if($item) { |
| 57 |
my $courseitem = GetCourseItem(itemnumber => $item->id); |
| 58 |
if($courseitem) { |
| 59 |
|
| 60 |
my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id); |
| 61 |
|
| 62 |
my $no_of_res = @$res_info; |
| 63 |
|
| 64 |
my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res}; |
| 65 |
push ( @item_and_count, $delitemcount ); |
| 66 |
|
| 67 |
foreach my $cr (@$res_info) { |
| 68 |
if($cr->{cr_id}) { |
| 69 |
DelCourseReserve('cr_id' => $cr->{cr_id}); |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
else { |
| 74 |
push( @invalid_barcodes, $bar); |
| 75 |
} |
| 76 |
} |
| 77 |
else { |
| 78 |
push( @invalid_barcodes, $bar ); |
| 79 |
} |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
$template->param( |
| 84 |
action => 'display_results', |
| 85 |
invalid_barcodes => \@invalid_barcodes, |
| 86 |
item_and_count => \@item_and_count, |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
output_html_with_http_headers $cgi, $cookie, $template->output; |