|
Lines 3-16
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 |
# "publiclogdir" in koha-conf.xml so they can be downloaded by users with the |
6 |
# "accessdir" in koha-conf.xml so they can be downloaded by users with the |
| 7 |
# "reports" permission. |
7 |
# "reports" permission. |
| 8 |
# |
8 |
# |
| 9 |
# This file is part of Koha. |
9 |
# This file is part of Koha. |
| 10 |
# |
10 |
# |
| 11 |
# Koha is free software; you can redistribute it and/or modify it under the |
11 |
# Koha is free software; you can redistribute it and/or modify it under the |
| 12 |
# terms of the GNU General Public License as published by the Free Software |
12 |
# terms of the GNU General Public License as published by the Free Software |
| 13 |
# Foundation; either version 2 of the License, or (at your option) any later |
13 |
# Foundation; either version 3 of the License, or (at your option) any later |
| 14 |
# version. |
14 |
# version. |
| 15 |
# |
15 |
# |
| 16 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
16 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
|
Lines 33-64
use Digest::MD5 qw(md5_hex);
Link Here
|
| 33 |
|
33 |
|
| 34 |
my $input = new CGI; |
34 |
my $input = new CGI; |
| 35 |
my $file_id = $input->param("id"); |
35 |
my $file_id = $input->param("id"); |
| 36 |
my $directory = C4::Context->config('publiclogdir'); |
36 |
my $directory = C4::Context->config('accessdir'); |
| 37 |
|
37 |
|
| 38 |
my ($template, $borrowernumber, $cookie) |
38 |
my ($template, $borrowernumber, $cookie) |
| 39 |
= get_template_and_user({template_name => "reports/report_files.tt", |
39 |
= get_template_and_user({template_name => "reports/report_files.tt", |
| 40 |
query => $input, |
40 |
query => $input, |
| 41 |
type => "intranet", |
41 |
type => "intranet", |
| 42 |
authnotrequired => 0, |
42 |
authnotrequired => 0, |
| 43 |
flagsrequired => {reports => '*'}, |
43 |
flagsrequired => {reports => '*'}, |
| 44 |
}); |
44 |
}); |
| 45 |
|
45 |
|
| 46 |
unless($directory) { |
46 |
unless($directory) { |
| 47 |
$template->param(error_no_publiclogdir => 1); |
47 |
$template->param(error_no_dir => 1); |
| 48 |
} |
48 |
} |
| 49 |
else { |
49 |
else { |
| 50 |
#Get the files list |
50 |
#Get the files list |
| 51 |
my @files_list; |
51 |
my @files_list; |
| 52 |
opendir(DIR, $directory); |
52 |
opendir(DIR, $directory); |
| 53 |
|
53 |
|
| 54 |
foreach my $filename (readdir(DIR)) { |
54 |
foreach my $filename (readdir(DIR)) { |
| 55 |
my $id = md5_hex($filename); |
55 |
my $id = md5_hex($filename); |
| 56 |
my $full_path = "$directory/$filename"; |
56 |
my $full_path = "$directory/$filename"; |
| 57 |
next if ($filename =~ /^\./ or -d $full_path); |
57 |
next if ($filename =~ /^\./ or -d $full_path); |
| 58 |
|
58 |
|
| 59 |
my $st = stat($full_path); |
59 |
my $st = stat($full_path); |
|
|
60 |
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); |
| 61 |
my $dt=DateTime->new(year => $year + 1900, |
| 62 |
month => $mon + 1, |
| 63 |
day => $mday, |
| 64 |
hour => $hour, |
| 65 |
minute => $min, |
| 66 |
); |
| 60 |
push(@files_list, {name => $filename, |
67 |
push(@files_list, {name => $filename, |
| 61 |
date => scalar localtime($st->mtime), |
68 |
date =>Koha::DateUtils::output_pref($dt), |
| 62 |
size => $st->size, |
69 |
size => $st->size, |
| 63 |
id => $id}); |
70 |
id => $id}); |
| 64 |
} |
71 |
} |
|
Lines 75-88
else {
Link Here
|
| 75 |
-Content_length => -s "$directory/$filename", |
82 |
-Content_length => -s "$directory/$filename", |
| 76 |
-attachment => "$filename"); |
83 |
-attachment => "$filename"); |
| 77 |
|
84 |
|
| 78 |
open FILE, "<:utf8", "$directory/$filename"; |
85 |
my $fh; |
| 79 |
binmode FILE; |
86 |
open $fh, "<:encoding(UTF-8)", "$directory/$filename"; |
|
|
87 |
binmode $fh; |
| 80 |
|
88 |
|
| 81 |
my $buf; |
89 |
my $buf; |
| 82 |
while(read(FILE, $buf, 65536)) { |
90 |
while(read($fh, $buf, 65536)) { |
| 83 |
print $buf; |
91 |
print $buf; |
| 84 |
} |
92 |
} |
| 85 |
close FILE; |
93 |
close $fh; |
| 86 |
|
94 |
|
| 87 |
exit(1); |
95 |
exit(1); |
| 88 |
} |
96 |
} |
| 89 |
- |
|
|