@@ -, +, @@ --- reports/report_files.pl | 52 ++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 24 deletions(-) --- a/reports/report_files.pl +++ a/reports/report_files.pl @@ -31,9 +31,10 @@ use C4::Koha; use File::stat; use Digest::MD5 qw(md5_hex); -my $input = new CGI; +my $input = new CGI; my $file_id = $input->param("id"); -my $directory = C4::Context->config('accessdir'); +my $accessdir = C4::Context->config('accessdir'); +my @directories = $accessdir ? (ref $accessdir ? @{$accessdir} : ($accessdir)) : (); my ($template, $borrowernumber, $cookie) = get_template_and_user({template_name => "reports/report_files.tt", @@ -43,47 +44,50 @@ my ($template, $borrowernumber, $cookie) flagsrequired => {reports => '*'}, }); -unless($directory) { +unless(@directories) { $template->param(error_no_dir => 1); } else { #Get the files list my @files_list; - opendir(DIR, $directory); + foreach my $dir(@directories){ + opendir(DIR, $dir); + foreach my $filename (readdir(DIR)) { + my $id = md5_hex($filename); + my $full_path = "$dir/$filename"; + next if ($filename =~ /^\./ or -d $full_path); - foreach my $filename (readdir(DIR)) { - my $id = md5_hex($filename); - my $full_path = "$directory/$filename"; - next if ($filename =~ /^\./ or -d $full_path); - - my $st = stat($full_path); - my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); - my $dt=DateTime->new(year => $year + 1900, - month => $mon + 1, - day => $mday, - hour => $hour, - minute => $min, - ); - push(@files_list, {name => $filename, - date =>Koha::DateUtils::output_pref($dt), - size => $st->size, - id => $id}); + my $st = stat($full_path); + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); + my $dt=DateTime->new(year => $year + 1900, + month => $mon + 1, + day => $mday, + hour => $hour, + minute => $min, + ); + push(@files_list, {name => $filename, + accessdir => $dir, + date =>Koha::DateUtils::output_pref($dt), + size => $st->size, + id => $id}); + } + closedir(DIR); } - closedir(DIR); my %files_hash = map { $_->{id} => $_ } @files_list; # If we received a file_id and it is valid, send the file to the browser if(defined $file_id and $file_id >= 0 and exists $files_hash{$file_id} ){ my $filename = $files_hash{$file_id}->{name}; + my $dir = $files_hash{$file_id}->{accessdir}; binmode STDOUT; # Open the selected file and send it to the browser print $input->header(-type => 'application/x-download', -name => "$filename", - -Content_length => -s "$directory/$filename", + -Content_length => -s "$dir/$filename", -attachment => "$filename"); my $fh; - open $fh, "<:encoding(UTF-8)", "$directory/$filename"; + open $fh, "<:encoding(UTF-8)", "$dir/$filename"; binmode $fh; my $buf; --