Bug 22844: Remove 'separate columns with |' from prefs description
[koha.git] / opac / opac-illrequests.pl
blobf81edf41cec8188a211c3ab191d6060cfa08e7eb
1 #!/usr/bin/perl
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>.
20 use Modern::Perl;
22 use JSON qw( encode_json );
24 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Koha;
27 use C4::Output;
29 use Koha::Illrequest::Config;
30 use Koha::Illrequests;
31 use Koha::Libraries;
32 use Koha::Patrons;
33 use Koha::Illrequest::Availability;
35 my $query = new CGI;
37 # Grab all passed data
38 # 'our' since Plack changes the scoping
39 # of 'my'
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");
45 exit;
48 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
49 template_name => "opac-illrequests.tt",
50 query => $query,
51 type => "opac",
52 authnotrequired => 0,
53 });
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;
69 $template->param(
70 requests => $requests,
71 backends => $backends
74 } elsif ( $op eq 'view') {
75 my $request = Koha::Illrequests->find({
76 borrowernumber => $loggedinuser,
77 illrequest_id => $params->{illrequest_id}
78 });
79 $template->param(
80 request => $request
83 } elsif ( $op eq 'update') {
84 my $request = Koha::Illrequests->find({
85 borrowernumber => $loggedinuser,
86 illrequest_id => $params->{illrequest_id}
87 });
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} .
92 '&message=1'
94 exit;
95 } elsif ( $op eq 'cancreq') {
96 my $request = Koha::Illrequests->find({
97 borrowernumber => $loggedinuser,
98 illrequest_id => $params->{illrequest_id}
99 });
100 $request->status('CANCREQ')->store;
101 print $query->redirect(
102 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
103 $params->{illrequest_id} .
104 '&message=1'
106 exit;
107 } elsif ( $op eq 'create' ) {
108 if (!$params->{backend}) {
109 my $req = Koha::Illrequest->new;
110 $template->param(
111 backends => $req->available_backends
113 } else {
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.
119 if (
120 C4::Context->preference("ILLCheckAvailability") &&
121 $request->_backend_capability(
122 'should_display_availability',
123 $params
124 ) &&
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({
133 ui_context => 'opac'
135 if (scalar @{$services} > 0) {
136 # Modify our method so we use the correct part of the
137 # template
138 $op = 'availability';
139 # Prepare the metadata we're sending them
140 my $metadata = $availability->prep_metadata($params);
141 $template->param(
142 metadata => $metadata,
143 services_json => encode_json($services),
144 services => $services,
145 illrequestsview => 1,
146 message => $params->{message},
147 method => $op,
148 whole => $params
150 output_html_with_http_headers $query, $cookie,
151 $template->output, undef, { force_no_caching => 1 };
152 exit;
156 $params->{cardnumber} = Koha::Patrons->find({
157 borrowernumber => $loggedinuser
158 })->cardnumber;
159 $params->{opac} = 1;
160 my $backend_result = $request->backend_create($params);
161 if ($backend_result->{stage} eq 'copyrightclearance') {
162 $template->param(
163 stage => $backend_result->{stage},
164 whole => $backend_result
166 } else {
167 $template->param(
168 types => [ "Book", "Article", "Journal" ],
169 branches => Koha::Libraries->search->unblessed,
170 whole => $backend_result,
171 request => $request
173 if ($backend_result->{stage} eq 'commit') {
174 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
175 exit;
182 $template->param(
183 message => $params->{message},
184 illrequestsview => 1,
185 method => $op
188 output_html_with_http_headers $query, $cookie, $template->output, undef, { force_no_caching => 1 };