Bug 30477: Add new UNIMARC installer translation files
[koha.git] / opac / opac-topissues.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 # Parts Copyright Catalyst IT 2011
6 #
7 # This file is part of Koha.
8 #
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.
13 #
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.
18 #
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>.
21
22 use Modern::Perl;
23
24 use CGI qw ( -utf8 );
25 use C4::Auth qw( get_template_and_user );
26 use C4::Context;
27 use C4::Search;
28 use C4::Output qw( output_html_with_http_headers );
29 use C4::Circulation qw( GetTopIssues );
30
31 =head1 NAME
32
33 plugin that shows a stats on borrowers
34
35 =head1 DESCRIPTION
36
37 =cut
38
39 my $input = CGI->new;
40
41 # if OpacTopissue is disabled, leave immediately
42 if ( ! C4::Context->preference('OpacTopissue') ) {
43     print $input->redirect("/cgi-bin/koha/errors/404.pl");
44     exit;
45 }
46
47 my ($template, $borrowernumber, $cookie) = get_template_and_user(
48     {
49         template_name   => 'opac-topissues.tt',
50         query           => $input,
51         type            => "opac",
52         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
53     }
54 );
55 my $dbh = C4::Context->dbh;
56 # Displaying results
57 my $do_it = $input->param('do_it') || 0; # as form been posted
58 my $limit = $input->param('limit');
59 $limit = 10 unless ($limit && $limit =~ /^\d+$/); # control user input for SQL query
60 $limit = 100 if $limit > 100;
61 my $branch = $input->param('branch') || '';
62 if (!$do_it && C4::Context->userenv && C4::Context->userenv->{'branch'} ) {
63     $branch = C4::Context->userenv->{'branch'}; # select user branch by default
64 }
65 my $itemtype = $input->param('itemtype') || '';
66 my $timeLimit = $input->param('timeLimit') || 3;
67 my $advanced_search_types = C4::Context->preference('OpacAdvancedSearchTypes');
68 my @advanced_search_types = split /\|/, $advanced_search_types;
69
70 my $params = {
71     count => $limit,
72     branch => $branch,
73     newness => $timeLimit < 999 ? $timeLimit * 30 : undef,
74 };
75
76 @advanced_search_types = grep /^(ccode|itemtypes)$/, @advanced_search_types;
77 foreach my $type (@advanced_search_types) {
78     if ($type eq 'itemtypes') {
79         $type = 'itemtype';
80     }
81     $params->{$type} = $input->param($type);
82     $template->param('selected_' . $type => scalar $input->param($type));
83 }
84
85 my @results = GetTopIssues($params);
86
87 $template->param(
88     limit => $limit,
89     branch => $branch,
90     timeLimit => $timeLimit,
91     results => \@results,
92 );
93
94 output_html_with_http_headers $input, $cookie, $template->output;