Removing connexion informations from basket page.
[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 =over 2
39
40 =cut
41
42 my $input = new CGI;
43 my $branches = GetBranches();
44 my $itemtypes = GetItemTypes();
45
46 my ($template, $borrowernumber, $cookie)
47         = get_template_and_user({template_name => 'opac-topissues.tmpl',
48                                 query => $input,
49                                 type => "opac",
50                                 authnotrequired => 1,
51                                 debug => 1,
52                                 });
53 my $dbh = C4::Context->dbh;
54 # Displaying results
55 my $limit = $input->param('limit') || 10;
56 my $branch = $input->param('branch');
57 my $itemtype = $input->param('itemtype');
58 my $timeLimit = $input->param('timeLimit') || 3;
59 my $whereclause;
60 $whereclause .= 'items.homebranch='.$dbh->quote($branch)." AND " if ($branch); 
61 $whereclause .= 'biblioitems.itemtype='.$dbh->quote($itemtype)." AND " if $itemtype;
62 $whereclause .= 'TO_DAYS(NOW()) - TO_DAYS(biblio.datecreated) <= '.$timeLimit*30 if $timeLimit < 999;
63 $whereclause =~ s/ AND $//;
64 $whereclause = " WHERE ".$whereclause if $whereclause;
65
66 my $query = "SELECT datecreated, 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                 HAVING tot >0
77                 ORDER BY tot DESC
78                 LIMIT $limit
79                 ";
80
81 my $sth = $dbh->prepare($query);
82 $sth->execute();
83 my @results;
84 while (my $line= $sth->fetchrow_hashref) {
85     push @results, $line;
86 }
87
88 $template->param(do_it => 1,
89                 limit => $limit,
90                 branch => $branches->{$branch}->{branchname},
91                 itemtype => $itemtypes->{$itemtype}->{description},
92                 timeLimit => $timeLimit,
93                 results_loop => \@results,
94                 );
95
96 # load the branches
97 my $branches = GetBranches();
98 my @branch_loop;
99 for my $branch_hash (sort keys %$branches ) {
100     my $selected=(C4::Context->userenv && ($branch_hash eq C4::Context->userenv->{branch})) if (C4::Context->preference('SearchMyLibraryFirst'));
101     push @branch_loop,
102       {
103         value      => "branch: $branch_hash",
104         branchname => $branches->{$branch_hash}->{'branchname'},
105         selected => $selected
106       };
107 }
108 $template->param( branchloop => \@branch_loop, "mylibraryfirst"=>C4::Context->preference("SearchMyLibraryFirst"));
109
110 #doctype
111 my $itemtypes = GetItemTypes;
112 my @itemtypeloop;
113 foreach my $thisitemtype (keys %$itemtypes) {
114         my %row =(value => $thisitemtype,
115                     description => $itemtypes->{$thisitemtype}->{'description'},
116                         );
117         push @itemtypeloop, \%row;
118 }
119
120 $template->param(
121                  itemtypeloop =>\@itemtypeloop,
122                 );
123 output_html_with_http_headers $input, $cookie, $template->output;
124