Bug 25716: (QA follow-up) Move additional options to etc/z3950/config.xml
[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 qw( output_and_exit output_html_with_http_headers );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Search qw( enabled_staff_search_views );
25 use C4::Serials qw( CountSubscriptionFromBiblionumber );
26 use Koha::Biblios;
27 use Koha::Logger;
28 use Koha::Patrons;
29 use Koha::ArticleRequests;
30
31 use Scalar::Util qw( blessed );
32 use Try::Tiny;
33
34 my $cgi = CGI->new;
35
36 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
37     {
38         template_name   => "circ/request-article.tt",
39         query           => $cgi,
40         type            => "intranet",
41         flagsrequired   => { circulate => 'circulate_remaining_permissions' },
42     }
43 );
44
45 my $action            = $cgi->param('action') || q{};
46 my $biblionumber      = $cgi->param('biblionumber');
47 my $patron_cardnumber = $cgi->param('patron_cardnumber');
48 my $patron_id         = $cgi->param('borrowernumber');
49
50 my $biblio = Koha::Biblios->find($biblionumber);
51 output_and_exit( $cgi, $cookie, $template, 'unknown_biblio')
52     unless $biblio;
53
54 my $patron =
55     $patron_id         ? Koha::Patrons->find($patron_id)
56   : $patron_cardnumber ? Koha::Patrons->find( { cardnumber => $patron_cardnumber } )
57   : undef;
58
59 if ( $action eq 'create' ) {
60     my $borrowernumber = $cgi->param('borrowernumber');
61     my $branchcode     = $cgi->param('branchcode');
62
63     my $itemnumber   = $cgi->param('itemnumber')   || undef;
64     my $title        = $cgi->param('title')        || undef;
65     my $author       = $cgi->param('author')       || undef;
66     my $volume       = $cgi->param('volume')       || undef;
67     my $issue        = $cgi->param('issue')        || undef;
68     my $date         = $cgi->param('date')         || undef;
69     my $pages        = $cgi->param('pages')        || undef;
70     my $chapters     = $cgi->param('chapters')     || undef;
71     my $patron_notes = $cgi->param('patron_notes') || undef;
72     my $format       = $cgi->param('format')       || undef;
73     my $toc_request  = $cgi->param('toc_request');
74
75     try {
76         my $ar = Koha::ArticleRequest->new(
77             {
78                 borrowernumber => $borrowernumber,
79                 biblionumber   => $biblionumber,
80                 branchcode     => $branchcode,
81                 itemnumber     => $itemnumber,
82                 title          => $title,
83                 author         => $author,
84                 volume         => $volume,
85                 issue          => $issue,
86                 date           => $date,
87                 pages          => $pages,
88                 chapters       => $chapters,
89                 patron_notes   => $patron_notes,
90                 format         => $format,
91                 toc_request    => $toc_request ? 1 : 0,
92             }
93         )->request;
94     } catch {
95         if ( blessed $_ and $_->isa('Koha::Exceptions::ArticleRequest::LimitReached') ) {
96             $template->param(
97                 error_message => 'article_request_limit_reached'
98             );
99         }
100         else {
101             Koha::Logger->get->debug("Unhandled exception when placing an article request ($_)");
102             $template->param(
103                 error_message => 'article_request_unhandled_exception'
104             );
105         }
106     };
107     undef $patron;
108 }
109
110 if ( $patron && !$patron->can_request_article ) {
111     $patron = undef;
112     $template->param( error_message => 'article_request_limit_reached' );
113 }
114
115 if ( $patron ) {
116     $template->param(
117         article_request_fee => $patron->article_request_fee
118     );
119 }
120
121 $template->param(
122     biblio => $biblio,
123     patron => $patron,
124     subscriptionsnumber => CountSubscriptionFromBiblionumber($biblionumber),
125     C4::Search::enabled_staff_search_views,
126     attribute_type_codes => ( C4::Context->preference('ExtendedPatronAttributes')
127         ? [ Koha::Patron::Attribute::Types->search( { staff_searchable => 1 } )->get_column('code') ]
128         : []
129     ),
130 );
131
132
133 output_html_with_http_headers $cgi, $cookie, $template->output;