Bug 17785: Fix OAI-PMH's XSLT-generated URLs under Plack
[koha.git] / opac / opac-discharge.pl
blob3b75166dec03d0aeec0f10c90f7f75a21cb3c6a7
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Copyright 2013 BibLibre
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;
21 use Carp;
23 use C4::Auth qw(:DEFAULT get_session);
24 use CGI qw( -utf8 );
25 use C4::Context;
26 use C4::Output;
27 use C4::Log;
28 use C4::Debug;
29 use C4::Members;
30 use Koha::Patron::Discharge;
31 use Koha::DateUtils;
33 my $input = new CGI;
35 unless ( C4::Context->preference('useDischarge') ) {
36 print $input->redirect("/cgi-bin/koha/errors/404.pl");
37 exit;
40 my $op = $input->param("op");
42 # Getting the template and auth
43 my ( $template, $loggedinuser, $cookie ) = get_template_and_user({
44 template_name => "opac-discharge.tt",
45 query => $input,
46 type => "opac",
47 debug => 1,
48 });
50 if ( $op eq 'request' ) {
51 my $success = Koha::Patron::Discharge::request({
52 borrowernumber => $loggedinuser,
53 });
55 if ($success) {
56 $template->param( success => 1 );
58 else {
59 $template->param( has_issues => 1 );
62 elsif ( $op eq 'get' ) {
63 eval {
65 # Getting member data
66 my $data = GetMember( borrowernumber => $loggedinuser );
67 my $pdf_path = Koha::Patron::Discharge::generate_as_pdf({
68 borrowernumber => $loggedinuser,
69 branchcode => $data->{'branchcode'},
70 });
72 binmode(STDOUT);
73 print $input->header(
74 -type => 'application/pdf',
75 -charset => 'utf-8',
76 -attachment => "discharge_$loggedinuser.pdf",
78 open my $fh, '<', $pdf_path;
79 my @lines = <$fh>;
80 close $fh;
81 print @lines;
82 exit;
84 if ( $@ ) {
85 carp $@;
86 $template->param( messages => [ {type => 'error', code => 'unable_to_generate_pdf'} ] );
89 else {
90 my $pending = Koha::Patron::Discharge::count({
91 borrowernumber => $loggedinuser,
92 pending => 1,
93 });
94 # FIXME looks like $available is not needed
95 # If a patron is discharged he has a validated discharge available
96 my $available = Koha::Patron::Discharge::count({
97 borrowernumber => $loggedinuser,
98 validated => 1,
99 });
100 $template->param(
101 available => $available && Koha::Patron::Discharge::is_discharged({borrowernumber => $loggedinuser}),
102 pending => $pending,
106 $template->param( dischargeview => 1 );
108 output_html_with_http_headers $input, $cookie, $template->output, undef, { force_no_caching => 1 };