Bug 21481: Remove reference of *-staff-help.po from koha-translate
[koha.git] / members / files.pl
blob46c3694bbade009f256da6f6a99f2542ff037bb2
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::Members::Attributes qw(GetBorrowerAttributes);
28 use C4::Debug;
30 use Koha::DateUtils;
31 use Koha::Patrons;
32 use Koha::Patron::Files;
33 use Koha::Patron::Categories;
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 => 'edit_borrowers' },
44 debug => 1,
47 $template->param( 'borrower_files' => 1 );
49 my $borrowernumber = $cgi->param('borrowernumber');
51 my $logged_in_user = Koha::Patrons->find( $loggedinuser ) or die "Not logged in";
52 my $patron = Koha::Patrons->find($borrowernumber);
53 output_and_exit_if_error( $cgi, $cookie, $template, { module => 'members', logged_in_user => $logged_in_user, current_patron => $patron } );
55 my $bf = Koha::Patron::Files->new( borrowernumber => $borrowernumber ); # FIXME Should be $patron->get_files. Koha::Patron::Files needs to be Koha::Objects based first
57 my $op = $cgi->param('op') || '';
59 if ( $op eq 'download' ) {
60 my $file_id = $cgi->param('file_id');
61 my $file = $bf->GetFile( id => $file_id );
63 print $cgi->header(
64 -type => $file->{'file_type'},
65 -charset => 'utf-8',
66 -attachment => $file->{'file_name'}
68 print $file->{'file_content'};
70 else {
72 my $patron_category = $patron->category;
73 $template->param( patron => $patron );
75 my %errors;
77 if ( $op eq 'upload' ) {
78 my $uploaded_file = $cgi->upload('uploadfile');
80 if ($uploaded_file) {
81 my $filename = $cgi->param('uploadfile');
82 my $mimetype = $cgi->uploadInfo($filename)->{'Content-Type'};
84 $errors{'empty_upload'} = 1 if ( -z $uploaded_file );
86 if (%errors) {
87 $template->param( errors => %errors );
89 else {
90 my $file_content;
91 while (<$uploaded_file>) {
92 $file_content .= $_;
95 $bf->AddFile(
96 name => $filename,
97 type => $mimetype,
98 content => $file_content,
99 description => scalar $cgi->param('description'),
103 else {
104 $errors{'no_file'} = 1;
106 } elsif ( $op eq 'delete' ) {
107 $bf->DelFile( id => scalar $cgi->param('file_id') );
110 if (C4::Context->preference('ExtendedPatronAttributes')) {
111 my $attributes = GetBorrowerAttributes($borrowernumber);
112 $template->param(
113 ExtendedPatronAttributes => 1,
114 extendedattributes => $attributes
118 $template->param(
119 files => Koha::Patron::Files->new( borrowernumber => $borrowernumber )
120 ->GetFilesInfo(),
122 errors => \%errors,
124 output_html_with_http_headers $cgi, $cookie, $template->output;
127 =head1 AUTHOR
129 Kyle M Hall <kyle@bywatersolutions.com>
131 =cut