]> git.koha-community.org Git - koha.git/blob - opac/opac-illrequests.pl
Bug 21337: Add Koha::Patrons->delete (trivial wrapper)
[koha.git] / opac / opac-illrequests.pl
1 #!/usr/bin/perl
2
3 # Copyright 2017 PTFS-Europe Ltd
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 CGI qw ( -utf8 );
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Output;
26
27 use Koha::Illrequest::Config;
28 use Koha::Illrequests;
29 use Koha::Libraries;
30 use Koha::Patrons;
31
32 my $query = new CGI;
33
34 # Grab all passed data
35 # 'our' since Plack changes the scoping
36 # of 'my'
37 our $params = $query->Vars();
38
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;
43 }
44
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 });
51
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 );
56
57 my $op = $params->{'method'} || 'list';
58
59 if ( $op eq 'list' ) {
60
61     my $requests = Koha::Illrequests->search(
62         { borrowernumber => $loggedinuser }
63     );
64     my $req = Koha::Illrequest->new;
65     $template->param(
66         requests => $requests,
67         backends    => $req->available_backends
68     );
69
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
77     );
78
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'
89     );
90     exit;
91 } elsif ( $op eq 'cancreq') {
92     my $request = Koha::Illrequests->find({
93         borrowernumber => $loggedinuser,
94         illrequest_id  => $params->{illrequest_id}
95     });
96     $request->status('CANCREQ')->store;
97     print $query->redirect(
98         '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
99         $params->{illrequest_id} .
100         '&message=1'
101     );
102     exit;
103 } elsif ( $op eq 'create' ) {
104     if (!$params->{backend}) {
105         my $req = Koha::Illrequest->new;
106         $template->param(
107             backends    => $req->available_backends
108         );
109     } else {
110         my $request = Koha::Illrequest->new
111             ->load_backend($params->{backend});
112         $params->{cardnumber} = Koha::Patrons->find({
113             borrowernumber => $loggedinuser
114         })->cardnumber;
115         $params->{opac} = 1;
116         my $backend_result = $request->backend_create($params);
117         if ($backend_result->{stage} eq 'copyrightclearance') {
118             $template->param(
119                 stage       => $backend_result->{stage},
120                 whole       => $backend_result
121             );
122         } else {
123             $template->param(
124                 media       => [ "Book", "Article", "Journal" ],
125                 branches    => Koha::Libraries->search->unblessed,
126                 whole       => $backend_result,
127                 request     => $request
128             );
129             if ($backend_result->{stage} eq 'commit') {
130                 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
131                 exit;
132             }
133         }
134
135     }
136 }
137
138 $template->param(
139     message         => $params->{message},
140     illrequestsview => 1,
141     method          => $op
142 );
143
144 output_html_with_http_headers $query, $cookie, $template->output;