Mod C4::Labels::add_batch to accept an array of items.
[koha.git] / opac / opac-topissues.pl
blobf47c138cefbc9be14179dd2fe1d79b810a514c0b
1 #!/usr/bin/perl
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
11 # version.
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
21 use strict;
22 use CGI;
23 use C4::Auth;
24 use C4::Context;
25 use C4::Search;
26 use C4::Output;
27 use C4::Koha;
28 use C4::Branch;
29 use Date::Manip;
31 =head1 NAME
33 plugin that shows a stats on borrowers
35 =head1 DESCRIPTION
37 =over 2
39 =cut
41 my $input = new CGI;
42 my $branches = GetBranches();
43 my $itemtypes = GetItemTypes();
45 my ($template, $borrowernumber, $cookie)
46 = get_template_and_user({template_name => 'opac-topissues.tmpl',
47 query => $input,
48 type => "opac",
49 authnotrequired => 1,
50 debug => 1,
51 });
52 my $dbh = C4::Context->dbh;
53 # Displaying results
54 my $limit = $input->param('limit') || 10;
55 my $branch = $input->param('branch');
56 my $itemtype = $input->param('itemtype');
57 my $timeLimit = $input->param('timeLimit') || 3;
58 my $whereclause;
59 $whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch);
60 $whereclause .= 'biblioitems.itemtype='.$dbh->quote($itemtype)." AND " if $itemtype;
61 $whereclause .= ' TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.($timeLimit*30).' AND ' if $timeLimit < 999;
62 $whereclause =~ s/ AND $//;
63 $whereclause = " WHERE ".$whereclause if $whereclause;
65 my $query = "SELECT datecreated, biblio.biblionumber, title,
66 author, sum( items.issues ) AS tot, biblioitems.itemtype,
67 biblioitems.publishercode,biblioitems.publicationyear,
68 itemtypes.description
69 FROM biblio
70 LEFT JOIN items USING (biblionumber)
71 LEFT JOIN biblioitems USING (biblionumber)
72 LEFT JOIN itemtypes ON itemtypes.itemtype = biblioitems.itemtype
73 $whereclause
74 GROUP BY biblio.biblionumber
75 HAVING tot >0
76 ORDER BY tot DESC
77 LIMIT $limit
80 my $sth = $dbh->prepare($query);
81 $sth->execute();
82 my @results;
83 while (my $line= $sth->fetchrow_hashref) {
84 push @results, $line;
87 if($timeLimit eq 999){ $timeLimit = 0 };
89 $template->param(do_it => 1,
90 limit => $limit,
91 branch => $branches->{$branch}->{branchname},
92 itemtype => $itemtypes->{$itemtype}->{description},
93 timeLimit => $timeLimit,
94 results_loop => \@results,
97 # load the branches ## again??
98 $branches = GetBranches();
99 my @branch_loop;
100 for my $branch_hash (sort keys %$branches ) {
101 my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
102 push @branch_loop,
104 value => "$branch_hash",
105 branchname => $branches->{$branch_hash}->{'branchname'},
106 selected => $selected
109 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
111 #doctype
112 $itemtypes = GetItemTypes;
113 my @itemtypeloop;
114 foreach my $thisitemtype (keys %$itemtypes) {
115 my %row =(value => $thisitemtype,
116 description => $itemtypes->{$thisitemtype}->{'description'},
118 push @itemtypeloop, \%row;
121 $template->param(
122 itemtypeloop =>\@itemtypeloop,
124 output_html_with_http_headers $input, $cookie, $template->output;