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>.
31 use C4
::CourseReserves
qw(GetCourse GetCourseItem GetCourseReserve 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') && $action eq 'lookup') ?
$cgi->param('itemnumber') : '';
43 my $is_edit = $cgi->param('is_edit') || '';
45 my $item = Koha
::Items
->find( { ( $itemnumber ?
( itemnumber
=> $itemnumber ) : ( barcode
=> $barcode ) ) } );
46 my $title = ($item) ?
$item->biblio->title : undef;
48 my $step = ( $action eq 'lookup' && $item ) ?
'2' : '1';
50 my $tmpl = ($course_id) ?
"add_items-step$step.tt" : "invalid-course.tt";
51 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
(
52 { template_name
=> "course_reserves/$tmpl",
56 flagsrequired
=> { coursereserves
=> 'add_reserves' },
60 if ( !$item && $action eq 'lookup' ){
61 $template->param( ERROR_ITEM_NOT_FOUND
=> 1 );
62 $template->param( UNKNOWN_BARCODE
=> $barcode ) if $barcode;
65 $template->param( course
=> GetCourse
($course_id) );
67 if ( $action eq 'lookup' and $item ) {
68 my $course_item = GetCourseItem
( itemnumber
=> $item->itemnumber );
72 course_id
=> $course_id,
73 ci_id
=> $course_item->{'ci_id'}
77 my $itemtypes = Koha
::ItemTypes
->search;
80 biblio
=> $item->biblio,
81 course_item
=> $course_item,
82 course_reserve
=> $course_reserve,
85 ccodes
=> GetAuthorisedValues
('CCODE'),
86 locations
=> GetAuthorisedValues
('LOC'),
87 itypes
=> $itemtypes, # FIXME We certainly want to display the translated_description in the template
91 } elsif ( $action eq 'add' ) {
92 my $ci_id = ModCourseItem
(
93 itemnumber
=> scalar $cgi->param('itemnumber'),
94 itype
=> scalar $cgi->param('itype'),
95 ccode
=> scalar $cgi->param('ccode'),
96 holdingbranch
=> scalar $cgi->param('holdingbranch'),
97 location
=> scalar $cgi->param('location'),
100 my $cr_id = ModCourseReserve
(
101 course_id
=> $course_id,
103 staff_note
=> scalar $cgi->param('staff_note'),
104 public_note
=> scalar $cgi->param('public_note'),
108 print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
113 output_html_with_http_headers
$cgi, $cookie, $template->output;