Bug 13669: Re-adds error handling to load_sql
[koha.git] / opac / opac-topissues.pl
blob1bb4d2d3cdfadc96a3409cc78024db7a64dad8f4
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
5 # Parts Copyright Catalyst IT 2011
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use strict;
23 use warnings;
25 use CGI qw ( -utf8 );
26 use C4::Auth;
27 use C4::Context;
28 use C4::Languages;
29 use C4::Search;
30 use C4::Output;
31 use C4::Koha;
32 use C4::Branch;
33 use C4::Circulation;
34 use Date::Manip;
36 =head1 NAME
38 plugin that shows a stats on borrowers
40 =head1 DESCRIPTION
42 =cut
44 my $input = new CGI;
46 # if OpacTopissue is disabled, leave immediately
47 if ( ! C4::Context->preference('OpacTopissue') ) {
48 print $input->redirect("/cgi-bin/koha/errors/404.pl");
49 exit;
52 my $branches = GetBranches();
53 my $itemtypes = GetItemTypes();
55 my ($template, $borrowernumber, $cookie) = get_template_and_user(
57 template_name => 'opac-topissues.tt',
58 query => $input,
59 type => "opac",
60 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
61 debug => 1,
64 my $dbh = C4::Context->dbh;
65 # Displaying results
66 my $do_it = $input->param('do_it') || 0; # as form been posted
67 my $limit = $input->param('limit');
68 $limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query
69 $limit = 100 if $limit > 100;
70 my $branch = $input->param('branch') || '';
71 if (!$do_it && C4::Context->userenv && C4::Context->userenv->{'branch'} ) {
72 $branch = C4::Context->userenv->{'branch'}; # select user branch by default
74 my $itemtype = $input->param('itemtype') || '';
75 my $timeLimit = $input->param('timeLimit') || 3;
76 my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
77 my @advanced_search_types = split /\|/, $advanced_search_types;
79 my $params = {
80 count => $limit,
81 branch => $branch,
82 newness => $timeLimit < 999 ? $timeLimit * 30 : undef,
85 @advanced_search_types = grep /^(ccode|itemtypes)$/, @advanced_search_types;
86 foreach my $type (@advanced_search_types) {
87 if ($type eq 'itemtypes') {
88 $type = 'itemtype';
90 $params->{$type} = $input->param($type);
91 $template->param('selected_' . $type => scalar $input->param($type));
94 my @results = GetTopIssues($params);
96 $template->param(
97 limit => $limit,
98 branch => $branches->{$branch}->{branchname},
99 timeLimit => $timeLimit,
100 results => \@results,
103 $template->param(branchloop => GetBranchesLoop($branch));
105 output_html_with_http_headers $input, $cookie, $template->output;