Modifying 0 value display in templates
[koha.git] / reports / catalogue_stats.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 C4::Auth;
24 use CGI;
25 use C4::Context;
26 use HTML::Template;
27 use C4::Search;
28 use C4::Output;
29 use C4::Koha;
30 use C4::Interface::CGI::Output;
31 use C4::Circulation::Circ2;
32
33 =head1 NAME
34
35 plugin that shows a stats on borrowers
36
37 =head1 DESCRIPTION
38
39
40 =over2
41
42 =cut
43
44 my $input = new CGI;
45 my $do_it=$input->param('do_it');
46 my $fullreportname = "reports/catalogue_stats.tmpl";
47 my $line = $input->param("Line");
48 my $column = $input->param("Column");
49 my @filters = $input->param("Filter");
50 my $deweydigits = $input->param("deweydigits");
51 my $lccndigits = $input->param("lccndigits");
52 my $cotedigits = $input->param("cotedigits");
53 my $output = $input->param("output");
54 my $basename = $input->param("basename");
55 my $mime = $input->param("MIME");
56 my $del = $input->param("sep");
57
58 my ($template, $borrowernumber, $cookie)
59         = get_template_and_user({template_name => $fullreportname,
60                                 query => $input,
61                                 type => "intranet",
62                                 authnotrequired => 0,
63                                 flagsrequired => {editcatalogue => 1},
64                                 debug => 1,
65                                 });
66 $template->param(do_it => $do_it);
67 if ($do_it) {
68         my $results = calculate($line, $column, $deweydigits, $lccndigits, $cotedigits, \@filters);
69         if ($output eq "screen"){
70                 $template->param(mainloop => $results);
71                 output_html_with_http_headers $input, $cookie, $template->output;
72                 exit(1);
73         } else {
74                 print $input->header(-type => 'application/vnd.sun.xml.calc',
75                                                          -attachment=>"$basename.csv",
76                                                          -name=>"$basename.csv" );
77                 my $cols = @$results[0]->{loopcol};
78                 my $lines = @$results[0]->{looprow};
79                 my $sep;
80                 $sep =C4::Context->preference("delimiter");
81                 print @$results[0]->{line} ."/". @$results[0]->{column} .$sep;
82                 foreach my $col ( @$cols ) {
83                         print $col->{coltitle}.$sep;
84                 }
85                 print "Total\n";
86                 foreach my $line ( @$lines ) {
87                         my $x = $line->{loopcell};
88                         print $line->{rowtitle}.$sep;
89                         foreach my $cell (@$x) {
90                                 print $cell->{value}.$sep;
91                         }
92                         print $line->{totalrow};
93                         print "\n";
94                 }
95                 print "TOTAL";
96                 $cols = @$results[0]->{loopfooter};
97                 foreach my $col ( @$cols ) {
98                         print $sep.$col->{totalcol};
99                 }
100                 print $sep.@$results[0]->{total};
101                 exit(1);
102         }
103 } else {
104         my $dbh = C4::Context->dbh;
105         my @values;
106         my %labels;
107         my $count=0;
108         my $req;
109         $req = $dbh->prepare("select distinctrow left(dewey,3) from biblioitems order by dewey");
110         $req->execute;
111         my $hasdewey;
112         my @select;
113         push @select,"";
114         while (my ($value) =$req->fetchrow) {
115                 $hasdewey =1 if (($value) and (! $hasdewey));
116                 $count++ if (($value) and (! $hasdewey));
117                 push @select, $value;
118         }
119         my $CGIdewey=CGI::scrolling_list( -name     => 'Filter',
120                                 -id => 'Filter',
121                                 -values   => \@select,
122                                 -size     => 1,
123                                 -multiple => 0 );
124         
125         $req = $dbh->prepare( "select distinctrow left(lccn,3) from biblioitems order by lccn");
126         $req->execute;
127         undef @select;
128         push @select,"";
129         my $haslccn;
130         my $hlghtlccn;
131         while (my ($value) =$req->fetchrow) {
132                 $hlghtlccn = !($hasdewey);
133                 $haslccn =1 if (($value) and (! $haslccn));
134                 $count++ if (($value) and (! $haslccn));
135                 push @select, $value;
136         }
137         my $CGIlccn=CGI::scrolling_list( -name     => 'Filter',
138                                 -id => 'Filter',
139                                 -values   => \@select,
140                                 -size     => 1,
141                                 -multiple => 0 );
142         
143         $req = $dbh->prepare("select distinctrow left(itemcallnumber,5) from items order by itemcallnumber");
144         $req->execute;
145         undef @select;
146         push @select,"";
147         my $hascote;
148         my $hlghtcote;
149         while (my ($value) =$req->fetchrow) {
150                 $hascote =1 if (($value) and (! $hascote));
151                 $count++ if (($value) and (! $hascote));
152                 $hlghtcote = (($hasdewey) and ($haslccn)) or (!($hasdewey) and !($haslccn));
153                 push @select, $value;
154         }
155         my $CGIcote=CGI::scrolling_list( -name     => 'Filter',
156                                 -id => 'Filter',
157                                 -values   => \@select,
158                                 -size     => 1,
159                                 -multiple => 0 );
160         $count++;
161         my $hglghtDT =$count % 2;
162 #       warn "highlightDT ".$hglghtDT;
163         $count++;
164         my $hglghtPub =$count % 2;
165 #       warn "highlightPub ".$hglghtPub;
166         $count++;
167         my $hglghtPY =$count % 2;
168 #       warn "highlightPY ".$hglghtPY;
169         $count++;
170         my $hglghtHB =$count % 2;
171 #       warn "highlightHB ".$hglghtHB;
172         $count++;
173         my $hglghtLOC =$count % 2;
174 #       warn "highlightLOC ".$hglghtLOC;
175         
176 #       undef @select;
177 #       push @select,"";
178 #       for (my $i=1950;$i<=2050;$i++) {
179 #               push @select, $i;
180 #       }
181 #       my $CGIpublicationyear=CGI::scrolling_list( -name     => 'Filter',
182 #                               -id => 'Filter',
183 #                               -values   => \@select,
184 #                               -size     => 1,
185 #                               -multiple => 0 );
186         
187         $req = $dbh->prepare("select distinctrow itemtype from biblioitems order by itemtype");
188         $req->execute;
189         undef @select;
190         push @select,"";
191         while (my ($value) =$req->fetchrow) {
192                 push @select, $value;
193         }
194         my $CGIitemtype=CGI::scrolling_list( -name     => 'Filter',
195                                 -id => 'Filter',
196                                 -values   => \@select,
197                                 -size     => 1,
198                                 -multiple => 0 );
199         
200         $req = $dbh->prepare("select distinctrow publishercode from biblioitems order by publishercode");
201         $req->execute;
202         undef @select;
203         push @select,"";
204         while (my ($value) =$req->fetchrow) {
205                 push @select, $value;
206         }
207         my $CGIpublisher=CGI::scrolling_list( -name     => 'Filter',
208                                 -id => 'Filter',
209                                 -values   => \@select,
210                                 -size     => 1,
211                                 -multiple => 0 );
212
213         undef @select;
214         push @select,"";
215         my $branches=getbranches();
216         my %select_branches;
217         $select_branches{""} = "";
218         foreach my $branch (keys %$branches) {
219                 push @select, $branch;
220                 $select_branches{$branch} = $branches->{$branch}->{'branchname'};
221         }
222         my $CGIbranch=CGI::scrolling_list( -name     => 'Filter',
223                                 -id => 'Filter',
224                                 -values   => \@select,
225                                 -labels   => \%select_branches,
226                                 -size     => 1,
227                                 -multiple => 0 );
228         
229         $req = $dbh->prepare("select distinctrow location from items order by location");
230         $req->execute;
231         undef @select;
232         push @select,"";
233         my $CGIlocation=CGI::scrolling_list( -name     => 'Filter',
234                                 -id => 'Filter',
235                                 -values   => \@select,
236                                 -size     => 1,
237                                 -multiple => 0 );
238         
239         my @mime = ( C4::Context->preference("MIME") );
240         foreach my $mime (@mime){
241 #               warn "".$mime;
242         }
243         
244         my $CGIextChoice=CGI::scrolling_list(
245                                 -name => 'MIME',
246                                 -id => 'MIME',
247                                 -values   => \@mime,
248                                 -size     => 1,
249                                 -multiple => 0 );
250         
251         my @dels = ( C4::Context->preference("delimiter") );
252         my $CGIsepChoice=CGI::scrolling_list(
253                                 -name => 'sep',
254                                 -id => 'sep',
255                                 -values   => \@dels,
256                                 -size     => 1,
257                                 -multiple => 0 );
258         
259         $template->param(hasdewey=>$hasdewey,
260                                         CGIFromDeweyClass => $CGIdewey,
261                                         CGIToDeweyClass => $CGIdewey,
262                                         haslccn=> $haslccn,
263                                         hlghtlccn => $hlghtlccn,
264                                         CGIFromLoCClass => $CGIlccn,
265                                         CGIToLoCClass => $CGIlccn,
266                                         hascote=> $hascote,
267                                         hlghtcote => $hlghtcote,
268                                         hglghtDT => $hglghtDT,
269                                         hglghtPub => $hglghtPub,
270                                         hglghtPY => $hglghtPY,
271                                         hglghtHB => $hglghtHB,
272                                         hglghtLOC => $hglghtLOC,
273                                         CGIFromCoteClass => $CGIcote,
274                                         CGIToCoteClass => $CGIcote,
275                                         CGIItemType => $CGIitemtype,
276 #                                       CGIFromPublicationYear => $CGIpublicationyear,
277 #                                       CGIToPublicationYear => $CGIpublicationyear,
278                                         CGIPublisher => $CGIpublisher,
279                                         CGIBranch => $CGIbranch,
280                                         CGILocation => $CGIlocation,
281                                         CGIextChoice => $CGIextChoice,
282                                         CGIsepChoice => $CGIsepChoice
283                                         );
284
285 }
286 output_html_with_http_headers $input, $cookie, $template->output;
287
288
289
290 sub calculate {
291         my ($line, $column, $deweydigits, $lccndigits, $cotedigits, $filters) = @_;
292         my @mainloop;
293         my @loopfooter;
294         my @loopcol;
295         my @loopline;
296         my @looprow;
297         my %globalline;
298         my $grantotal =0;
299 # extract parameters
300         my $dbh = C4::Context->dbh;
301
302 # Filters
303 # Checking filters
304 #
305         my @loopfilter;
306         for (my $i=0;$i<=11;$i++) {
307                 my %cell;
308                 if ( @$filters[$i] ) {
309                         if ((($i==1) or ($i==3) or ($i==5) or ($i==9)) and (@$filters[$i-1])) {
310                                 $cell{err} = 1 if (@$filters[$i]<@$filters[$i-1]) ;
311                         }
312                         $cell{filter} .= @$filters[$i];
313                         $cell{crit} .="Dewey Classification From" if ($i==0);
314                         $cell{crit} .="Dewey Classification To" if ($i==1);
315                         $cell{crit} .="Lccn Classification From" if ($i==2);
316                         $cell{crit} .="Lccn Classification To" if ($i==3);
317                         $cell{crit} .="Cote Classification From" if ($i==4);
318                         $cell{crit} .="Cote Classification To" if ($i==5);
319                         $cell{crit} .="Document type" if ($i==6);
320                         $cell{crit} .="Publisher" if ($i==7);
321                         $cell{crit} .="Publication year From" if ($i==8);
322                         $cell{crit} .="Publication year To" if ($i==9);
323                         $cell{crit} .="Branch :" if ($i==10);
324                         $cell{crit} .="Location:" if ($i==11);
325                         push @loopfilter, \%cell;
326                 }
327         }
328         
329         my @linefilter;
330 #       warn "filtres ".@filters[0];
331 #       warn "filtres ".@filters[1];
332 #       warn "filtres ".@filters[2];
333 #       warn "filtres ".@filters[3];
334         
335         $linefilter[0] = @$filters[0] if ($line =~ /dewey/ )  ;
336         $linefilter[1] = @$filters[1] if ($line =~ /dewey/ )  ;
337         $linefilter[0] = @$filters[2] if ($line =~ /lccn/ )  ;
338         $linefilter[1] = @$filters[3] if ($line =~ /lccn/ )  ;
339         $linefilter[0] = @$filters[4] if ($line =~ /items.itemcallnumber/ )  ;
340         $linefilter[1] = @$filters[5] if ($line =~ /items.itemcallnumber/ )  ;
341         @linefilter[0] = @$filters[6] if ($line =~ /itemtype/ )  ;
342         @linefilter[0] = @$filters[7] if ($line =~ /publishercode/ ) ;
343         $linefilter[0] = @$filters[8] if ($line =~ /publicationyear/ ) ;
344         $linefilter[1] = @$filters[9] if ($line =~ /publicationyear/ ) ;
345         @linefilter[0] = @$filters[10] if ($line =~ /items.homebranch/ ) ;
346         @linefilter[0] = @$filters[11] if ($line =~ /items.location/ ) ;
347
348         my @colfilter ;
349         $colfilter[0] = @$filters[0] if ($column =~ /dewey/ )  ;
350         $colfilter[1] = @$filters[1] if ($column =~ /dewey/ )  ;
351         $colfilter[0] = @$filters[2] if ($column =~ /lccn/ )  ;
352         $colfilter[1] = @$filters[3] if ($column =~ /lccn/ )  ;
353         $colfilter[0] = @$filters[4] if ($column =~ /itemcallnumber/ )  ;
354         $colfilter[1] = @$filters[5] if ($column =~ /itemcallnumber/ )  ;
355         @colfilter[0] = @$filters[6] if ($column =~ /itemtype/ )  ;
356         @colfilter[0] = @$filters[7] if ($column =~ /publishercode/ ) ;
357         $colfilter[0] = @$filters[8] if ($column =~ /publicationyear/ ) ;
358         $colfilter[1] = @$filters[9] if ($column =~ /publicationyear/ ) ;
359         @colfilter[0] = @$filters[10] if ($column =~ /items.homebranch/ ) ;
360         @colfilter[0] = @$filters[11] if ($column =~ /items.location/ ) ;
361
362 # 1st, loop rows.
363         my $linefield;
364         if (($line =~/dewey/)  and ($deweydigits)) {
365                 $linefield .="left($line,$deweydigits)";
366         } elsif (($line=~/lccn/) and ($lccndigits)) {
367                 $linefield .="left($line,$lccndigits)";
368         } elsif (($line=~/items.itemcallnumber/) and ($cotedigits)) {
369                 $linefield .="left($line,$cotedigits)";
370         }else {
371                 $linefield .= $line;
372         }
373         
374         
375         my $strsth;
376         $strsth .= "select distinctrow $linefield from biblioitems left join items on (items.biblioitemnumber = biblioitems.biblioitemnumber) where $line is not null ";
377         if ( @linefilter ) {
378                 if ($linefilter[1]){
379                         $strsth .= " and $line >= ? " ;
380                         $strsth .= " and $line <= ? " ;
381                 } elsif ($linefilter[0]) {
382                         $linefilter[0] =~ s/\*/%/g;
383                         $strsth .= " and $line LIKE ? " ;
384                 }
385         }
386         $strsth .=" order by $linefield";
387         warn "". $strsth;
388         
389         my $sth = $dbh->prepare( $strsth );
390         if (( @linefilter ) and ($linefilter[1])){
391                 $sth->execute($linefilter[0],$linefilter[1]);
392         } elsif ($linefilter[0]) {
393                 $sth->execute($linefilter[0]);
394         } else {
395                 $sth->execute;
396         }
397         while ( my ($celvalue) = $sth->fetchrow) {
398                 my %cell;
399                 if ($celvalue) {
400                         $cell{rowtitle} = $celvalue;
401 #               } else {
402 #                       $cell{rowtitle} = "";
403                 }
404                 $cell{totalrow} = 0;
405                 push @loopline, \%cell;
406         }
407
408 # 2nd, loop cols.
409         my $colfield;
410         if (($column =~/dewey/)  and ($deweydigits)) {
411                 $colfield .="left($column,$deweydigits)";
412         }elsif (($column=~/lccn/) and ($lccndigits)) {
413                 $colfield .="left($column,$lccndigits)";
414         }elsif (($column=~/itemcallnumber/) and ($cotedigits)) {
415                 $colfield .="left($column,$cotedigits)";
416         }else {
417                 $colfield .= $column;
418         }
419         
420         my $strsth2;
421         $strsth2 .= "select distinctrow $colfield from biblioitems left join items on (items.biblioitemnumber = biblioitems.biblioitemnumber) where $column is not null ";
422         if (( @colfilter ) and ($colfilter[1])) {
423                 $strsth2 .= " and $column> ? and $column< ?";
424         }elsif ($colfilter[0]){
425                 $colfilter[0] =~ s/\*/%/g;
426                 $strsth2 .= " and $column LIKE ? ";
427         } 
428         $strsth2 .= " order by $colfield";
429         warn "". $strsth2;
430         my $sth2 = $dbh->prepare( $strsth2 );
431         if ((@colfilter) and ($colfilter[1])) {
432                 $sth2->execute($colfilter[0],$colfilter[1]);
433         } elsif ($colfilter[0]){
434                 $sth2->execute($colfilter[0]);
435         } else {
436                 $sth2->execute;
437         }
438         while (my ($celvalue) = $sth2->fetchrow) {
439                 my %cell;
440                 my %ft;
441                 if ($celvalue) {
442                         $cell{coltitle} = $celvalue;
443 #               } else {
444 #                       $cell{coltitle} = "";
445                 }
446                 $ft{totalcol} = 0;
447                 push @loopcol, \%cell;
448         }
449         
450
451         my $i=0;
452         my @totalcol;
453         my $hilighted=-1;
454         
455         #Initialization of cell values.....
456         my %table;
457 #       warn "init table";
458         foreach my $row ( @loopline ) {
459                 foreach my $col ( @loopcol ) {
460 #                       warn " init table : $row->{rowtitle} / $col->{coltitle} ";
461                         $table{$row->{rowtitle}}->{$col->{coltitle}}=0;
462                 }
463                 $table{$row->{rowtitle}}->{totalrow}=0;
464         }
465
466 # preparing calculation
467         my $strcalc .= "SELECT $linefield, $colfield, count( * ) FROM biblioitems LEFT JOIN  items ON (items.biblioitemnumber = biblioitems.biblioitemnumber)";
468         my $cond=0;
469         if (@$filters[0]){
470                 @$filters[0]=~ s/\*/%/g;
471                 $strcalc .= " WHERE dewey >" . @$filters[0] ."";
472                 $cond=1; 
473         }
474         if (@$filters[1]){
475                 @$filters[1]=~ s/\*/%/g ;
476                 if ($cond){
477                         $strcalc .= " AND dewey <" . @$filters[1] ."";
478                 } else {
479                         $strcalc .= " WHERE dewey <" . @$filters[1] ."" ;
480                         $cond=1;
481                 }
482                 
483         }
484         if (@$filters[2]){
485                 @$filters[2]=~ s/\*/%/g ;
486                 if ($cond){
487                         $strcalc .= " AND lccn >" . @$filters[2] ."" ;
488                 } else {
489                         $strcalc .= " WHERE lccn > " . @$filters[2] ."" ;
490                         $cond=1;
491                 }
492         }
493         if (@$filters[3]){
494                 @$filters[3]=~ s/\*/%/g;
495                 if ($cond){
496                         $strcalc .= " AND lccn <" . @$filters[3] ."" ;
497                 } else {
498                         $strcalc .= " WHERE lccn <" . @$filters[3] ."" ;
499                         $cond=1;
500                 }
501         }
502         if (@$filters[4]){
503                 @$filters[4]=~ s/\*/%/g ;
504                 if ($cond){
505                         $strcalc .= " AND items.itemcallnumber >" . @$filters[4] ."" ;
506                 } else {
507                         $strcalc .= " WHERE items.itemcallnumber >" . @$filters[4] ."" ;
508                         $cond=1;
509                 }
510         }
511         
512         if (@$filters[5]){
513                 @$filters[5]=~ s/\*/%/g;
514                 if ($cond){
515                         $strcalc .= " AND items.itemcallnumber <" . @$filters[5] ."" ;
516                 } else {
517                         $strcalc .= " WHERE items.itemcallnumber <" . @$filters[5] ."" ;
518                         $cond=1;
519                 }
520         }
521         
522         if (@$filters[6]){
523                 @$filters[6]=~ s/\*/%/g;
524                 if ($cond){
525                         $strcalc .= " AND biblioitems.itemtype like '" . @$filters[6] ."'";
526                 } else {
527                         $strcalc .= " WHERE biblioitems.itemtype like '" . @$filters[6] ."'";
528                         $cond=1;
529                 }
530         }
531         
532         if (@$filters[7]){
533                 @$filters[7]=~ s/\*/%/g;
534                 if ($cond){
535                         $strcalc .= " AND biblioitems.publishercode like '" . @$filters[7] ."'";
536                 } else {
537                         $strcalc .= " WHERE biblioitems.publishercode like '" . @$filters[7] ."'";
538                         $cond=1;
539                 }
540         }
541         if (@$filters[8]){
542                 @$filters[8]=~ s/\*/%/g;
543                 if ($cond){
544                         $strcalc .= " AND publicationyear >" . @$filters[8] ."" ;
545                 } else {
546                         $strcalc .= " WHERE publicationyear >" . @$filters[8] ."" ;
547                         $cond=1;
548                 }
549         }
550         if (@$filters[9]){
551                 @$filters[9]=~ s/\*/%/g;
552                 if ($cond){
553                         $strcalc .= " AND publicationyear <" . @$filters[9] ."";
554                 } else {
555                         $strcalc .= " WHERE publicationyear <" . @$filters[9] ."";
556                         $cond=1;
557                 }
558         }
559         if (@$filters[10]){
560                 @$filters[10]=~ s/\*/%/g;
561                 if ($cond){
562                         $strcalc .= " AND items.homebranch like '" . @$filters[10] ."'";
563                 } else {
564                         $strcalc .= " WHERE items.homebranch like '" . @$filters[10] ."'";
565                         $cond=1;
566                 }
567         }
568         if (@$filters[11]){
569                 @$filters[11]=~ s/\*/%/g;
570                 if ($cond){
571                         $strcalc .= " AND items.location like '" . @$filters[11] ."'" if ( @$filters[11] );
572                 } else {
573                         $strcalc .= " WHERE items.location like '" . @$filters[11] ."'" if ( @$filters[11] );
574                 }
575         }
576         
577         $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
578         warn "". $strcalc;
579         my $dbcalc = $dbh->prepare($strcalc);
580         $dbcalc->execute;
581 #       warn "filling table";
582         
583         my $emptycol; 
584         while (my ($row, $col, $value) = $dbcalc->fetchrow) {
585 #               warn "filling table $row / $col / $value ";
586                 $emptycol = 1 if ($col eq undef);
587                 $col = "zzEMPTY" if ($col eq undef);
588                 $row = "zzEMPTY" if ($row eq undef);
589                 
590                 $table{$row}->{$col}+=$value;
591                 $table{$row}->{totalrow}+=$value;
592                 $grantotal += $value;
593         }
594
595 #       my %cell = {rowtitle => 'zzROWEMPTY'};
596 #       push @loopline,\%cell;
597 #       undef %cell;
598 #       my %cell;
599 #       %cell = {coltitle => "zzEMPTY"};
600         push @loopcol,{coltitle => "NULL"} if ($emptycol);
601         
602         foreach my $row ( sort keys %table ) {
603                 my @loopcell;
604                 #@loopcol ensures the order for columns is common with column titles
605                 # and the number matches the number of columns
606                 foreach my $col ( @loopcol ) {
607                         my $value =$table{$row}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
608                         push @loopcell, {value => $value  } ;
609                 }
610                 push @looprow,{ 'rowtitle' => ($row eq "zzEMPTY")?"NULL":$row,
611                                                 'loopcell' => \@loopcell,
612                                                 'hilighted' => ($hilighted >0),
613                                                 'totalrow' => $table{$row}->{totalrow}
614                                         };
615                 $hilighted = -$hilighted;
616         }
617         
618 #       warn "footer processing";
619         foreach my $col ( @loopcol ) {
620                 my $total=0;
621                 foreach my $row ( @looprow ) {
622                         $total += $table{($row->{rowtitle} eq "NULL")?"zzEMPTY":$row->{rowtitle}}->{($col->{coltitle} eq "NULL")?"zzEMPTY":$col->{coltitle}};
623 #                       warn "value added ".$table{$row->{rowtitle}}->{$col->{coltitle}}. "for line ".$row->{rowtitle};
624                 }
625 #               warn "summ for column ".$col->{coltitle}."  = ".$total;
626                 push @loopfooter, {'totalcol' => $total};
627         }
628                         
629
630         # the header of the table
631         $globalline{loopfilter}=\@loopfilter;
632         # the core of the table
633         $globalline{looprow} = \@looprow;
634         $globalline{loopcol} = \@loopcol;
635 #       # the foot (totals by borrower type)
636         $globalline{loopfooter} = \@loopfooter;
637         $globalline{total}= $grantotal;
638         $globalline{line} = $line;
639         $globalline{column} = $column;
640         push @mainloop,\%globalline;
641         return \@mainloop;
642 }
643
644 1;