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

(-)a/opac/svc/report (-14 / +33 lines)
Lines 1-12 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
2
3
# Copyright 2011 Chris Cormack <chris@bigballofwax.co.nz>
3
# Copyright 2011 Chris Cormack <chris@bigballofwax.co.nz>
4
# Updated 2013 by Chris Cormack <chris@bigballofwax.co.nz>
4
#
5
#
5
# This file is part of Koha.
6
# This file is part of Koha.
6
#
7
#
7
# Koha is free software; you can redistribute it and/or modify it under the
8
# Koha is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU General Public License as published by the Free Software
9
# terms of the GNU General Public License as published by the Free Software
9
# Foundation; either version 2 of the License, or (at your option) any later
10
# Foundation; either version 3 of the License, or (at your option) any later
10
# version.
11
# version.
11
#
12
#
12
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
Lines 17-23 Link Here
17
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20
20
21
use strict;
21
use strict;
22
use warnings;
22
use warnings;
23
23
Lines 27-58 use CGI; Link Here
27
27
28
use Koha::Cache;
28
use Koha::Cache;
29
29
30
my $query  = CGI->new();
30
my $query       = CGI->new();
31
my $report_id = $query->param('id');
31
my $report_id   = $query->param('id');
32
my $report_name = $query->param('name');
32
my $report_name = $query->param('name');
33
my @sql_params  = $query->param('sql_params');
33
34
34
my $report_rec = get_saved_report( $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
35
my $report_rec = get_saved_report(
36
    $report_name ? { 'name' => $report_name } : { 'id' => $report_id } );
35
die "Sorry this report is not public\n" unless $report_rec->{public};
37
die "Sorry this report is not public\n" unless $report_rec->{public};
36
38
37
38
my $cache_active = Koha::Cache->is_cache_active;
39
my $cache_active = Koha::Cache->is_cache_active;
39
my ($cache_key, $cache, $json_text);
40
my ( $cache_key, $cache, $json_text );
40
if ($cache_active) {
41
if ($cache_active) {
41
    $cache_key = "opac:report:".($report_name ? "name:$report_name" : "id:$report_id");
42
    $cache_key =
42
    $cache = Koha::Cache->new();
43
        "opac:report:"
44
      . ( $report_name ? "name:$report_name" : "id:$report_id" )
45
      . @sql_params;
46
    $cache     = Koha::Cache->new();
43
    $json_text = $cache->get_from_cache($cache_key);
47
    $json_text = $cache->get_from_cache($cache_key);
44
}
48
}
45
49
46
unless ($json_text) {
50
unless ($json_text) {
47
    my $offset = 0;
51
    my $offset = 0;
48
    my $limit  = C4::Context->preference("SvcMaxReportRows") || 10;
52
    my $limit = C4::Context->preference("SvcMaxReportRows") || 10;
49
    my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit );
53
    my $sql = $report_rec->{savedsql};
54
    if (@sql_params) {
55
56
        # we have sql params need to fix the sql
57
        my @split = split /<<|>>/, $sql;
58
        my @tmpl_parameters;
59
        for ( my $i = 0 ; $i < $#split / 2 ; $i++ ) {
60
            my $quoted = C4::Context->dbh->quote( $sql_params[$i] );
61
62
            # if there are special regexp chars, we must \ them
63
            $split[ $i * 2 + 1 ] =~ s/(\||\?|\.|\*|\(|\)|\%)/\\$1/g;
64
            $sql =~ s/<<$split[$i*2+1]>>/$quoted/;
65
        }
66
    }
67
    my ( $sth, $errors ) =
68
      execute_query( $sql, $offset, $limit );
50
    if ($sth) {
69
    if ($sth) {
51
        my $lines     = $sth->fetchall_arrayref;
70
        my $lines = $sth->fetchall_arrayref;
52
        $json_text = to_json($lines);
71
        $json_text = to_json($lines);
53
72
54
        if ($cache_active) {
73
        if ($cache_active) {
55
            $cache->set_in_cache( $cache_key, $json_text, $report_rec->{cache_expiry} );
74
            $cache->set_in_cache( $cache_key, $json_text,
75
                $report_rec->{cache_expiry} );
56
        }
76
        }
57
    }
77
    }
58
    else {
78
    else {
59
- 

Return to bug 9915