| Lines 31-39
          use C4::Koha;
      
      
        Link Here | 
        
          | 31 | use File::stat; | 31 | use File::stat; | 
        
          | 32 | use Digest::MD5 qw(md5_hex); | 32 | use Digest::MD5 qw(md5_hex); | 
        
          | 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('accessdir'); | 36 | my $accessdir = C4::Context->config('accessdir'); | 
            
              |  |  | 37 | my @directories = $accessdir ? (ref $accessdir ? @{$accessdir} : ($accessdir)) : (); | 
        
          | 37 |  | 38 |  | 
        
          | 38 | my ($template, $borrowernumber, $cookie) | 39 | my ($template, $borrowernumber, $cookie) | 
        
          | 39 |     = get_template_and_user({template_name => "reports/report_files.tt", | 40 |     = get_template_and_user({template_name => "reports/report_files.tt", | 
  
    | Lines 43-89
          my ($template, $borrowernumber, $cookie)
      
      
        Link Here | 
        
          | 43 |                 flagsrequired => {reports => '*'}, | 44 |                 flagsrequired => {reports => '*'}, | 
        
          | 44 |                 }); | 45 |                 }); | 
        
          | 45 |  | 46 |  | 
          
            
              | 46 | unless($directory) { | 47 | unless(@directories) { | 
        
          | 47 |     $template->param(error_no_dir => 1); | 48 |     $template->param(error_no_dir => 1); | 
        
          | 48 | } | 49 | } | 
        
          | 49 | else { | 50 | else { | 
        
          | 50 |     #Get the files list | 51 |     #Get the files list | 
        
          | 51 |     my @files_list; | 52 |     my @files_list; | 
          
            
              | 52 |     opendir(DIR, $directory); | 53 |     foreach my $dir(@directories){ | 
            
              |  |  | 54 |         opendir(DIR, $dir); | 
            
              | 55 |         foreach my $filename (readdir(DIR)) { | 
            
              | 56 |         my $id = md5_hex($filename); | 
            
              | 57 |             my $full_path = "$dir/$filename"; | 
            
              | 58 |             next if ($filename =~ /^\./ or -d $full_path); | 
        
          | 53 |  | 59 |  | 
          
            
              | 54 |     foreach my $filename (readdir(DIR)) { | 60 |             my $st = stat($full_path); | 
            
              | 55 |     my $id = md5_hex($filename); | 61 |             my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); | 
            
              | 56 |         my $full_path = "$directory/$filename"; | 62 |             my $dt=DateTime->new(year      => $year + 1900, | 
            
              | 57 |         next if ($filename =~ /^\./ or -d $full_path); | 63 |                                   month    => $mon + 1, | 
            
              | 58 |  | 64 |                                   day      => $mday, | 
            
              | 59 |         my $st = stat($full_path); | 65 |                                   hour     => $hour, | 
            
              | 60 |         my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime); | 66 |                                   minute   => $min, | 
            
              | 61 |         my $dt=DateTime->new(year      => $year + 1900, | 67 |                             ); | 
            
              | 62 |                               month    => $mon + 1, | 68 |             push(@files_list, {name => $filename, | 
            
              | 63 |                               day      => $mday, | 69 |                                accessdir => $dir, | 
            
              | 64 |                               hour     => $hour, | 70 |                                date =>Koha::DateUtils::output_pref($dt), | 
            
              | 65 |                               minute   => $min, | 71 |                                size => $st->size, | 
            
              | 66 |                         ); | 72 |                                id   => $id}); | 
            
              | 67 |         push(@files_list, {name => $filename, | 73 |         } | 
            
              | 68 |                            date =>Koha::DateUtils::output_pref($dt), | 74 |         closedir(DIR); | 
            
              | 69 |                            size => $st->size, |  |  | 
            
              | 70 |                            id   => $id}); | 
        
          | 71 |     } | 75 |     } | 
            
              | 72 |     closedir(DIR); |  |  | 
        
          | 73 |  | 76 |  | 
        
          | 74 |     my %files_hash = map { $_->{id} => $_ } @files_list; | 77 |     my %files_hash = map { $_->{id} => $_ } @files_list; | 
        
          | 75 |     # If we received a file_id and it is valid, send the file to the browser | 78 |     # If we received a file_id and it is valid, send the file to the browser | 
        
          | 76 |     if(defined $file_id and $file_id >= 0 and exists $files_hash{$file_id} ){ | 79 |     if(defined $file_id and $file_id >= 0 and exists $files_hash{$file_id} ){ | 
        
          | 77 |         my $filename = $files_hash{$file_id}->{name}; | 80 |         my $filename = $files_hash{$file_id}->{name}; | 
            
              |  |  | 81 |         my $dir = $files_hash{$file_id}->{accessdir}; | 
        
          | 78 |         binmode STDOUT; | 82 |         binmode STDOUT; | 
        
          | 79 |         # Open the selected file and send it to the browser | 83 |         # Open the selected file and send it to the browser | 
        
          | 80 |         print $input->header(-type => 'application/x-download', | 84 |         print $input->header(-type => 'application/x-download', | 
        
          | 81 |                              -name => "$filename", | 85 |                              -name => "$filename", | 
          
            
              | 82 |                              -Content_length => -s "$directory/$filename", | 86 |                              -Content_length => -s "$dir/$filename", | 
        
          | 83 |                              -attachment => "$filename"); | 87 |                              -attachment => "$filename"); | 
        
          | 84 |  | 88 |  | 
        
          | 85 |         my $fh; | 89 |         my $fh; | 
          
            
              | 86 |         open $fh, "<:encoding(UTF-8)", "$directory/$filename"; | 90 |         open $fh, "<:encoding(UTF-8)", "$dir/$filename"; | 
        
          | 87 |         binmode $fh; | 91 |         binmode $fh; | 
        
          | 88 |  | 92 |  | 
        
          | 89 |         my $buf; | 93 |         my $buf; | 
            
              | 90 | -  |  |  |