4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
35 plugin that shows a stats on borrowers
44 my $branches = GetBranches();
45 my $itemtypes = GetItemTypes();
47 my ($template, $borrowernumber, $cookie)
48 = get_template_and_user({template_name => 'opac-topissues.tmpl',
54 my $dbh = C4::Context->dbh;
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;
61 $whereclause .= ' AND items.homebranch='.$dbh->quote($branch) if ($branch);
62 $whereclause .= ' AND TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30) if $timeLimit < 999;
63 $whereclause =~ s/ AND $//;
65 if(C4::Context->preference('AdvancedSearchTypes') eq 'ccode'){
66 $whereclause .= ' AND authorised_values.authorised_value='.$dbh->quote($itemtype) if $itemtype;
67 $query = "SELECT datecreated, biblio.biblionumber, title,
68 author, sum( items.issues ) AS tot, biblioitems.itemtype,
69 biblioitems.publishercode,biblioitems.publicationyear,
70 authorised_values.lib as description
72 LEFT JOIN items USING (biblionumber)
73 LEFT JOIN biblioitems USING (biblionumber)
74 LEFT JOIN authorised_values ON items.ccode = authorised_values.authorised_value
77 AND authorised_values.category = 'ccode'
78 GROUP BY biblio.biblionumber
84 $whereclause .= ' AND biblioitems.itemtype='.$dbh->quote($itemtype) if $itemtype;
85 $query = "SELECT datecreated, biblio.biblionumber, title,
86 author, sum( items.issues ) AS tot, biblioitems.itemtype,
87 biblioitems.publishercode,biblioitems.publicationyear,
90 LEFT JOIN items USING (biblionumber)
91 LEFT JOIN biblioitems USING (biblionumber)
92 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
95 GROUP BY biblio.biblionumber
101 my $sth = $dbh->prepare($query);
104 while (my $line= $sth->fetchrow_hashref) {
105 push @results, $line;
108 my $timeLimitFinite = $timeLimit;
109 if($timeLimit eq 999){ $timeLimitFinite = 0 };
111 $template->param(do_it => 1,
113 branch => $branches->{$branch}->{branchname} || 'all locations',
114 itemtype => $itemtypes->{$itemtype}->{description} || 'item types',
115 timeLimit => $timeLimit,
116 timeLimitFinite => $timeLimit,
117 results_loop => \@results,
120 # load the branches ## again??
121 $branches = GetBranches();
123 for my $branch_hash (sort keys %$branches ) {
124 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
127 value => "$branch_hash",
128 branchname => $branches->{$branch_hash}->{'branchname'},
129 selected => $selected
132 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
135 $itemtypes = GetItemTypes;
137 foreach my $thisitemtype (sort {$itemtypes->{$a}->{'description'} cmp $itemtypes->{$b}->{'description'}} keys %$itemtypes) {
138 my $selected = 1 if $thisitemtype eq $itemtype;
139 my %row =(value => $thisitemtype,
140 description => $itemtypes->{$thisitemtype}->{'description'},
141 selected => $selected,
143 push @itemtypeloop, \%row;
147 itemtypeloop =>\@itemtypeloop,
148 dateformat => C4::Context->preference("dateformat"),
150 output_html_with_http_headers $input, $cookie, $template->output;