Bug 21442: Update two-column templates with Bootstrap grid: Circulation part 1
[koha.git] / opac / opac-illrequests.pl
blob1b7807cb34e2d81909d0c563df7b47bbc7a5e229
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 CGI qw ( -utf8 );
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Output;
27 use Koha::Illrequest::Config;
28 use Koha::Illrequests;
29 use Koha::Libraries;
30 use Koha::Patrons;
32 my $query = new CGI;
34 # Grab all passed data
35 # 'our' since Plack changes the scoping
36 # of 'my'
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");
42 exit;
45 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
46 template_name => "opac-illrequests.tt",
47 query => $query,
48 type => "opac",
49 authnotrequired => 0,
50 });
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;
65 $template->param(
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}
74 });
75 $template->param(
76 request => $request
79 } elsif ( $op eq 'update') {
80 my $request = Koha::Illrequests->find({
81 borrowernumber => $loggedinuser,
82 illrequest_id => $params->{illrequest_id}
83 });
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} .
88 '&message=1'
90 exit;
91 } elsif ( $op eq 'cancreq') {
92 my $request = Koha::Illrequests->find({
93 borrowernumber => $loggedinuser,
94 illrequest_id => $params->{illrequest_id}
95 });
96 $request->status('CANCREQ')->store;
97 print $query->redirect(
98 '/cgi-bin/koha/opac-illrequests.pl?method=view&illrequest_id=' .
99 $params->{illrequest_id} .
100 '&message=1'
102 exit;
103 } elsif ( $op eq 'create' ) {
104 if (!$params->{backend}) {
105 my $req = Koha::Illrequest->new;
106 $template->param(
107 backends => $req->available_backends
109 } else {
110 my $request = Koha::Illrequest->new
111 ->load_backend($params->{backend});
112 $params->{cardnumber} = Koha::Patrons->find({
113 borrowernumber => $loggedinuser
114 })->cardnumber;
115 $params->{opac} = 1;
116 my $backend_result = $request->backend_create($params);
117 if ($backend_result->{stage} eq 'copyrightclearance') {
118 $template->param(
119 stage => $backend_result->{stage},
120 whole => $backend_result
122 } else {
123 $template->param(
124 types => [ "Book", "Article", "Journal" ],
125 branches => Koha::Libraries->search->unblessed,
126 whole => $backend_result,
127 request => $request
129 if ($backend_result->{stage} eq 'commit') {
130 print $query->redirect('/cgi-bin/koha/opac-illrequests.pl?message=2');
131 exit;
138 $template->param(
139 message => $params->{message},
140 illrequestsview => 1,
141 method => $op
144 output_html_with_http_headers $query, $cookie, $template->output;