Bug 20467: Remove useless use statements
[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
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.
12 #
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.
17 #
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>.
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 Koha::Items;
30
31 use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve);
32
33 use Koha::Items;
34 use Koha::ItemTypes;
35
36 my $cgi = new CGI;
37
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
44 my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } );
45 my $title = ($item) ? $item->biblio->title : undef;
46
47 my $step = ( $action eq 'lookup' && $item ) ? '2' : '1';
48
49 my $tmpl = ($course_id) ? "add_items-step$step.tt" : "invalid-course.tt";
50 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
51     {   template_name   => "course_reserves/$tmpl",
52         query           => $cgi,
53         type            => "intranet",
54         authnotrequired => 0,
55         flagsrequired   => { coursereserves => 'add_reserves' },
56     }
57 );
58
59 if ( !$item && $action eq 'lookup' ){
60     $template->param( ERROR_ITEM_NOT_FOUND => 1 );
61     $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode;
62 }
63
64 $template->param( course => GetCourse($course_id) );
65
66 if ( $action eq 'lookup' and $item ) {
67     my $course_item = GetCourseItem( itemnumber => $item->itemnumber );
68     my $course_reserve =
69       ($course_item)
70       ? GetCourseReserve(
71         course_id => $course_id,
72         ci_id     => $course_item->{'ci_id'}
73       )
74       : undef;
75
76     my $itemtypes = Koha::ItemTypes->search;
77     $template->param(
78         item           => $item,
79         biblio         => $item->biblio,
80         course_item    => $course_item,
81         course_reserve => $course_reserve,
82
83         ccodes    => GetAuthorisedValues('CCODE'),
84         locations => GetAuthorisedValues('LOC'),
85         itypes    => $itemtypes, # FIXME We certainly want to display the translated_description in the template
86         return    => $return,
87     );
88
89 } elsif ( $action eq 'add' ) {
90     my $ci_id = ModCourseItem(
91         itemnumber    => scalar $cgi->param('itemnumber'),
92         itype         => scalar $cgi->param('itype'),
93         ccode         => scalar $cgi->param('ccode'),
94         holdingbranch => scalar $cgi->param('holdingbranch'),
95         location      => scalar $cgi->param('location'),
96     );
97
98     my $cr_id = ModCourseReserve(
99         course_id   => $course_id,
100         ci_id       => $ci_id,
101         staff_note  => scalar $cgi->param('staff_note'),
102         public_note => scalar $cgi->param('public_note'),
103     );
104
105     if ( $return ) {
106         print $cgi->redirect("/cgi-bin/koha/course_reserves/course-details.pl?course_id=$return");
107         exit;
108     }
109 }
110
111 output_html_with_http_headers $cgi, $cookie, $template->output;