5 # Copyright 2000-2002 Katipo Communications
7 # This file is part of Koha.
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
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.
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
30 use C4::Interface::CGI::Output;
35 plugin that shows a stats on borrowers
45 my $branches = GetBranches();
46 my $itemtypes = GetItemTypes();
48 my ($template, $borrowernumber, $cookie)
49 = get_template_and_user({template_name => 'opac-topissues.tmpl',
55 my $dbh = C4::Context->dbh;
57 my $limit = $input->param('limit') || 10;
58 my $branch = $input->param('branch');
59 my $itemtype = $input->param('itemtype');
60 my $timeLimit = $input->param('timeLimit') || 3;
62 $whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch);
63 $whereclause .= 'biblioitems.itemtype='.$dbh->quote($itemtype)." AND " if $itemtype;
64 $whereclause .= 'TO_DAYS(NOW()) - TO_DAYS(biblio.timestamp) <= '.$timeLimit*30 if $timeLimit;
65 $whereclause =~ s/ AND $//;
66 $whereclause = " WHERE ".$whereclause if $whereclause;
67 my $query = "SELECT biblio.timestamp, biblio.biblionumber, title,
68 author, sum( items.issues ) AS tot, biblioitems.itemtype,
69 biblioitems.publishercode,biblioitems.publicationyear,
72 LEFT JOIN items USING (biblionumber)
73 LEFT JOIN biblioitems USING (biblionumber)
74 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
76 GROUP BY biblio.biblionumber
81 my $sth = $dbh->prepare($query);
84 while (my $line= $sth->fetchrow_hashref) {
88 $template->param(do_it => 1,
90 branch => $branches->{$branch}->{branchname},
91 itemtype => $itemtypes->{$itemtype}->{description},
92 timeLimit => $timeLimit,
93 results_loop => \@results,
96 my $branches = GetBranches;
98 foreach my $thisbranch (keys %$branches) {
99 my %row =(value => $thisbranch,
100 branchname => $branches->{$thisbranch}->{'branchname'},
102 push @branchloop, \%row;
106 my $itemtypes = GetItemTypes;
108 foreach my $thisitemtype (keys %$itemtypes) {
109 my %row =(value => $thisitemtype,
110 description => $itemtypes->{$thisitemtype}->{'description'},
112 push @itemtypeloop, \%row;
116 branchloop =>\@branchloop,
117 itemtypeloop =>\@itemtypeloop,
119 output_html_with_http_headers $input, $cookie, $template->output;