Bug 24412: DBIC schema changes
[koha.git] / course_reserves / batch_add_items.pl
blob829709930d631c78134494eb58970856f110b6ba
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 = CGI->new;
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 $homebranch = $cgi->param('homebranch');
41 my $holdingbranch = $cgi->param('holdingbranch');
42 my $location = $cgi->param('location');
43 my $staff_note = $cgi->param('staff_note');
44 my $public_note = $cgi->param('public_note');
46 my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0;
47 my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0;
48 my $homebranch_enabled = scalar $cgi->param('homebranch_enabled') ? 1 : 0;
49 my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0;
50 my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0;
52 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
54 template_name => "course_reserves/batch_add_items.tt",
55 query => $cgi,
56 type => "intranet",
57 flagsrequired => { coursereserves => 'add_reserves' },
61 my $course = GetCourse($course_id);
63 if ( $course_id && $course ) {
64 $template->param( course => $course );
66 if ( !$action ) {
67 $template->param( action => 'display_form' );
69 elsif ( $action eq 'add' ) {
70 my @barcodes = uniq( split( /\s\n/, $barcodes ) );
72 my @items;
73 my @invalid_barcodes;
74 for my $b (@barcodes) {
75 my $item = Koha::Items->find( { barcode => $b } );
77 if ($item) {
78 push( @items, $item );
80 else {
81 push( @invalid_barcodes, $b );
85 foreach my $item (@items) {
86 my $ci_id = ModCourseItem(
87 itemnumber => $item->id,
88 itype => $itype,
89 ccode => $ccode,
90 holdingbranch => $holdingbranch,
91 homebranch => $homebranch,
92 location => $location,
93 itype_enabled => $itype_enabled,
94 ccode_enabled => $ccode_enabled,
95 holdingbranch_enabled => $holdingbranch_enabled,
96 homebranch_enabled => $homebranch_enabled,
97 location_enabled => $location_enabled,
100 my $cr_id = ModCourseReserve(
101 course_id => $course_id,
102 ci_id => $ci_id,
103 staff_note => $staff_note,
104 public_note => $public_note,
108 $template->param(
109 action => 'display_results',
110 items_added => \@items,
111 invalid_barcodes => \@invalid_barcodes,
112 course_id => $course_id,
115 } else {
116 $template->param( action => 'invalid_course' );
119 output_html_with_http_headers $cgi, $cookie, $template->output;