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>.
25 use C4::Auth qw( get_template_and_user );
26 use C4::Output qw( output_html_with_http_headers );
27 use C4::Koha qw( GetAuthorisedValues );
30 use C4::CourseReserves qw( GetCourse GetCourseReserve ModCourse ModCourseItem ModCourseReserve );
37 my $action = $cgi->param('action') || '';
38 my $course_id = $cgi->param('course_id') || '';
39 my $barcode = $cgi->param('barcode') || '';
40 my $return = $cgi->param('return') || '';
41 my $itemnumber = $cgi->param('itemnumber') || '';
42 my $is_edit = $cgi->param('is_edit') || '';
43 my $biblionumber = $cgi->param('biblionumber') || '';
45 $barcode =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace
46 $biblionumber =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace
48 my ( $item, $biblio );
50 if ( $barcode || $itemnumber ) {
51 # adding an item to course items
52 $item = $itemnumber ? Koha::Items->find( $itemnumber ) : Koha::Items->find({ barcode => $barcode });
54 $itemnumber = $item->id;
55 $biblio = $item->biblio;
58 # adding a biblio to course items
59 $biblio = Koha::Biblios->find( $biblionumber );
62 my $step = ( $action eq 'lookup' && ( $item or $biblio ) ) ? '2' : '1';
64 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
65 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
66 { template_name => "course_reserves/$tmpl",
69 flagsrequired => { coursereserves => 'add_reserves' },
73 if ( !$item && !$biblio && $action eq 'lookup' ){
74 $template->param( ERROR_ITEM_NOT_FOUND => 1 );
75 $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode;
76 $template->param( UNKNOWN_BIBLIONUMBER => $biblionumber ) if $biblionumber;
79 $template->param( course => GetCourse($course_id) );
81 if ( $action eq 'lookup' and $item ) {
82 my $course_item = Koha::Course::Items->find({ itemnumber => $item->id });
86 course_id => $course_id,
87 ci_id => $course_item->ci_id,
91 my $itemtypes = Koha::ItemTypes->search;
95 course_item => $course_item,
96 course_reserve => $course_reserve,
99 ccodes => GetAuthorisedValues('CCODE'),
100 locations => GetAuthorisedValues('LOC'),
101 itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template
105 } elsif ( $action eq 'lookup' and $biblio ) {
106 my $course_item = Koha::Course::Items->find({ biblionumber => $biblio->biblionumber });
110 course_id => $course_id,
111 ci_id => $course_item->ci_id,
115 my $itemtypes = Koha::ItemTypes->search;
118 course_item => $course_item,
119 course_reserve => $course_reserve,
125 } elsif ( $action eq 'add' ) {
126 my $itype = scalar $cgi->param('itype');
127 my $ccode = scalar $cgi->param('ccode');
128 my $homebranch = $cgi->param('homebranch');
129 my $holdingbranch = scalar $cgi->param('holdingbranch');
130 my $location = scalar $cgi->param('location');
132 my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0;
133 my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0;
134 my $homebranch_enabled = $cgi->param('homebranch_enabled') ? 1 : 0;
135 my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0;
136 my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0;
138 my $ci_id = ModCourseItem(
139 itemnumber => $itemnumber,
140 biblionumber => $biblionumber,
143 homebranch => $homebranch,
144 holdingbranch => $holdingbranch,
145 location => $location,
146 itype_enabled => $itype_enabled,
147 ccode_enabled => $ccode_enabled,
148 homebranch_enabled => $homebranch_enabled,
149 holdingbranch_enabled => $holdingbranch_enabled,
150 location_enabled => $location_enabled,
153 my $cr_id = ModCourseReserve(
154 course_id => $course_id,
156 staff_note => scalar $cgi->param('staff_note'),
157 public_note => scalar $cgi->param('public_note'),
161 print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
166 output_html_with_http_headers $cgi, $cookie, $template->output;