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

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

Return to bug 9915