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>.
27 use Koha::Illrequests;
33 # Grab all passed data
34 # 'our' since Plack changes the scoping
36 our $params = $query->Vars();
38 # if illrequests is disabled, leave immediately
39 if ( ! C4::Context->preference('ILLModule') ) {
40 print $query->redirect("/cgi-bin/koha/errors/404.pl");
44 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
45 template_name => "opac-illrequests.tt",
48 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
51 my $op = $params->{'method'} || 'list';
53 if ( $op eq 'list' ) {
55 my $requests = Koha::Illrequests->search(
56 { borrowernumber => $loggedinuser }
58 my $req = Koha::Illrequest->new;
60 requests => $requests,
61 backends => $req->available_backends
64 } elsif ( $op eq 'view') {
65 my $request = Koha::Illrequests->find({
66 borrowernumber => $loggedinuser,
67 illrequest_id => $params->{illrequest_id}
73 } elsif ( $op eq 'update') {
74 my $request = Koha::Illrequests->find({
75 borrowernumber => $loggedinuser,
76 illrequest_id => $params->{illrequest_id}
78 $request->notesopac($params->{notesopac})->store;
79 print $query->redirect(
80 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
81 $params->{illrequest_id} .
84 } elsif ( $op eq 'cancreq') {
85 my $request = Koha::Illrequests->find({
86 borrowernumber => $loggedinuser,
87 illrequest_id => $params->{illrequest_id}
89 $request->status('CANCREQ')->store;
90 print $query->redirect(
91 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
92 $params->{illrequest_id} .
96 } elsif ( $op eq 'create' ) {
97 if (!$params->{backend}) {
98 my $req = Koha::Illrequest->new;
100 backends => $req->available_backends
103 my $request = Koha::Illrequest->new
104 ->load_backend($params->{backend});
105 $params->{cardnumber} = Koha::Patrons->find({
106 borrowernumber => $loggedinuser
108 my $backend_result = $request->backend_create($params);
110 media => [ "Book", "Article", "Journal" ],
111 branches => Koha::Libraries->search->unblessed,
112 whole => $backend_result,
115 if ($backend_result->{stage} eq 'commit') {
116 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
124 message => $params->{message},
125 illrequestsview => 1,
129 output_html_with_http_headers $query, $cookie, $template->output;