Bug 26510: Transport Cost Matrix editor doesn't show all data when HoldsQueueSkipClos...
[koha.git] / members / files.pl
blob18487ae0229a6b0d924a628c22b2bcb10182444a
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 Modern::Perl;
22 use CGI qw ( -utf8 );
24 use C4::Auth;
25 use C4::Output;
26 use C4::Members;
27 use C4::Debug;
29 use Koha::DateUtils;
30 use Koha::Patrons;
31 use Koha::Patron::Files;
32 use Koha::Patron::Categories;
34 my $cgi = CGI->new;
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "members/files.tt",
39 query => $cgi,
40 type => "intranet",
41 flagsrequired => { borrowers => 'edit_borrowers' },
42 debug => 1,
45 $template->param( 'borrower_files' => 1 );
47 my $borrowernumber = $cgi->param('borrowernumber');
49 my $logged_in_user = Koha::Patrons->find( $loggedinuser );
50 my $patron = Koha::Patrons->find($borrowernumber);
51 output_and_exit_if_error( $cgi, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
53 my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber ); # FIXME Should be $patron->get_files. Koha::Patron::Files needs to be Koha::Objects based first
55 my $op = $cgi->param('op') || '';
57 if ( $op eq 'download' ) {
58 my $file_id = $cgi->param('file_id');
59 my $file = $bf->GetFile( id => $file_id );
61 print $cgi->header(
62 -type => $file->{'file_type'},
63 -charset => 'utf-8',
64 -attachment => $file->{'file_name'}
66 print $file->{'file_content'};
68 else {
70 my $patron_category = $patron->category;
71 $template->param( patron => $patron );
73 my %errors;
75 if ( $op eq 'upload' ) {
76 my $uploaded_file = $cgi->upload('uploadfile');
78 if ($uploaded_file) {
79 my $filename = $cgi->param('uploadfile');
80 my $mimetype = $cgi->uploadInfo($filename)->{'Content-Type'};
82 $errors{'empty_upload'} = 1 if ( -z $uploaded_file );
84 if (%errors) {
85 $template->param( errors => %errors );
87 else {
88 my $file_content;
89 while (<$uploaded_file>) {
90 $file_content .= $_;
93 $bf->AddFile(
94 name => $filename,
95 type => $mimetype,
96 content => $file_content,
97 description => scalar $cgi->param('description'),
101 else {
102 $errors{'no_file'} = 1;
104 } elsif ( $op eq 'delete' ) {
105 $bf->DelFile( id => scalar $cgi->param('file_id') );
108 $template->param(
109 files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )
110 ->GetFilesInfo(),
112 errors => \%errors,
114 output_html_with_http_headers $cgi, $cookie, $template->output;
117 =head1 AUTHOR
119 Kyle M Hall <kyle@bywatersolutions.com>
121 =cut