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::Circulation qw( barcodedecode );
27 use C4::Output qw( output_html_with_http_headers );
28 use C4::Koha qw( GetAuthorisedValues );
31 use C4::CourseReserves qw( GetCourse GetCourseReserve ModCourse ModCourseItem ModCourseReserve );
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') || '';
44 my $biblionumber = $cgi->param('biblionumber') || '';
46 $barcode = barcodedecode($barcode) if $barcode;
47 $biblionumber =~ s/^\s*|\s*$//g; #remove leading/trailing whitespace
49 my ( $item, $biblio );
51 if ( $barcode || $itemnumber ) {
52 # adding an item to course items
53 $item = $itemnumber ? Koha::Items->find( $itemnumber ) : Koha::Items->find({ barcode => $barcode });
55 $itemnumber = $item->id;
56 $biblio = $item->biblio;
59 # adding a biblio to course items
60 $biblio = Koha::Biblios->find( $biblionumber );
63 my $step = ( $action eq 'lookup' && ( $item or $biblio ) ) ? '2' : '1';
65 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
66 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
67 { template_name => "course_reserves/$tmpl",
70 flagsrequired => { coursereserves => 'add_reserves' },
74 if ( !$item && !$biblio && $action eq 'lookup' ){
75 $template->param( ERROR_ITEM_NOT_FOUND => 1 );
76 $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode;
77 $template->param( UNKNOWN_BIBLIONUMBER => $biblionumber ) if $biblionumber;
80 $template->param( course => GetCourse($course_id) );
82 if ( $action eq 'lookup' and $item ) {
83 my $course_item = Koha::Course::Items->find({ itemnumber => $item->id });
87 course_id => $course_id,
88 ci_id => $course_item->ci_id,
92 my $itemtypes = Koha::ItemTypes->search;
96 course_item => $course_item,
97 course_reserve => $course_reserve,
100 ccodes => GetAuthorisedValues('CCODE'),
101 locations => GetAuthorisedValues('LOC'),
102 itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template
106 } elsif ( $action eq 'lookup' and $biblio ) {
107 my $course_item = Koha::Course::Items->find({ biblionumber => $biblio->biblionumber });
111 course_id => $course_id,
112 ci_id => $course_item->ci_id,
116 my $itemtypes = Koha::ItemTypes->search;
119 course_item => $course_item,
120 course_reserve => $course_reserve,
126 } elsif ( $action eq 'add' ) {
127 my $itype = scalar $cgi->param('itype');
128 my $ccode = scalar $cgi->param('ccode');
129 my $homebranch = $cgi->param('homebranch');
130 my $holdingbranch = scalar $cgi->param('holdingbranch');
131 my $location = scalar $cgi->param('location');
133 my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0;
134 my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0;
135 my $homebranch_enabled = $cgi->param('homebranch_enabled') ? 1 : 0;
136 my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0;
137 my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0;
139 my $ci_id = ModCourseItem(
140 itemnumber => $itemnumber,
141 biblionumber => $biblionumber,
144 homebranch => $homebranch,
145 holdingbranch => $holdingbranch,
146 location => $location,
147 itype_enabled => $itype_enabled,
148 ccode_enabled => $ccode_enabled,
149 homebranch_enabled => $homebranch_enabled,
150 holdingbranch_enabled => $holdingbranch_enabled,
151 location_enabled => $location_enabled,
154 my $cr_id = ModCourseReserve(
155 course_id => $course_id,
157 staff_note => scalar $cgi->param('staff_note'),
158 public_note => scalar $cgi->param('public_note'),
162 print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
167 output_html_with_http_headers $cgi, $cookie, $template->output;