Bug 5770: (QA follow-up) Adapt for replyto handling
[koha.git] / opac / opac-topissues.pl
blobfbf0081a38361d4ca2eea0100345e278c9d9e3c0
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 Modern::Perl;
24 use CGI qw ( -utf8 );
25 use C4::Auth;
26 use C4::Context;
27 use C4::Languages;
28 use C4::Search;
29 use C4::Output;
30 use C4::Koha;
31 use C4::Circulation;
32 use Date::Manip;
34 =head1 NAME
36 plugin that shows a stats on borrowers
38 =head1 DESCRIPTION
40 =cut
42 my $input = new CGI;
44 # if OpacTopissue is disabled, leave immediately
45 if ( ! C4::Context->preference('OpacTopissue') ) {
46 print $input->redirect("/cgi-bin/koha/errors/404.pl");
47 exit;
50 my ($template, $borrowernumber, $cookie) = get_template_and_user(
52 template_name => 'opac-topissues.tt',
53 query => $input,
54 type => "opac",
55 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
56 debug => 1,
59 my $dbh = C4::Context->dbh;
60 # Displaying results
61 my $do_it = $input->param('do_it') || 0; # as form been posted
62 my $limit = $input->param('limit');
63 $limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query
64 $limit = 100 if $limit > 100;
65 my $branch = $input->param('branch') || '';
66 if (!$do_it && C4::Context->userenv && C4::Context->userenv->{'branch'} ) {
67 $branch = C4::Context->userenv->{'branch'}; # select user branch by default
69 my $itemtype = $input->param('itemtype') || '';
70 my $timeLimit = $input->param('timeLimit') || 3;
71 my $advanced_search_types = C4::Context->preference('AdvancedSearchTypes');
72 my @advanced_search_types = split /\|/, $advanced_search_types;
74 my $params = {
75 count => $limit,
76 branch => $branch,
77 newness => $timeLimit < 999 ? $timeLimit * 30 : undef,
80 @advanced_search_types = grep /^(ccode|itemtypes)$/, @advanced_search_types;
81 foreach my $type (@advanced_search_types) {
82 if ($type eq 'itemtypes') {
83 $type = 'itemtype';
85 $params->{$type} = $input->param($type);
86 $template->param('selected_' . $type => scalar $input->param($type));
89 my @results = GetTopIssues($params);
91 $template->param(
92 limit => $limit,
93 branch => $branch,
94 timeLimit => $timeLimit,
95 results => \@results,
98 output_html_with_http_headers $input, $cookie, $template->output;