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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/report_files.tt (+62 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Report/log files</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
<script type="text/javascript" src="[% themelang %]/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
5
<script type="text/JavaScript" language="JavaScript">
6
	//<![CDATA[
7
		$(document).ready(function() {
8
    		$("#files").tablesorter({
9
    				widgets : ['zebra'],
10
                    headers: {2:{sorter: false}}
11
    			});
12
    	});
13
	//]]>
14
</script>
15
</head>
16
<body>
17
[% INCLUDE 'header.inc' %]
18
[% INCLUDE 'cat-search.inc' %]
19
20
<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>
21
22
<div id="doc3" class="yui-t2">
23
   <div id="bd">
24
	<div id="yui-main">
25
	<div class="yui-b">
26
27
	<h1>Report/log files</h1>
28
29
[% IF ( error_no_publiclogdir ) %]
30
    <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>
31
[% ELSE %]
32
    [% IF ( files_loop ) %]
33
        <table id="files">
34
            <thead>
35
                <tr>
36
                    <th>Name</th>
37
                    <th>Size (bytes)</th>
38
                    <th>Date last modified</th>
39
                </tr>
40
            </thead>
41
            <tbody>
42
                [% FOREACH file IN files_loop %]
43
                <tr>
44
                    <td><a href="/cgi-bin/koha/reports/report_files.pl?id=[% file.id |url %]">[% file.name %]</a></td>
45
                    <td align="right">[% file.size %]</td>
46
                    <td>[% file.date %]</td>
47
                </tr>
48
                [% END %]
49
            </tbody>
50
        </table>
51
    [% ELSE %]
52
        No file found.
53
    [% END %]
54
[% END %]
55
56
</div>
57
</div>
58
<div class="yui-b">
59
[% INCLUDE 'reports-menu.inc' %]
60
</div>
61
</div>
62
[% 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