Bug 20996: Fix unit tests
[koha.git] / circ / request-article.pl
blob7c0877bff8d0037b867dec9160750ed03a48047c
1 #!/usr/bin/perl
3 # Copyright 2015 ByWater Solutions
5 # This file is part of Koha.
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.
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.
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>.
20 use Modern::Perl;
22 use C4::Output;
23 use C4::Auth;
24 use C4::Utils::DataTables::Members;
25 use C4::Search;
26 use C4::Serials;
27 use Koha::Biblios;
28 use Koha::Patrons;
29 use Koha::ArticleRequests;
31 my $cgi = new CGI;
33 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
35 template_name => "circ/request-article.tt",
36 query => $cgi,
37 type => "intranet",
38 authnotrequired => 0,
39 flagsrequired => { circulate => 'circulate_remaining_permissions' },
43 my $action = $cgi->param('action') || q{};
44 my $biblionumber = $cgi->param('biblionumber');
45 my $patron_cardnumber = $cgi->param('patron_cardnumber');
46 my $patron_id = $cgi->param('patron_id');
48 my $biblio = Koha::Biblios->find($biblionumber);
49 output_and_exit( $cgi, $cookie, $template, 'unknown_biblio')
50 unless $biblio;
52 my $patron =
53 $patron_id ? Koha::Patrons->find($patron_id)
54 : $patron_cardnumber ? Koha::Patrons->find( { cardnumber => $patron_cardnumber } )
55 : undef;
57 if ( $action eq 'create' ) {
58 my $borrowernumber = $cgi->param('borrowernumber');
59 my $branchcode = $cgi->param('branchcode');
61 my $itemnumber = $cgi->param('itemnumber') || undef;
62 my $title = $cgi->param('title') || undef;
63 my $author = $cgi->param('author') || undef;
64 my $volume = $cgi->param('volume') || undef;
65 my $issue = $cgi->param('issue') || undef;
66 my $date = $cgi->param('date') || undef;
67 my $pages = $cgi->param('pages') || undef;
68 my $chapters = $cgi->param('chapters') || undef;
69 my $patron_notes = $cgi->param('patron_notes') || undef;
71 my $ar = Koha::ArticleRequest->new(
73 borrowernumber => $borrowernumber,
74 biblionumber => $biblionumber,
75 branchcode => $branchcode,
76 itemnumber => $itemnumber,
77 title => $title,
78 author => $author,
79 volume => $volume,
80 issue => $issue,
81 date => $date,
82 pages => $pages,
83 chapters => $chapters,
84 patron_notes => $patron_notes,
86 )->store();
90 if ( !$patron && $patron_cardnumber ) {
91 my $results = C4::Utils::DataTables::Members::search(
93 searchmember => $patron_cardnumber,
94 dt_params => { iDisplayLength => -1 },
98 my $patrons = $results->{patrons};
100 if ( scalar @$patrons == 1 ) {
101 $patron = Koha::Patrons->find( $patrons->[0]->{borrowernumber} );
103 elsif (@$patrons) {
104 $template->param( patrons => $patrons );
106 else {
107 $template->param( no_patrons_found => $patron_cardnumber );
111 $template->param(
112 biblio => $biblio,
113 patron => $patron,
114 subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
115 C4::Search::enabled_staff_search_views,
118 output_html_with_http_headers $cgi, $cookie, $template->output;