Lines 3-9
Link Here
|
3 |
# Frédérick Capovilla, 2011 - Libéo |
3 |
# Frédérick Capovilla, 2011 - Libéo |
4 |
# |
4 |
# |
5 |
# Show a list of all the files in the directory specified by the option |
5 |
# Show a list of all the files in the directory specified by the option |
6 |
# "accessdir" in koha-conf.xml so they can be downloaded by users with the |
6 |
# "access_dir" in koha-conf.xml so they can be downloaded by users with the |
7 |
# "access_files" permission. |
7 |
# "access_files" permission. |
8 |
# |
8 |
# |
9 |
# This file is part of Koha. |
9 |
# This file is part of Koha. |
Lines 30-40
use C4::Output;
Link Here
|
30 |
use C4::Koha; |
30 |
use C4::Koha; |
31 |
use File::stat qw(stat); |
31 |
use File::stat qw(stat); |
32 |
use Digest::MD5 qw(md5_hex); |
32 |
use Digest::MD5 qw(md5_hex); |
|
|
33 |
use Encode; |
33 |
|
34 |
|
34 |
my $input = new CGI; |
35 |
my $input = new CGI; |
35 |
my $file_id = $input->param("id"); |
36 |
my $file_id = $input->param("id"); |
36 |
my $accessdir = C4::Context->config('accessdir'); |
37 |
my $access_dir = C4::Context->config('access_dir'); |
37 |
my @directories = $accessdir ? (ref $accessdir ? @{$accessdir} : ($accessdir)) : (); |
38 |
my @directories = $access_dir ? (ref $access_dir ? @{$access_dir} : ($access_dir)) : (); |
38 |
|
39 |
|
39 |
my ($template, $borrowernumber, $cookie) |
40 |
my ($template, $borrowernumber, $cookie) |
40 |
= get_template_and_user({template_name => "tools/access_files.tt", |
41 |
= get_template_and_user({template_name => "tools/access_files.tt", |
Lines 54-63
else {
Link Here
|
54 |
opendir(DIR, $dir); |
55 |
opendir(DIR, $dir); |
55 |
foreach my $filename (readdir(DIR)) { |
56 |
foreach my $filename (readdir(DIR)) { |
56 |
my $full_path = "$dir/$filename"; |
57 |
my $full_path = "$dir/$filename"; |
57 |
my $id = md5_hex($full_path); |
58 |
my $id = md5_hex($full_path); |
58 |
next if ($filename =~ /^\./ or -d $full_path); |
59 |
next if ($filename =~ /^\./ or -d $full_path); |
59 |
|
60 |
|
60 |
my $st = stat($full_path); |
61 |
# Make sure the filename is unicode-friendly |
|
|
62 |
my $decoded_filename = decode('utf8', $filename); |
63 |
my $st = stat("$dir/$decoded_filename"); |
64 |
|
61 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); |
65 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); |
62 |
my $dt=DateTime->new(year => $year + 1900, |
66 |
my $dt=DateTime->new(year => $year + 1900, |
63 |
month => $mon + 1, |
67 |
month => $mon + 1, |
Lines 65-72
else {
Link Here
|
65 |
hour => $hour, |
69 |
hour => $hour, |
66 |
minute => $min, |
70 |
minute => $min, |
67 |
); |
71 |
); |
68 |
push(@files_list, {name => $filename, |
72 |
push(@files_list, {name => $decoded_filename, |
69 |
accessdir => $dir, |
73 |
access_dir => $dir, |
70 |
date =>Koha::DateUtils::output_pref($dt), |
74 |
date =>Koha::DateUtils::output_pref($dt), |
71 |
size => $st->size, |
75 |
size => $st->size, |
72 |
id => $id}); |
76 |
id => $id}); |
Lines 78-84
else {
Link Here
|
78 |
# If we received a file_id and it is valid, send the file to the browser |
82 |
# If we received a file_id and it is valid, send the file to the browser |
79 |
if(defined $file_id and exists $files_hash{$file_id} ){ |
83 |
if(defined $file_id and exists $files_hash{$file_id} ){ |
80 |
my $filename = $files_hash{$file_id}->{name}; |
84 |
my $filename = $files_hash{$file_id}->{name}; |
81 |
my $dir = $files_hash{$file_id}->{accessdir}; |
85 |
my $dir = $files_hash{$file_id}->{access_dir}; |
82 |
binmode STDOUT; |
86 |
binmode STDOUT; |
83 |
# Open the selected file and send it to the browser |
87 |
# Open the selected file and send it to the browser |
84 |
print $input->header(-type => 'application/x-download', |
88 |
print $input->header(-type => 'application/x-download', |
85 |
- |
|
|