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>.
22 use JSON
qw( encode_json );
29 use Koha
::Illrequest
::Config
;
30 use Koha
::Illrequests
;
33 use Koha
::Illrequest
::Availability
;
37 # Grab all passed data
38 # 'our' since Plack changes the scoping
40 our $params = $query->Vars();
42 # if illrequests is disabled, leave immediately
43 if ( ! C4
::Context
->preference('ILLModule') ) {
44 print $query->redirect("/cgi-bin/koha/errors/404.pl");
48 my ( $template, $loggedinuser, $cookie ) = get_template_and_user
({
49 template_name
=> "opac-illrequests.tt",
55 # Are we able to actually work?
56 my $reduced = C4
::Context
->preference('ILLOpacbackends');
57 my $backends = Koha
::Illrequest
::Config
->new->available_backends($reduced);
58 my $backends_available = ( scalar @
{$backends} > 0 );
59 $template->param( backends_available
=> $backends_available );
61 my $op = $params->{'method'} || 'list';
63 if ( $op eq 'list' ) {
65 my $requests = Koha
::Illrequests
->search(
66 { borrowernumber
=> $loggedinuser }
68 my $req = Koha
::Illrequest
->new;
70 requests
=> $requests,
74 } elsif ( $op eq 'view') {
75 my $request = Koha
::Illrequests
->find({
76 borrowernumber
=> $loggedinuser,
77 illrequest_id
=> $params->{illrequest_id
}
83 } elsif ( $op eq 'update') {
84 my $request = Koha
::Illrequests
->find({
85 borrowernumber
=> $loggedinuser,
86 illrequest_id
=> $params->{illrequest_id
}
88 $request->notesopac($params->{notesopac
})->store;
89 print $query->redirect(
90 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
91 $params->{illrequest_id
} .
95 } elsif ( $op eq 'cancreq') {
96 my $request = Koha
::Illrequests
->find({
97 borrowernumber
=> $loggedinuser,
98 illrequest_id
=> $params->{illrequest_id
}
100 $request->status('CANCREQ')->store;
101 print $query->redirect(
102 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
103 $params->{illrequest_id
} .
107 } elsif ( $op eq 'create' ) {
108 if (!$params->{backend
}) {
109 my $req = Koha
::Illrequest
->new;
111 backends
=> $req->available_backends
114 my $request = Koha
::Illrequest
->new
115 ->load_backend($params->{backend
});
117 # Does this backend enable us to insert an availability stage and should
118 # we? If not, proceed as normal.
120 C4
::Context
->preference("ILLCheckAvailability") &&
121 $request->_backend_capability(
122 'should_display_availability',
125 # If the user has elected to continue with the request despite
126 # having viewed availability info, this flag will be set
127 !$params->{checked_availability
}
129 # Establish which of the installed availability providers
130 # can service our metadata, if so, jump in
131 my $availability = Koha
::Illrequest
::Availability
->new($params);
132 my $services = $availability->get_services({
135 if (scalar @
{$services} > 0) {
136 # Modify our method so we use the correct part of the
138 $op = 'availability';
139 # Prepare the metadata we're sending them
140 my $metadata = $availability->prep_metadata($params);
142 metadata
=> $metadata,
143 services_json
=> encode_json
($services),
144 services
=> $services,
145 illrequestsview
=> 1,
146 message
=> $params->{message
},
150 output_html_with_http_headers
$query, $cookie,
151 $template->output, undef, { force_no_caching
=> 1 };
156 $params->{cardnumber
} = Koha
::Patrons
->find({
157 borrowernumber
=> $loggedinuser
160 my $backend_result = $request->backend_create($params);
161 if ($backend_result->{stage
} eq 'copyrightclearance') {
163 stage
=> $backend_result->{stage
},
164 whole
=> $backend_result
168 types
=> [ "Book", "Article", "Journal" ],
169 branches
=> Koha
::Libraries
->search->unblessed,
170 whole
=> $backend_result,
173 if ($backend_result->{stage
} eq 'commit') {
174 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
183 message
=> $params->{message
},
184 illrequestsview
=> 1,
188 output_html_with_http_headers
$query, $cookie, $template->output, undef, { force_no_caching
=> 1 };