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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt (+68 lines)
Line 0 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
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
[% INCLUDE 'datatables-strings.inc' %]
7
<script type="text/javascript" src="[% themelang %]/js/datatables.js"></script>
8
<script type="text/JavaScript" language="JavaScript">
9
	//<![CDATA[
10
		$(document).ready(function() {
11
            $("#files").dataTable($.extend(true, {}, dataTablesDefaults, {
12
                "sDom": 't',
13
                "aoColumnDefs": [
14
                    { "aTargets": [ -1 ], "bSortable": false, "bSearchable": false }
15
                ],
16
                "bPaginate": false
17
            }));
18
	});
19
	//]]>
20
</script>
21
</head>
22
<body>
23
[% INCLUDE 'header.inc' %]
24
[% INCLUDE 'cat-search.inc' %]
25
26
<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>
27
28
<div id="doc3" class="yui-t2">
29
   <div id="bd">
30
	<div id="yui-main">
31
	<div class="yui-b">
32
33
	<h1>Report/log files</h1>
34
35
[% IF ( error_no_publiclogdir ) %]
36
    <div class="dialog alert"><strong>Error : </strong>Report/log files could not be found because the "publiclogdir" option was not set in "koha-conf.xml". Contact your system administrator to add this option.</div>
37
[% ELSE %]
38
    [% IF ( files_loop ) %]
39
        <table id="files">
40
            <thead>
41
                <tr>
42
                    <th>Name</th>
43
                    <th>Size (bytes)</th>
44
                    <th>Date last modified</th>
45
                </tr>
46
            </thead>
47
            <tbody>
48
                [% FOREACH file IN files_loop %]
49
                <tr>
50
                    <td><a href="/cgi-bin/koha/reports/report_files.pl?id=[% file.id |url %]">[% file.name %]</a></td>
51
                    <td align="right">[% file.size %]</td>
52
                    <td>[% file.date %]</td>
53
                </tr>
54
                [% END %]
55
            </tbody>
56
        </table>
57
    [% ELSE %]
58
        No file found.
59
    [% END %]
60
[% END %]
61
62
</div>
63
</div>
64
<div class="yui-b">
65
[% INCLUDE 'reports-menu.inc' %]
66
</div>
67
</div>
68
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/reports-home.tt (+1 lines)
Lines 66-71 Link Here
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
66
        <li><a href="http://schema.koha-community.org/" target="blank">Koha database schema</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
67
        <li><a href="http://wiki.koha-community.org/wiki/SQL_Reports_Library" target="blank">Koha reports library</a></li>
68
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
68
        <!--<li><a href="/cgi-bin/koha/reports/stats.screen.pl">Till reconciliation</a></li> -->
69
        <li><a href="/cgi-bin/koha/reports/report_files.pl">Report/log files</a></li>
69
	</ul></div>
70
	</ul></div>
70
</div>
71
</div>
71
72
(-)a/reports/report_files.pl (-1 / +94 lines)
Line 0 Link Here
0
- 
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
# "publiclogdir" 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 2 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
33
my $input      = new CGI;
34
my $file_id = $input->param("id");
35
my $directory = C4::Context->config('publiclogdir');
36
37
my ($template, $borrowernumber, $cookie)
38
	= get_template_and_user({template_name => "reports/report_files.tt",
39
				query => $input,
40
				type => "intranet",
41
				authnotrequired => 0,
42
				flagsrequired => {reports => '*'},
43
				});
44
45
unless($directory) {
46
    $template->param(error_no_publiclogdir => 1);
47
}
48
else {
49
    #Get the files list
50
    my @files_list;
51
	opendir(DIR, $directory);
52
53
    my $i=0;
54
    foreach my $filename (readdir(DIR)) {
55
        my $full_path = "$directory/$filename";
56
        next if ($filename =~ /^\./ or -d $full_path);
57
58
        my $st = stat($full_path);
59
        push(@files_list, {name => $filename,
60
                           date => scalar localtime($st->mtime),
61
                           size => $st->size,
62
                           id   => $i});
63
        $i++;
64
    }
65
    closedir(DIR);
66
67
    # If we received a file_id and it is valid, send the file to the browser
68
    if(defined $file_id and $file_id >= 0 and $file_id < scalar @files_list){
69
        my $filename = $files_list[$file_id]->{name};
70
        binmode STDOUT;
71
        # Open the selected file and send it to the browser
72
        print $input->header(-type => 'application/x-download',
73
                             -name => "$filename",
74
                             -Content_length => -s "$directory/$filename",
75
                             -attachment => "$filename");
76
77
        open FILE, "<:utf8", "$directory/$filename";
78
        binmode FILE;
79
80
        my $buf;
81
        while(read(FILE, $buf, 65536)) {
82
            print $buf;
83
        }
84
        close FILE;
85
86
        exit(1);
87
    }
88
    else{
89
        # Send the file list to the template
90
        $template->param(files_loop => \@files_list);
91
    }
92
}
93
94
output_html_with_http_headers $input, $cookie, $template->output;

Return to bug 11317