Bug 11174: fix OPAC search links built from authority 5xx fields
[koha.git] / svc / report
blob654ef1572b76c231badabfc1e1c782510734bee6
1 #!/usr/bin/perl
3 # Copyright 2011 Chris Cormack <chris@bigballofwax.co.nz>
5 # This file is part of Koha.
7 # 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 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
21 use strict;
22 use warnings;
24 use C4::Auth;
25 use C4::Reports::Guided;
26 use JSON;
27 use CGI;
29 use Koha::Cache;
32 my $query = CGI->new();
33 my $report_id = $query->param('id');
34 my $report_name = $query->param('name');
36 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
38 template_name => "intranet-main.tmpl",
39 query => $query,
40 type => "intranet",
41 authnotrequired => 0,
42 flagsrequired => { catalogue => 1, },
46 my $cache_active = Koha::Cache->is_cache_active;
47 my ($cache_key, $cache, $json_text);
48 if ($cache_active) {
49 $cache_key = "intranet:report:".($report_name ? "name:$report_name" : "id:$report_id");
50 $cache = Koha::Cache->new();
51 $json_text = $cache->get_from_cache($cache_key);
54 unless ($json_text) {
55 my $report_rec = get_saved_report($report_name ? { 'name' => $report_name } : { 'id' => $report_id });
56 my $offset = 0;
57 my $limit = C4::Context->preference("SvcMaxReportRows") || 10;
58 my ( $sth, $errors ) = execute_query( $report_rec->{savedsql}, $offset, $limit );
59 if ($sth) {
60 my $lines = $sth->fetchall_arrayref;
61 $json_text = to_json($lines);
63 if ($cache_active) {
64 $cache->set_in_cache( $cache_key, $json_text, $report_rec->{cache_expiry} );
67 else {
68 $json_text = to_json($errors);
72 print $query->header;
73 print $json_text;