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
} .
91 } elsif ( $op eq 'cancreq') {
92 my $request = Koha
::Illrequests
->find({
93 borrowernumber
=> $loggedinuser,
94 illrequest_id
=> $params->{illrequest_id
}
96 $request->status('CANCREQ')->store;
97 print $query->redirect(
98 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
99 $params->{illrequest_id
} .
103 } elsif ( $op eq 'create' ) {
104 if (!$params->{backend
}) {
105 my $req = Koha
::Illrequest
->new;
107 backends
=> $req->available_backends
110 my $request = Koha
::Illrequest
->new
111 ->load_backend($params->{backend
});
112 $params->{cardnumber
} = Koha
::Patrons
->find({
113 borrowernumber
=> $loggedinuser
116 my $backend_result = $request->backend_create($params);
117 if ($backend_result->{stage
} eq 'copyrightclearance') {
119 stage
=> $backend_result->{stage
},
120 whole
=> $backend_result
124 types
=> [ "Book", "Article", "Journal" ],
125 branches
=> Koha
::Libraries
->search->unblessed,
126 whole
=> $backend_result,
129 if ($backend_result->{stage
} eq 'commit') {
130 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
139 message
=> $params->{message
},
140 illrequestsview
=> 1,
144 output_html_with_http_headers
$query, $cookie, $template->output;