fix indentation.
[koha.git] / reports / itemtypes.plugin
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 C4::Auth;
24 use CGI;
25 use C4::Context;
26 use HTML::Template::Pro;
27 use C4::Search;
28 use C4::Output;
29 use C4::Koha;
30 use C4::Branch; # GetBranches
31 =head1
32
33 =cut
34
35 sub set_parameters {
36         my ($template) = @_;
37         my $dbh = C4::Context->dbh;
38         my $branches=GetBranches();
39         my @branches;
40         my @select_branch;
41         my %select_branches;
42         push @select_branch,"";
43         $select_branches{""} = "";
44         foreach my $branch (keys %$branches) {
45                 push @select_branch, $branch;
46                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
47         }
48         my $CGIbranch=CGI::scrolling_list( -name     => 'value',
49                                 -id => 'value',
50                                 -values   => \@select_branch,
51                                 -labels   => \%select_branches,
52                                 -size     => 1,
53                                 -multiple => 0 );
54         $template->param(CGIbranch => $CGIbranch);
55         return $template;
56 }
57 sub calculate {
58         my ($parameters) = @_;
59         my @results =();
60         my $branch = @$parameters[0];
61         my $dbh = C4::Context->dbh;
62         my $sth;
63         if ($branch) {
64                 $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems, items 
65                                                 where biblioitems.itemtype=itemtypes.itemtype 
66                                                         and items.biblioitemnumber=biblioitems.biblioitemnumber
67                                                         and items.holdingbranch=?
68                                                 group by biblioitems.itemtype");
69                 $sth->execute($branch);
70         } else {
71                 $sth = $dbh->prepare("select description, biblioitems.itemtype, count(*) as total from itemtypes, biblioitems,items where biblioitems.itemtype=itemtypes.itemtype 
72                                       and biblioitems.biblioitemnumber = items.biblioitemnumber group by biblioitems.itemtype");
73                 $sth->execute;
74         }
75         my ($description,$biblioitems,$total);
76         my $grantotal = 0;
77         my $count = 0;
78         while (($description,$biblioitems,$total) = $sth->fetchrow) {
79                 my %line;
80                 if($count % 2){
81                         $line{toggle} = 1;
82                         } else {
83                                 $line{toggle} = 0;
84                         }
85                 $line{itemtype} = $description;
86                 $line{count} = $total;
87                 $grantotal += $total;
88                 push @results,\%line;
89                 $count ++;
90         }
91         my @mainloop;
92         my %globalline;
93         $globalline{loopitemtype} = \@results;
94         $globalline{total} = $grantotal;
95         $globalline{branch} = $branch;
96         push @mainloop,\%globalline;
97         return \@mainloop;
98 }
99
100 1;