Bug 19996: (RM follow-up 2) Remove commented use warnings;
[koha.git] / circ / request-article.pl
1 #!/usr/bin/perl
2
3 # Copyright 2015 ByWater Solutions
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use C4::Output;
23 use C4::Auth;
24 use C4::Utils::DataTables::Members;
25 use Koha::Biblios;
26 use Koha::Patrons;
27 use Koha::ArticleRequests;
28
29 my $cgi = new CGI;
30
31 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
32     {
33         template_name   => "circ/request-article.tt",
34         query           => $cgi,
35         type            => "intranet",
36         authnotrequired => 0,
37         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
38     }
39 );
40
41 my $action            = $cgi->param('action') || q{};
42 my $biblionumber      = $cgi->param('biblionumber');
43 my $patron_cardnumber = $cgi->param('patron_cardnumber');
44 my $patron_id         = $cgi->param('patron_id');
45
46 my $biblio = Koha::Biblios->find($biblionumber);
47 my $patron =
48     $patron_id         ? Koha::Patrons->find($patron_id)
49   : $patron_cardnumber ? Koha::Patrons->find( { cardnumber => $patron_cardnumber } )
50   : undef;
51
52 if ( $action eq 'create' ) {
53     my $borrowernumber = $cgi->param('borrowernumber');
54     my $branchcode     = $cgi->param('branchcode');
55
56     my $itemnumber   = $cgi->param('itemnumber')   || undef;
57     my $title        = $cgi->param('title')        || undef;
58     my $author       = $cgi->param('author')       || undef;
59     my $volume       = $cgi->param('volume')       || undef;
60     my $issue        = $cgi->param('issue')        || undef;
61     my $date         = $cgi->param('date')         || undef;
62     my $pages        = $cgi->param('pages')        || undef;
63     my $chapters     = $cgi->param('chapters')     || undef;
64     my $patron_notes = $cgi->param('patron_notes') || undef;
65
66     my $ar = Koha::ArticleRequest->new(
67         {
68             borrowernumber => $borrowernumber,
69             biblionumber   => $biblionumber,
70             branchcode     => $branchcode,
71             itemnumber     => $itemnumber,
72             title          => $title,
73             author         => $author,
74             volume         => $volume,
75             issue          => $issue,
76             date           => $date,
77             pages          => $pages,
78             chapters       => $chapters,
79             patron_notes   => $patron_notes,
80         }
81     )->store();
82
83 }
84
85 if ( !$patron && $patron_cardnumber ) {
86     my $results = C4::Utils::DataTables::Members::search(
87         {
88             searchmember => $patron_cardnumber,
89             dt_params    => { iDisplayLength => -1 },
90         }
91     );
92
93     my $patrons = $results->{patrons};
94
95     if ( scalar @$patrons == 1 ) {
96         $patron = Koha::Patrons->find( $patrons->[0]->{borrowernumber} );
97     }
98     elsif (@$patrons) {
99         $template->param( patrons => $patrons );
100     }
101     else {
102         $template->param( no_patrons_found => $patron_cardnumber );
103     }
104 }
105
106 $template->param(
107     biblio => $biblio,
108     patron => $patron,
109 );
110
111 output_html_with_http_headers $cgi, $cookie, $template->output;