Bug 18553 - Incorrect Loading... tag on circulation.tt when no clubs defined
[koha.git] / course_reserves / add_items.pl
blob89cbb47eb7b535ff6e79a6fbc7cb838ab317eccf
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::ItemTypes;
35 my $cgi = new CGI;
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') && $action eq 'lookup') ? $cgi->param('itemnumber') : '';
43 my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } );
44 my $title = ($item) ? $item->biblio->title : undef;
46 my $step = ( $action eq 'lookup' && $item ) ? '2' : '1';
48 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
49 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
50 { template_name => "course_reserves/$tmpl",
51 query => $cgi,
52 type => "intranet",
53 authnotrequired => 0,
54 flagsrequired => { coursereserves => 'add_reserves' },
57 my $inumber = $itemnumber ? "(blank) (itemnumber:$itemnumber)" : "";
58 $template->param( ERROR_BARCODE_NOT_FOUND => $barcode . $inumber )
59 unless ( $barcode && !$itemnumber && $item && $action eq 'lookup' );
61 $template->param( course => GetCourse($course_id) );
63 if ( $action eq 'lookup' ) {
64 my $course_item = GetCourseItem( itemnumber => $item->{'itemnumber'} );
65 my $course_reserve =
66 ($course_item)
67 ? GetCourseReserve(
68 course_id => $course_id,
69 ci_id => $course_item->{'ci_id'}
71 : undef;
73 my $itemtypes = Koha::ItemTypes->search;
74 $template->param(
75 item => $item,
76 title => $title,
77 course_item => $course_item,
78 course_reserve => $course_reserve,
80 ccodes => GetAuthorisedValues('CCODE'),
81 locations => GetAuthorisedValues('LOC'),
82 itypes => $itemtypes, # FIXME We certainly want to display the translated_description in the template
83 return => $return,
86 } elsif ( $action eq 'add' ) {
87 my $ci_id = ModCourseItem(
88 itemnumber => scalar $cgi->param('itemnumber'),
89 itype => scalar $cgi->param('itype'),
90 ccode => scalar $cgi->param('ccode'),
91 holdingbranch => scalar $cgi->param('holdingbranch'),
92 location => scalar $cgi->param('location'),
95 my $cr_id = ModCourseReserve(
96 course_id => $course_id,
97 ci_id => $ci_id,
98 staff_note => scalar $cgi->param('staff_note'),
99 public_note => scalar $cgi->param('public_note'),
102 if ( $return ) {
103 print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
104 exit;
108 output_html_with_http_headers $cgi, $cookie, $template->output;