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
::Illrequest
::Config
;
28 use Koha
::Illrequests
;
34 # Grab all passed data
35 # 'our' since Plack changes the scoping
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");
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
({
46 template_name
=> "opac-illrequests.tt",
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;
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
}
79 } elsif ( $op eq 'update') {
80 my $request = Koha
::Illrequests
->find({
81 borrowernumber
=> $loggedinuser,
82 illrequest_id
=> $params->{illrequest_id
}
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
} .
90 } elsif ( $op eq 'cancreq') {
91 my $request = Koha
::Illrequests
->find({
92 borrowernumber
=> $loggedinuser,
93 illrequest_id
=> $params->{illrequest_id
}
95 $request->status('CANCREQ')->store;
96 print $query->redirect(
97 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
98 $params->{illrequest_id
} .
102 } elsif ( $op eq 'create' ) {
103 if (!$params->{backend
}) {
104 my $req = Koha
::Illrequest
->new;
106 backends
=> $req->available_backends
109 my $request = Koha
::Illrequest
->new
110 ->load_backend($params->{backend
});
111 $params->{cardnumber
} = Koha
::Patrons
->find({
112 borrowernumber
=> $loggedinuser
114 my $backend_result = $request->backend_create($params);
116 media
=> [ "Book", "Article", "Journal" ],
117 branches
=> Koha
::Libraries
->search->unblessed,
118 whole
=> $backend_result,
121 if ($backend_result->{stage
} eq 'commit') {
122 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
128 message
=> $params->{message
},
129 illrequestsview
=> 1,
133 output_html_with_http_headers
$query, $cookie, $template->output;