Bug 9302: Use patron-title.inc
[koha.git] / opac / opac-illrequests.pl
blob6f2b33cd149c417b43118e76c8d06f3d12e27f22
1 #!/usr/bin/perl
3 # Copyright 2017 PTFS-Europe Ltd
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 CGI qw ( -utf8 );
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Output;
27 use Koha::Illrequest::Config;
28 use Koha::Illrequests;
29 use Koha::Libraries;
30 use Koha::Patrons;
32 my $query = new CGI;
34 # Grab all passed data
35 # 'our' since Plack changes the scoping
36 # of 'my'
37 our $params = $query->Vars();
39 # if illrequests is disabled, leave immediately
40 if ( ! C4::Context->preference('ILLModule') ) {
41 print $query->redirect("/cgi-bin/koha/errors/404.pl");
42 exit;
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
46 template_name => "opac-illrequests.tt",
47 query => $query,
48 type => "opac",
49 authnotrequired => 0,
50 });
52 # Are we able to actually work?
53 my $backends = Koha::Illrequest::Config->new->available_backends;
54 my $backends_available = ( scalar @{$backends} > 0 );
55 $template->param( backends_available => $backends_available );
57 my $op = $params->{'method'} || 'list';
59 if ( $op eq 'list' ) {
61 my $requests = Koha::Illrequests->search(
62 { borrowernumber => $loggedinuser }
64 my $req = Koha::Illrequest->new;
65 $template->param(
66 requests => $requests,
67 backends => $req->available_backends
70 } elsif ( $op eq 'view') {
71 my $request = Koha::Illrequests->find({
72 borrowernumber => $loggedinuser,
73 illrequest_id => $params->{illrequest_id}
74 });
75 $template->param(
76 request => $request
79 } elsif ( $op eq 'update') {
80 my $request = Koha::Illrequests->find({
81 borrowernumber => $loggedinuser,
82 illrequest_id => $params->{illrequest_id}
83 });
84 $request->notesopac($params->{notesopac})->store;
85 print $query->redirect(
86 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
87 $params->{illrequest_id} .
88 '&message=1'
90 } elsif ( $op eq 'cancreq') {
91 my $request = Koha::Illrequests->find({
92 borrowernumber => $loggedinuser,
93 illrequest_id => $params->{illrequest_id}
94 });
95 $request->status('CANCREQ')->store;
96 print $query->redirect(
97 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
98 $params->{illrequest_id} .
99 '&message=1'
102 } elsif ( $op eq 'create' ) {
103 if (!$params->{backend}) {
104 my $req = Koha::Illrequest->new;
105 $template->param(
106 backends => $req->available_backends
108 } else {
109 my $request = Koha::Illrequest->new
110 ->load_backend($params->{backend});
111 $params->{cardnumber} = Koha::Patrons->find({
112 borrowernumber => $loggedinuser
113 })->cardnumber;
114 my $backend_result = $request->backend_create($params);
115 $template->param(
116 media => [ "Book", "Article", "Journal" ],
117 branches => Koha::Libraries->search->unblessed,
118 whole => $backend_result,
119 request => $request
121 if ($backend_result->{stage} eq 'commit') {
122 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
127 $template->param(
128 message => $params->{message},
129 illrequestsview => 1,
130 method => $op
133 output_html_with_http_headers $query, $cookie, $template->output;