Bug 15552: Better wording of intranetreadinghistory
[koha.git] / members / files.pl
blob45ed50d7c2aa94373859f61211060247cf7556bd
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::Borrower::Files;
35 my $cgi = CGI->new;
37 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
39 template_name => "members/files.tt",
40 query => $cgi,
41 type => "intranet",
42 authnotrequired => 0,
43 flagsrequired => { borrowers => 1 },
44 debug => 1,
47 $template->param( 'borrower_files' => 1 );
49 my $borrowernumber = $cgi->param('borrowernumber');
50 my $bf = Koha::Borrower::Files->new( borrowernumber => $borrowernumber );
52 my $op = $cgi->param('op') || '';
54 if ( $op eq 'download' ) {
55 my $file_id = $cgi->param('file_id');
56 my $file = $bf->GetFile( id => $file_id );
58 print $cgi->header(
59 -type => $file->{'file_type'},
60 -charset => 'utf-8',
61 -attachment => $file->{'file_name'}
63 print $file->{'file_content'};
65 else {
66 my $data = GetMember( borrowernumber => $borrowernumber );
67 $template->param(%$data);
69 my %errors;
71 if ( $op eq 'upload' ) {
72 my $uploaded_file = $cgi->upload('uploadfile');
74 if ($uploaded_file) {
75 my $filename = $cgi->param('uploadfile');
76 my $mimetype = $cgi->uploadInfo($filename)->{'Content-Type'};
78 $errors{'empty_upload'} = 1 if ( -z $uploaded_file );
80 if (%errors) {
81 $template->param( errors => %errors );
83 else {
84 my $file_content;
85 while (<$uploaded_file>) {
86 $file_content .= $_;
89 $bf->AddFile(
90 name => $filename,
91 type => $mimetype,
92 content => $file_content,
93 description => $cgi->param('description'),
97 else {
98 $errors{'no_file'} = 1;
100 } elsif ( $op eq 'delete' ) {
101 $bf->DelFile( id => $cgi->param('file_id') );
104 $template->param(
105 categoryname => $data->{'description'},
106 branchname => GetBranchName($data->{'branchcode'}),
107 RoutingSerials => C4::Context->preference('RoutingSerials'),
110 if (C4::Context->preference('ExtendedPatronAttributes')) {
111 my $attributes = GetBorrowerAttributes($borrowernumber);
112 $template->param(
113 ExtendedPatronAttributes => 1,
114 extendedattributes => $attributes
118 my ($picture, $dberror) = GetPatronImage($data->{'borrowernumber'});
119 $template->param( picture => 1 ) if $picture;
121 $template->param(
122 files => Koha::Borrower::Files->new( borrowernumber => $borrowernumber )
123 ->GetFilesInfo(),
125 errors => \%errors,
127 output_html_with_http_headers $cgi, $cookie, $template->output;
130 =head1 AUTHOR
132 Kyle M Hall <kyle@bywatersolutions.com>
134 =cut