Bug 26795: Remove the use of jquery.checkboxes plugin from ILL pages
[koha.git] / course_reserves / add_items.pl
blob7c16a143f59bffbd6661e109f7342dba877d9266
1 #!/usr/bin/perl
4 # Copyright 2012 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 );
25 use C4::Auth;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Biblio;
29 use Koha::Items;
31 use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve);
33 use Koha::Items;
34 use Koha::ItemTypes;
36 my $cgi = CGI->new;
38 my $action = $cgi->param('action') || '';
39 my $course_id = $cgi->param('course_id') || '';
40 my $barcode = $cgi->param('barcode') || '';
41 my $return = $cgi->param('return') || '';
42 my $itemnumber = $cgi->param('itemnumber') || '';
43 my $is_edit = $cgi->param('is_edit') || '';
45 $barcode =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace
47 my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } );
48 $itemnumber = $item->id if $item;
50 my $title = ($item) ? $item->biblio->title : undef;
52 my $step = ( $action eq 'lookup' && $item ) ? '2' : '1';
54 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
55 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
56 { template_name => "course_reserves/$tmpl",
57 query => $cgi,
58 type => "intranet",
59 flagsrequired => { coursereserves => 'add_reserves' },
63 if ( !$item && $action eq 'lookup' ){
64 $template->param( ERROR_ITEM_NOT_FOUND => 1 );
65 $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode;
68 $template->param( course => GetCourse($course_id) );
70 if ( $action eq 'lookup' and $item ) {
71 my $course_item = Koha::Course::Items->find({ itemnumber => $item->id });
72 my $course_reserve =
73 ($course_item)
74 ? GetCourseReserve(
75 course_id => $course_id,
76 ci_id => $course_item->ci_id,
78 : undef;
80 my $itemtypes = Koha::ItemTypes->search;
81 $template->param(
82 item => $item,
83 biblio => $item->biblio,
84 course_item => $course_item,
85 course_reserve => $course_reserve,
86 is_edit => $is_edit,
88 ccodes => GetAuthorisedValues('CCODE'),
89 locations => GetAuthorisedValues('LOC'),
90 itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template
91 return => $return,
94 } elsif ( $action eq 'add' ) {
95 my $itype = scalar $cgi->param('itype');
96 my $ccode = scalar $cgi->param('ccode');
97 my $homebranch = $cgi->param('homebranch');
98 my $holdingbranch = scalar $cgi->param('holdingbranch');
99 my $location = scalar $cgi->param('location');
101 my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0;
102 my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0;
103 my $homebranch_enabled = $cgi->param('homebranch_enabled') ? 1 : 0;
104 my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0;
105 my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0;
107 my $ci_id = ModCourseItem(
108 itemnumber => $itemnumber,
109 itype => $itype,
110 ccode => $ccode,
111 homebranch => $homebranch,
112 holdingbranch => $holdingbranch,
113 location => $location,
114 itype_enabled => $itype_enabled,
115 ccode_enabled => $ccode_enabled,
116 homebranch_enabled => $homebranch_enabled,
117 holdingbranch_enabled => $holdingbranch_enabled,
118 location_enabled => $location_enabled,
121 my $cr_id = ModCourseReserve(
122 course_id => $course_id,
123 ci_id => $ci_id,
124 staff_note => scalar $cgi->param('staff_note'),
125 public_note => scalar $cgi->param('public_note'),
128 if ( $return ) {
129 print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
130 exit;
134 output_html_with_http_headers $cgi, $cookie, $template->output;