Adding hierarchy for hierarchy showing in opac-authoritiesdetail.pl
[koha.git] / opac / opac-topissues.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use CGI;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Search;
27 use C4::Output;
28 use C4::Koha;
29 use C4::Branch;
30 use Date::Manip;
31
32 =head1 NAME
33
34 plugin that shows a stats on borrowers
35
36 =head1 DESCRIPTION
37
38
39 =over2
40
41 =cut
42
43 my $input = new CGI;
44 my $branches = GetBranches();
45 my $itemtypes = GetItemTypes();
46
47 my ($template, $borrowernumber, $cookie)
48         = get_template_and_user({template_name => 'opac-topissues.tmpl',
49                                 query => $input,
50                                 type => "opac",
51                                 authnotrequired => 1,
52                                 debug => 1,
53                                 });
54 my $dbh = C4::Context->dbh;
55 # Displaying results
56 my $limit = $input->param('limit') || 10;
57 my $branch = $input->param('branch');
58 my $itemtype = $input->param('itemtype');
59 my $timeLimit = $input->param('timeLimit') || 3;
60 my $whereclause;
61 $whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch); 
62 $whereclause .= 'biblioitems.itemtype='.$dbh->quote($itemtype)." AND " if $itemtype;
63 $whereclause .= 'TO_DAYS(NOW()) - TO_DAYS(biblio.timestamp) <= '.$timeLimit*30 if $timeLimit;
64 $whereclause =~ s/ AND $//;
65 $whereclause = " WHERE ".$whereclause if $whereclause;
66 my $query = "SELECT biblio.timestamp, biblio.biblionumber, title, 
67                 author, sum( items.issues ) AS tot, biblioitems.itemtype,
68                 biblioitems.publishercode,biblioitems.publicationyear,
69                 itemtypes.description
70                 FROM biblio
71                 LEFT JOIN items USING (biblionumber)
72                 LEFT JOIN biblioitems USING (biblionumber)
73                 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
74                 $whereclause
75                 GROUP BY biblio.biblionumber
76                 ORDER BY tot DESC
77                 LIMIT $limit
78                 ";
79
80 my $sth = $dbh->prepare($query);
81 $sth->execute();
82 my @results;
83 while (my $line= $sth->fetchrow_hashref) {
84     push @results, $line;
85 }
86
87 $template->param(do_it => 1,
88                 limit => $limit,
89                 branch => $branches->{$branch}->{branchname},
90                 itemtype => $itemtypes->{$itemtype}->{description},
91                 timeLimit => $timeLimit,
92                 results_loop => \@results,
93                 );
94
95 my $branches = GetBranches;
96 my @branchloop;
97 foreach my $thisbranch (keys %$branches) {
98         my %row =(value => $thisbranch,
99                     branchname => $branches->{$thisbranch}->{'branchname'},
100                         );
101         push @branchloop, \%row;
102 }
103
104 #doctype
105 my $itemtypes = GetItemTypes;
106 my @itemtypeloop;
107 foreach my $thisitemtype (keys %$itemtypes) {
108         my %row =(value => $thisitemtype,
109                     description => $itemtypes->{$thisitemtype}->{'description'},
110                         );
111         push @itemtypeloop, \%row;
112 }
113
114 $template->param(
115                 branchloop =>\@branchloop,
116                 itemtypeloop =>\@itemtypeloop,
117                 );
118 output_html_with_http_headers $input, $cookie, $template->output;
119