Bug 16699: Remove requirement from borrowernumberQueryParam
[koha.git] / members / files.pl
blob3aa6aa7b0718f7320697c7ab07572f703403d4a7
1 #!/usr/bin/perl
3 # Copyright 2012 ByWater Solutions
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 strict;
21 use warnings;
23 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Branch;
27 use C4::Output;
28 use C4::Members;
29 use C4::Members::Attributes qw(GetBorrowerAttributes);
30 use C4::Debug;
32 use Koha::DateUtils;
33 use Koha::Patron::Files;
34 use Koha::Patron::Images;
36 my $cgi = CGI->new;
38 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
40 template_name => "members/files.tt",
41 query => $cgi,
42 type => "intranet",
43 authnotrequired => 0,
44 flagsrequired => { borrowers => 1 },
45 debug => 1,
48 $template->param( 'borrower_files' => 1 );
50 my $borrowernumber = $cgi->param('borrowernumber');
51 my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber );
53 my $op = $cgi->param('op') || '';
55 if ( $op eq 'download' ) {
56 my $file_id = $cgi->param('file_id');
57 my $file = $bf->GetFile( id => $file_id );
59 print $cgi->header(
60 -type => $file->{'file_type'},
61 -charset => 'utf-8',
62 -attachment => $file->{'file_name'}
64 print $file->{'file_content'};
66 else {
67 my $data = GetMember( borrowernumber => $borrowernumber );
68 $template->param(%$data);
70 my %errors;
72 if ( $op eq 'upload' ) {
73 my $uploaded_file = $cgi->upload('uploadfile');
75 if ($uploaded_file) {
76 my $filename = $cgi->param('uploadfile');
77 my $mimetype = $cgi->uploadInfo($filename)->{'Content-Type'};
79 $errors{'empty_upload'} = 1 if ( -z $uploaded_file );
81 if (%errors) {
82 $template->param( errors => %errors );
84 else {
85 my $file_content;
86 while (<$uploaded_file>) {
87 $file_content .= $_;
90 $bf->AddFile(
91 name => $filename,
92 type => $mimetype,
93 content => $file_content,
94 description => scalar $cgi->param('description'),
98 else {
99 $errors{'no_file'} = 1;
101 } elsif ( $op eq 'delete' ) {
102 $bf->DelFile( id => scalar $cgi->param('file_id') );
105 $template->param(
106 categoryname => $data->{'description'},
107 branchname => GetBranchName($data->{'branchcode'}),
108 RoutingSerials => C4::Context->preference('RoutingSerials'),
111 if (C4::Context->preference('ExtendedPatronAttributes')) {
112 my $attributes = GetBorrowerAttributes($borrowernumber);
113 $template->param(
114 ExtendedPatronAttributes => 1,
115 extendedattributes => $attributes
119 my $patron_image = Koha::Patron::Images->find($data->{borrowernumber});
120 $template->param( picture => 1 ) if $patron_image;
122 $template->param(
123 files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )
124 ->GetFilesInfo(),
126 errors => \%errors,
128 output_html_with_http_headers $cgi, $cookie, $template->output;
131 =head1 AUTHOR
133 Kyle M Hall <kyle@bywatersolutions.com>
135 =cut