View | Details | Raw Unified | Return to bug 11317
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bz11317-add-permission-for-tools-access-file.sql (+1 lines)
Line 0 Link Here
1
INSERT INTO permissions (module_bit, code, description) VALUES (13, 'access_files', 'Access to the files stored on the server');
(-)a/installer/data/mysql/userpermissions.sql (+1 lines)
Lines 57-62 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
57
   (13, 'records_batchmod', 'Perform batch modification of records (biblios or authorities)'),
57
   (13, 'records_batchmod', 'Perform batch modification of records (biblios or authorities)'),
58
   (13, 'marc_modification_templates', 'Manage marc modification templates'),
58
   (13, 'marc_modification_templates', 'Manage marc modification templates'),
59
   (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'),
59
   (13, 'records_batchdel', 'Perform batch deletion of records (bibliographic or authority)'),
60
   (13, 'access_files', 'Access to the files stored on the server'),
60
   (15, 'check_expiration', 'Check the expiration of a serial'),
61
   (15, 'check_expiration', 'Check the expiration of a serial'),
61
   (15, 'claim_serials', 'Claim missing serials'),
62
   (15, 'claim_serials', 'Claim missing serials'),
62
   (15, 'create_subscription', 'Create a new subscription'),
63
   (15, 'create_subscription', 'Create a new subscription'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc (+1 lines)
Lines 100-104 Link Here
100
    [%- CASE 'report' -%]<span>Use report plugins</span>
100
    [%- CASE 'report' -%]<span>Use report plugins</span>
101
    [%- CASE 'tool' -%]<span>Use tool plugins</span>
101
    [%- CASE 'tool' -%]<span>Use tool plugins</span>
102
    [%- CASE 'delete_public_lists' -%]<span>Delete public lists</span>
102
    [%- CASE 'delete_public_lists' -%]<span>Delete public lists</span>
103
    [%- CASE 'access_files' -%]<span>Access to the files stored on the server</span>
103
    [%- END -%]
104
    [%- END -%]
104
[%- END -%]
105
[%- END -%]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt (-67 lines)
Lines 1-67 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Report/log files</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<link rel="stylesheet" type="text/css" href="[% themelang %]/css/datatables.css" />
5
[% INCLUDE 'datatables.inc' %]
6
[% INCLUDE 'datatables-strings.inc' %]
7
<script type="text/JavaScript" language="JavaScript">
8
    //<![CDATA[
9
        $(document).ready(function() {
10
            $("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
11
                "sDom": 't',
12
                "aoColumnDefs": [
13
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
14
                ],
15
                "bPaginate": false
16
            }));
17
    });
18
    //]]>
19
</script>
20
</head>
21
<body>
22
[% INCLUDE 'header.inc' %]
23
[% INCLUDE 'cat-search.inc' %]
24
25
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/reports/reports-home.pl">Reports</a> &rsaquo; Report/log files</div>
26
27
<div id="doc3" class="yui-t2">
28
   <div id="bd">
29
    <div id="yui-main">
30
    <div class="yui-b">
31
32
    <h1>Report/log files</h1>
33
34
[% IF ( error_no_dir ) %]
35
    <div class="dialog alert"><strong>Error : </strong>Report/log files could not be found because the "accessdir" option was not set in "koha-conf.xml". Contact your system administrator to add this option.</div>
36
[% ELSE %]
37
    [% IF ( files_loop ) %]
38
        <table id="files">
39
            <thead>
40
                <tr>
41
                    <th>Name</th>
42
                    <th>Size (bytes)</th>
43
                    <th>Date last modified</th>
44
                </tr>
45
            </thead>
46
            <tbody>
47
                [% FOREACH file IN files_loop %]
48
                <tr>
49
                    <td><a href="/cgi-bin/koha/reports/report_files.pl?id=[% file.id |url %]">[% file.name %]</a></td>
50
                    <td align="right">[% file.size %]</td>
51
                    <td>[% file.date %]</td>
52
                </tr>
53
                [% END %]
54
            </tbody>
55
        </table>
56
    [% ELSE %]
