Bug 31281: Use correct reply-to email when sending overdue mails
[koha.git] / course_reserves / batch_rm_items.pl
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 qw( get_template_and_user );
26 use C4::Circulation qw( barcodedecode );
27 use C4::Output qw( output_html_with_http_headers );
28 use C4::CourseReserves qw( GetCourse GetCourseItem GetItemCourseReservesInfo DelCourse DelCourseReserve );
29
30 use Koha::Items;
31
32 my $cgi = CGI->new;
33
34 my $action    = $cgi->param('action')    || q{};
35 my $barcodes  = $cgi->param('barcodes')  || q{};
36
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38     {
39         template_name   => "course_reserves/batch_rm_items.tt",
40         query           => $cgi,
41         type            => "intranet",
42         flagsrequired   => { coursereserves => 'delete_reserves' },
43     }
44 );
45
46 if ( !$action ) {
47     $template->param( action => 'display_form' );
48 }
49
50 elsif ( $action eq 'batch_rm' ) {
51     my @barcodes = uniq( split (/\s\n/, $barcodes ) );
52     my @invalid_barcodes;
53     my @item_and_count;
54
55     foreach my $bar (@barcodes) {
56         $bar = barcodedecode($bar) if $bar;
57         my $item = Koha::Items->find( { barcode => $bar } );
58         if($item) {
59             my $courseitem = GetCourseItem(itemnumber => $item->id);
60             if($courseitem) {
61
62                 my $res_info = GetItemCourseReservesInfo(itemnumber => $item->id);
63
64                 my $no_of_res = @$res_info;
65
66                 my $delitemcount = {'delitem' => $item, 'delcount' => $no_of_res};
67                 push ( @item_and_count, $delitemcount );
68
69                 foreach my $cr (@$res_info) {
70                     if($cr->{cr_id}) {
71                         DelCourseReserve('cr_id' => $cr->{cr_id});
72                     }
73                 }
74             }
75             else {
76                 push( @invalid_barcodes, $bar);
77             }
78         }
79         else {
80             push( @invalid_barcodes, $bar );
81         }
82
83     }
84
85     $template->param(
86         action => 'display_results',
87         invalid_barcodes => \@invalid_barcodes,
88         item_and_count => \@item_and_count,
89     );
90 }
91
92 output_html_with_http_headers $cgi, $cookie, $template->output;