Bug 11944: use CGI( -utf8 ) everywhere
[koha.git] / course_reserves / add_items.pl
1 #!/usr/bin/perl
2
3 #
4 # Copyright 2012 Bywater Solutions
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 use Modern::Perl;
22
23 use CGI qw ( -utf8 );
24
25 use C4::Auth;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Biblio;
29 use C4::Branch;
30
31 use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve);
32
33 my $cgi = new CGI;
34
35 my $action    = $cgi->param('action')    || '';
36 my $course_id = $cgi->param('course_id') || '';
37 my $barcode   = $cgi->param('barcode')   || '';
38
39 my $item = GetBiblioFromItemNumber( undef, $barcode );
40
41 my $step = ( $action eq 'lookup' && $item ) ? '2' : '1';
42
43 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
45     {   template_name   => "course_reserves/$tmpl",
46         query           => $cgi,
47         type            => "intranet",
48         authnotrequired => 0,
49         flagsrequired   => { coursereserves => 'add_reserves' },
50     }
51 );
52 $template->param( ERROR_BARCODE_NOT_FOUND => $barcode )
53   unless ( $barcode && $item && $action eq 'lookup' );
54
55 $template->param( course => GetCourse($course_id) );
56
57 if ( $action eq 'lookup' ) {
58     my $course_item = GetCourseItem( itemnumber => $item->{'itemnumber'} );
59     my $course_reserve =
60       ($course_item)
61       ? GetCourseReserve(
62         course_id => $course_id,
63         ci_id     => $course_item->{'ci_id'}
64       )
65       : undef;
66
67     $template->param(
68         item           => $item,
69         course_item    => $course_item,
70         course_reserve => $course_reserve,
71
72         ccodes    => GetAuthorisedValues('CCODE'),
73         locations => GetAuthorisedValues('LOC'),
74         itypes    => GetItemTypes( style => 'array' ),
75         branches  => GetBranchesLoop(),
76     );
77
78 } elsif ( $action eq 'add' ) {
79     my $ci_id = ModCourseItem(
80         itemnumber    => $cgi->param('itemnumber'),
81         itype         => $cgi->param('itype'),
82         ccode         => $cgi->param('ccode'),
83         holdingbranch => $cgi->param('holdingbranch'),
84         location      => $cgi->param('location'),
85     );
86
87     my $cr_id = ModCourseReserve(
88         course_id   => $course_id,
89         ci_id       => $ci_id,
90         staff_note  => $cgi->param('staff_note'),
91         public_note => $cgi->param('public_note'),
92     );
93 }
94
95 output_html_with_http_headers $cgi, $cookie, $template->output;