57
        No file found.
58
    [% END %]
59
[% END %]
60
61
</div>
62
</div>
63
<div class="yui-b">
64
[% INCLUDE 'reports-menu.inc' %]
65
</div>
66
</div>
67
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt (-1 / +3 lines)
Lines 109-116 Link Here
109
    <dd>Manage EDIfact transmissions</dd>
109
    <dd>Manage EDIfact transmissions</dd>
110
    [% END %]
110
    [% END %]
111
111
112
    <dt><a href="/cgi-bin/koha/reports/report_files.pl">Report/log files </a></dt>
112
    [% IF CAN_user_tools_access_files %]
113
    <dt><a href="/cgi-bin/koha/tools/access_files.pl">Report/log files</a></dt>
113
    <dd>Report/log files</dd>
114
    <dd>Report/log files</dd>
115
    [% END %]
114
116
115
</dl>
117
</dl>
116
</div>
118
</div>
(-)a/reports/report_files.pl (-108 lines)
Lines 1-107 Link Here
1
#!/usr/bin/perl
2
3
# Frédérick Capovilla, 2011 - Libéo
4
#
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
7
# "reports" permission.
8
#
9
# This file is part of Koha.
10
#
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
13
# Foundation; either version 3 of the License, or (at your option) any later
14
# version.
15
#
16
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
17
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
18
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License along
21
# with Koha; if not, write to the Free Software Foundation, Inc.,
22
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24
use strict;
25
use warnings;
26
use C4::Auth;
27
use CGI;
28
use C4::Context;
29
use C4::Output;
30
use C4::Koha;
31
use File::stat;
32
use Digest::MD5 qw(md5_hex);
33
34
my $input = new CGI;
35
my $file_id = $input->param("id");
36
my $accessdir = C4::Context->config('accessdir');
37
my @directories = $accessdir ? (ref $accessdir ? @{$accessdir} : ($accessdir)) : ();
38
39
my ($template, $borrowernumber, $cookie)
40
    = get_template_and_user({template_name => "reports/report_files.tt",
41
                query => $input,
42
                type => "intranet",
43
                authnotrequired => 0,
44
                flagsrequired => {reports => '*'},
45
                });
46
47
unless(@directories) {
48
    $template->param(error_no_dir => 1);
49
}
50
else {
51
    #Get the files list
52
    my @files_list;
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);
59
60
            my $st = stat($full_path);
61
            my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =localtime($st->mtime);
62
            my $dt=DateTime->new(year      => $year + 1900,
63
                                  month    => $mon + 1,
64
                                  day      => $mday,
65
                                  hour     => $hour,
66
                                  minute   => $min,
67
                            );
68
            push(@files_list, {name => $filename,
69
                               accessdir => $dir,
70
                               date =>Koha::DateUtils::output_pref($dt),
71
                               size => $st->size,
72
                               id   => $id});
73
        }
74
        closedir(DIR);
75
    }
76
77
    my %files_hash = map { $_->{id} => $_ } @files_list;
78
    # If we received a file_id and it is valid, send the file to the browser
79
    if(defined $file_id and $file_id >= 0 and exists $files_hash{$file_id} ){
80
        my $filename = $files_hash{$file_id}->{name};
81
        my $dir = $files_hash{$file_id}->{accessdir};
82
        binmode STDOUT;
83
        # Open the selected file and send it to the browser
84
        print $input->header(-type => 'application/x-download',
85
                             -name => "$filename",
86
                             -Content_length => -s "$dir/$filename",
87
                             -attachment => "$filename");
88
89
        my $fh;
90
        open $fh, "<:encoding(UTF-8)", "$dir/$filename";
91
        binmode $fh;
92
93
        my $buf;
94
        while(read($fh, $buf, 65536)) {
95
            print $buf;
96
        }
97
        close $fh;
98
99
        exit(1);
100
    }
101
    else{
102
        # Send the file list to the template
103
        $template->param(files_loop => \@files_list);
104
    }
105
}
106
107
output_html_with_http_headers $input, $cookie, $template->output;
108
- 

Return to bug 11317