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 $reduced = C4
::Context
->preference('ILLOpacbackends');
54 my $backends = Koha
::Illrequest
::Config
->new->available_backends($reduced);
55 my $backends_available = ( scalar @
{$backends} > 0 );
56 $template->param( backends_available
=> $backends_available );
58 my $op = $params->{'method'} || 'list';
60 if ( $op eq 'list' ) {
62 my $requests = Koha
::Illrequests
->search(
63 { borrowernumber
=> $loggedinuser }
65 my $req = Koha
::Illrequest
->new;
67 requests
=> $requests,
71 } elsif ( $op eq 'view') {
72 my $request = Koha
::Illrequests
->find({
73 borrowernumber
=> $loggedinuser,
74 illrequest_id
=> $params->{illrequest_id
}
80 } elsif ( $op eq 'update') {
81 my $request = Koha
::Illrequests
->find({
82 borrowernumber
=> $loggedinuser,
83 illrequest_id
=> $params->{illrequest_id
}
85 $request->notesopac($params->{notesopac
})->store;
86 print $query->redirect(
87 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
88 $params->{illrequest_id
} .
92 } elsif ( $op eq 'cancreq') {
93 my $request = Koha
::Illrequests
->find({
94 borrowernumber
=> $loggedinuser,
95 illrequest_id
=> $params->{illrequest_id
}
97 $request->status('CANCREQ')->store;
98 print $query->redirect(
99 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
100 $params->{illrequest_id
} .
104 } elsif ( $op eq 'create' ) {
105 if (!$params->{backend
}) {
106 my $req = Koha
::Illrequest
->new;
108 backends
=> $req->available_backends
111 my $request = Koha
::Illrequest
->new
112 ->load_backend($params->{backend
});
113 $params->{cardnumber
} = Koha
::Patrons
->find({
114 borrowernumber
=> $loggedinuser
117 my $backend_result = $request->backend_create($params);
118 if ($backend_result->{stage
} eq 'copyrightclearance') {
120 stage
=> $backend_result->{stage
},
121 whole
=> $backend_result
125 types
=> [ "Book", "Article", "Journal" ],
126 branches
=> Koha
::Libraries
->search->unblessed,
127 whole
=> $backend_result,
130 if ($backend_result->{stage
} eq 'commit') {
131 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
140 message
=> $params->{message
},
141 illrequestsview
=> 1,
145 output_html_with_http_headers
$query, $cookie, $template->output;