installer: added (in some cases back) module deps
[koha_fer] / reports / catalogue_stats.pl
index a40d5c8..3ac0216 100755 (executable)
@@ -1,6 +1,5 @@
 #!/usr/bin/perl
 
-# $Id$
 
 # Copyright 2000-2002 Katipo Communications
 #
@@ -23,12 +22,10 @@ use strict;
 use C4::Auth;
 use CGI;
 use C4::Context;
-use HTML::Template;
-use C4::Search;
+use C4::Branch; # GetBranches
 use C4::Output;
 use C4::Koha;
-use C4::Interface::CGI::Output;
-use C4::Circulation::Circ2;
+use C4::Circulation;
 
 =head1 NAME
 
@@ -36,8 +33,7 @@ plugin that shows a stats on borrowers
 
 =head1 DESCRIPTION
 
-
-=over2
+=over 2
 
 =cut
 
@@ -60,7 +56,7 @@ my ($template, $borrowernumber, $cookie)
                                query => $input,
                                type => "intranet",
                                authnotrequired => 0,
-                               flagsrequired => {editcatalogue => 1},
+                               flagsrequired => {reports => 1},
                                debug => 1,
                                });
 $template->param(do_it => $do_it);
@@ -72,6 +68,7 @@ if ($do_it) {
                exit(1);
        } else {
                print $input->header(-type => 'application/vnd.sun.xml.calc',
+                                     -encoding    => 'utf-8',
                                                         -attachment=>"$basename.csv",
                                                         -name=>"$basename.csv" );
                my $cols = @$results[0]->{loopcol};
@@ -174,7 +171,7 @@ if ($do_it) {
 #      warn "highlightLOC ".$hglghtLOC;
        
        
-       $req = $dbh->prepare("select distinctrow itemtype from biblioitems order by itemtype");
+       $req = $dbh->prepare("select itemtype from itemtypes order by itemtype");
        $req->execute;
        undef @select;
        push @select,"";
@@ -202,7 +199,7 @@ if ($do_it) {
 
        undef @select;
        push @select,"";
-       my $branches=getbranches();
+       my $branches=GetBranches();
        my %select_branches;
        $select_branches{""} = "";
        foreach my $branch (keys %$branches) {
@@ -216,12 +213,15 @@ if ($do_it) {
                                -size     => 1,
                                -multiple => 0 );
        
-       $req = $dbh->prepare("select distinctrow holdingbranch from items order by holdingbranch");
+       $req = $dbh->prepare("select distinctrow location from items order by location");
        $req->execute;
        undef @select;
        push @select,"";
+       while (my ($value) =$req->fetchrow) {
+               push @select, $value;
+       }
        my $CGIlocation=CGI::scrolling_list( -name     => 'Filter',
-                               -id => 'holdingbranch',
+                               -id => 'location',
                                -values   => \@select,
                                -size     => 1,
                                -multiple => 0 );
@@ -267,7 +267,7 @@ if ($do_it) {
 #                                      CGIToPublicationYear => $CGIpublicationyear,
 #                                      CGIPublisher => $CGIpublisher,
                                        CGIBranch => $CGIbranch,
-                                       CGILocation => $CGIholdingbranch,
+                                       CGILocation => $CGIlocation,
                                        CGIextChoice => $CGIextChoice,
                                        CGIsepChoice => $CGIsepChoice
                                        );
@@ -332,8 +332,8 @@ sub calculate {
        $linefilter[0] = @$filters[7] if ($line =~ /publishercode/ ) ;
        $linefilter[0] = @$filters[8] if ($line =~ /publicationyear/ ) ;
        $linefilter[1] = @$filters[9] if ($line =~ /publicationyear/ ) ;
-       @linefilter[0] = @$filters[10] if ($line =~ /items.homebranch/ ) ;
-       @linefilter[0] = @$filters[11] if ($line =~ /items.holdingbranch/ ) ;
+       $linefilter[0] = @$filters[10] if ($line =~ /items.homebranch/ ) ;
+       $linefilter[0] = @$filters[11] if ($line =~ /items.location/ ) ;
 # 
        my @colfilter ;
        $colfilter[0] = @$filters[0] if ($column =~ /dewey/ )  ;
@@ -346,8 +346,8 @@ sub calculate {
        $colfilter[0] = @$filters[7] if ($column =~ /publishercode/ ) ;
        $colfilter[0] = @$filters[8] if ($column =~ /publicationyear/ ) ;
        $colfilter[1] = @$filters[9] if ($column =~ /publicationyear/ ) ;
-       @colfilter[0] = @$filters[10] if ($column =~ /items.homebranch/ ) ;
-       @colfilter[0] = @$filters[11] if ($column =~ /items.holdingbranch/ ) ;
+       $colfilter[0] = @$filters[10] if ($column =~ /items.homebranch/ ) ;
+       $colfilter[0] = @$filters[11] if ($column =~ /items.location/ ) ;
 
 # 1st, loop rows.
        my $linefield;
@@ -506,11 +506,7 @@ sub calculate {
        }
        if (@$filters[11]){
                @$filters[11]=~ s/\*/%/g;
-               if ($cond){
-                       $strcalc .= " AND items.holdingbranch like '" . @$filters[11] ."'" if ( @$filters[11] );
-               } else {
-                       $strcalc .= " WHERE items.holdingbranch like '" . @$filters[11] ."'" if ( @$filters[11] );
-               }
+               $strcalc .= " AND items.location like '" . @$filters[11] ."'" if ( @$filters[11] );
        }
        
        $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
@@ -580,4 +576,4 @@ sub calculate {
        return \@mainloop;
 }
 
-1;
\ No newline at end of file
+1;