Bug 20467: Remove useless use statements
[koha.git] / course_reserves / batch_add_items.pl
1 #!/usr/bin/perl
2
3 #
4 # Copyright 2018 Bywater Solutions
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22
23 use CGI qw( -utf8 );
24 use List::MoreUtils qw( uniq );
25
26 use C4::Auth;
27 use C4::Output;
28 use C4::CourseReserves qw(ModCourseItem ModCourseReserve GetCourse);
29
30 use Koha::Items;
31
32 my $cgi = new CGI;
33
34 my $action    = $cgi->param('action')    || q{};
35 my $course_id = $cgi->param('course_id') || q{};
36 my $barcodes  = $cgi->param('barcodes')  || q{};
37
38 my $itype         = $cgi->param('itype');
39 my $ccode         = $cgi->param('ccode');
40 my $holdingbranch = $cgi->param('holdingbranch');
41 my $location      = $cgi->param('location');
42 my $staff_note    = $cgi->param('staff_note');
43 my $public_note   = $cgi->param('public_note');
44
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
46     {
47         template_name   => "course_reserves/batch_add_items.tt",
48         query           => $cgi,
49         type            => "intranet",
50         authnotrequired => 0,
51         flagsrequired   => { coursereserves => 'add_reserves' },
52     }
53 );
54
55 $template->param( course => GetCourse($course_id) );
56
57 if ( !$action ) {
58     $template->param( action => 'display_form' );
59 }
60 elsif ( $action eq 'add' ) {
61     my @barcodes = uniq( split( /\s\n/, $barcodes ) );
62
63     my @items;
64     my @invalid_barcodes;
65     for my $b (@barcodes) {
66         my $item = Koha::Items->find( { barcode => $b } );
67
68         if ($item) {
69             push( @items, $item );
70         }
71         else {
72             push( @invalid_barcodes, $b );
73         }
74     }
75
76     foreach my $item (@items) {
77         my $ci_id = ModCourseItem(
78             itemnumber    => $item->id,
79             itype         => $itype,
80             ccode         => $ccode,
81             holdingbranch => $holdingbranch,
82             location      => $location,
83         );
84
85         my $cr_id = ModCourseReserve(
86             course_id   => $course_id,
87             ci_id       => $ci_id,
88             staff_note  => $staff_note,
89             public_note => $public_note,
90         );
91     }
92
93     $template->param(
94         action           => 'display_results',
95         items_added      => \@items,
96         invalid_barcodes => \@invalid_barcodes,
97         course_id        => $course_id,
98     );
99 }
100
101 output_html_with_http_headers $cgi, $cookie, $template->output;