Bug 7947: (follow-up) fix 490 subfield visibility (DE)
[koha.git] / course_reserves / batch_add_items.pl
blob2a924b6f35e543e38e031c2930e28c0ac73ddc9c
1 #!/usr/bin/perl
4 # Copyright 2018 Bywater Solutions
6 # This file is part of Koha.
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.
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.
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>.
21 use Modern::Perl;
23 use CGI qw( -utf8 );
24 use List::MoreUtils qw( uniq );
26 use C4::Auth;
27 use C4::Output;
28 use C4::CourseReserves qw(ModCourseItem ModCourseReserve GetCourse);
30 use Koha::Items;
32 my $cgi = new CGI;
34 my $action = $cgi->param('action') || q{};
35 my $course_id = $cgi->param('course_id') || q{};
36 my $barcodes = $cgi->param('barcodes') || q{};
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');
45 my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0;
46 my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0;
47 my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0;
48 my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0;
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
52 template_name => "course_reserves/batch_add_items.tt",
53 query => $cgi,
54 type => "intranet",
55 authnotrequired => 0,
56 flagsrequired => { coursereserves => 'add_reserves' },
60 my $course = GetCourse($course_id);
62 if ( $course_id && $course ) {
63 $template->param( course => $course );
65 if ( !$action ) {
66 $template->param( action => 'display_form' );
68 elsif ( $action eq 'add' ) {
69 my @barcodes = uniq( split( /\s\n/, $barcodes ) );
71 my @items;
72 my @invalid_barcodes;
73 for my $b (@barcodes) {
74 my $item = Koha::Items->find( { barcode => $b } );
76 if ($item) {
77 push( @items, $item );
79 else {
80 push( @invalid_barcodes, $b );
84 foreach my $item (@items) {
85 my $ci_id = ModCourseItem(
86 itemnumber => $item->id,
87 itype => $itype,
88 ccode => $ccode,
89 holdingbranch => $holdingbranch,
90 location => $location,
91 itype_enabled => $itype_enabled,
92 ccode_enabled => $ccode_enabled,
93 holdingbranch_enabled => $holdingbranch_enabled,
94 location_enabled => $location_enabled,
97 my $cr_id = ModCourseReserve(
98 course_id => $course_id,
99 ci_id => $ci_id,
100 staff_note => $staff_note,
101 public_note => $public_note,
105 $template->param(
106 action => 'display_results',
107 items_added => \@items,
108 invalid_barcodes => \@invalid_barcodes,
109 course_id => $course_id,
112 } else {
113 $template->param( action => 'invalid_course' );
116 output_html_with_http_headers $cgi, $cookie, $template->output;