7e7b81aa4ae6ac50baa180aef538d90058d77687
[koha-bibliografija] / html.pl
1 #!/usr/bin/perl
2
3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
4
5 use warnings;
6 use strict;
7
8 use DBI;
9 use Data::Dump qw(dump);
10 use autodie;
11 use locale;
12 use Text::Unaccent;
13 use Carp qw(confess);
14 use utf8;
15
16 use lib '/srv/koha_ffzg';
17 use C4::Context;
18 use XML::LibXML;
19 use XML::LibXSLT;
20
21 my $dbh = C4::Context->dbh;
22
23 sub debug {
24         my ($title, $data) = @_;
25         print "# $title ",dump($data), $/ if $ENV{DEBUG};
26 }
27
28 my $xslfilename = 'compact.xsl';
29
30 my $azvo_group_title = {
31 'znanstveno nastavni' => qr/(profesor|docent|znanstveni)/i,
32 'lektori i predavači' => qr/(lektor|predavač)/i,
33 'asistenti i novaci' => qr/(asistent|novak)/i,
34 };
35
36 my $department_groups = {
37 'ZZA_humanističke'             => qr/(anglistiku|arheologiju|antropologiju|filozofiju|fonetiku|germanistiku|hungarologiju|indologiju|slavenske|filologiju|komparativnu|kroatistiku|lingvistiku|povijest|romanistiku|talijanistiku)/i,
38 'ZZB_društvene'                        => qr/(informacijske|pedagogiju|psihologiju|sociologiju)/i,
39 };
40
41 my $auth_header;
42 my $auth_department;
43 my $auth_group;
44 my @authors;
45 my $department_in_sum;
46 my $department_in_group;
47
48 my $skip;
49
50 my $sth_auth = $dbh->prepare(q{
51 select
52         authid,
53         ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name,
54         ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="a"]') as department,
55         ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="i"]') as academic_title
56 from auth_header
57 });
58
59 $sth_auth->execute();
60 while( my $row = $sth_auth->fetchrow_hashref ) {
61         if ( $row->{department} !~ m/Filozofski fakultet u Zagrebu/ ) {
62                 push @{ $skip->{nije_ffzg} }, $row;
63                 next;
64         }
65         $auth_header->{ $row->{authid} } = $row->{full_name};
66         $row->{department} =~ s/, Filozofski fakultet u Zagrebu.*$//;
67         $row->{department} =~ s/^.+\.\s*//;
68         $row->{department} =~ s/\s+$//s;
69         my $group;
70         foreach my $title ( keys %$azvo_group_title ) {
71                 if ( $row->{academic_title} =~ $azvo_group_title->{$title} ) {
72                         $group = $title;
73                         last;
74                 }
75         }
76         if ( $group ) {
77                 $row->{academic_group} = $group;
78                 $auth_group->{ $row->{authid} } = $group;
79                 $skip->{group_stat}->{$group}++;
80         } else {
81                 push @{ $skip->{no_academic_group} }, $row;
82         }
83
84 #       warn "# ", dump( $row );
85         push @{ $auth_department->{ $row->{department} } }, $row->{authid};
86         push @authors, $row;
87         $department_in_sum->{ $row->{department} }++;
88         foreach my $name ( keys %$department_groups ) {
89                 my $regex = $department_groups->{$name};
90                 if ( $row->{department} =~ $regex ) {
91                         $department_in_group->{ $row->{department} } = $name;
92                         last;
93                 }
94         }
95 }
96
97 debug 'department_in_group' => $department_in_group;
98
99 foreach my $department ( keys %$department_in_sum ) {
100         $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
101 }
102
103 debug 'auth_department' => $auth_department;
104 debug 'auth_group' => $auth_group;
105 debug 'department_in_sum' => $department_in_sum;
106
107
108 my $authors;
109 my $marcxml;
110
111 my $sth_select_authors  = $dbh->prepare(q{
112 select
113         biblionumber,
114         itemtype,
115         marcxml
116 from biblioitems
117 where
118         agerestriction > 0
119 });
120
121 =for sql
122 --      ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
123 --      ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
124 --      ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
125
126 --      and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
127 -- order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
128 =cut
129
130 my $biblio_year;
131 my $type_stats;
132
133 my $parser = XML::LibXML->new();
134 $parser->recover_silently(0); # don't die when you find &, >, etc
135 my $style_doc = $parser->parse_file($xslfilename);
136 my $xslt = XML::LibXSLT->new();
137 my $parsed = $xslt->parse_stylesheet($style_doc);
138
139 my $biblio_html;
140 my $biblio_parsed;
141 my $biblio_data;
142
143 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
144
145 sub biblioitem_html {
146         my ($biblionumber, $parse_only) = @_;
147
148         return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber} && ! $parse_only;
149
150         my $xmlrecord = $marcxml->{$biblionumber} || confess "missing $biblionumber marcxml";
151
152         print $xml_fh $xmlrecord if $ENV{XML};
153
154         my $source = eval { $parser->parse_string($xmlrecord) };
155         if ( $@ ) {
156 #               warn "SKIP $biblionumber corrupt XML";
157                 push @{ $skip->{XML_corrupt} }, $biblionumber;
158                 return;
159         }
160
161         if ( $parse_only ) {
162                 $biblio_parsed->{$biblionumber} = $source;
163                 return $source;
164         }
165
166         my $transformed = $parsed->transform($source);
167         $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
168
169         delete $biblio_parsed->{$biblionumber};
170
171         return $biblio_html->{$biblionumber};
172 }
173
174 $sth_select_authors->execute();
175 while( my $row = $sth_select_authors->fetchrow_hashref ) {
176 #       warn dump($row),$/;
177
178         my $biblio;
179
180         $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
181
182         my $doc = biblioitem_html( $row->{biblionumber}, 1 );
183         if ( ! $doc ) {
184 #               warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
185                 next;
186         }
187
188         my $root = $doc->documentElement;
189 =for leader
190         my @leaders = $root->getElementsByLocalName('leader');
191         if (@leaders) {
192                 my $leader = $leaders[0]->textContent;
193                 warn "leader $leader\n";
194         }
195 =cut
196
197         my $extract = {
198                 '008' => undef,
199                 '100' => '9',
200                 '680' => 'i',
201                 '700' => '(9|4)',
202                 '942' => '(t|r|v)'
203         };
204
205         my $data;
206
207         foreach my $elt ($root->getChildrenByLocalName('*')) {
208                 my $tag = $elt->getAttribute('tag');
209                 next if ! $tag;
210                 next unless exists $extract->{ $tag };
211
212         if ($elt->localname eq 'controlfield') {
213                         if ( $tag eq '008' ) {
214                                 my $content = $elt->textContent;
215                                 my $year = substr($content, 7, 4 );
216                                 if ( $year !~ m/^\d+$/ ) {
217                                         $year = 0;
218                                         push @{ $skip->{invalid_year} }, $row->{biblionumber};
219                                 }
220                                 $biblio_year->{ $row->{biblionumber} } = $data->{year} = $year;
221                                 $data->{'008'} = $content;
222                         }
223                         next;
224         } elsif ($elt->localname eq 'datafield') {
225                         my $sf_data;
226             foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
227                 my $sf = $sfelt->getAttribute('code');
228                                 next unless $sf =~ m/$extract->{$tag}/;
229                                 if ( exists $sf_data->{$sf} ) {
230                                         $sf_data->{$sf} .= " " . $sfelt->textContent();
231                                 } else {
232                                         $sf_data->{$sf} = $sfelt->textContent();
233                                 }
234                         }
235                         push @{ $data->{$tag} }, $sf_data if $sf_data;
236         }
237     }
238
239         if ( $data->{year} < 2008 ) {
240                 push @{ $skip->{year_lt_2008} }, $row->{biblionumber};
241                 next;
242         } elsif ( $data->{year} > 2013 ) {
243                 push @{ $skip->{year_gt_2013} }, $row->{biblionumber};
244                 next;
245         }
246
247 #       warn "# ", $row->{biblionumber}, " data ",dump($data);
248
249         my $category = $data->{942}->[0]->{'t'};
250         if ( ! $category ) {
251 #               warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
252                 push @{ $skip->{no_category} }, $row->{biblionumber};
253                 next;
254         }
255
256         my $have_100 = 1;
257
258         if ( exists $data->{100} ) {
259                         my @first_author = map { $_->{'9'} } @{ $data->{100} };
260                         foreach my $authid ( @first_author ) {
261                                 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
262                         }
263         } else {
264                 $have_100 = 0;
265         }
266
267         my $have_edt;
268
269         if ( exists $data->{700} ) {
270                         foreach my $auth ( @{ $data->{700} } ) {
271                                 my $authid = $auth->{9} || next;
272                                 my $type   = $auth->{4} || next; #die "no 4 in ",dump($data);
273
274                                 $type_stats->{$type}++;
275
276                                 if ( $type =~ m/(edt|trl|com|ctb)/ ) {
277                                         push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
278                                         push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber};
279                                 } elsif ( $type =~ m/aut/ ) {
280                                         if ( ! $have_100 ) {
281                                                 $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
282                                                 if ( $have_edt ) {
283                                                         $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
284                                                 } else {
285                                                         push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
286                                                 }
287                                         } else {
288                                                 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
289                                         }
290                                 } else {
291 #                                       warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
292                                         $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
293                                 }
294                         }
295                         delete $data->{700};
296         }
297
298         $biblio_data->{ $row->{biblionumber} } = $data;
299
300 }
301
302 debug 'authors' => $authors;
303 debug 'type_stats' => $type_stats;
304 debug 'skip' => $skip;
305 debug 'biblio_year' => $biblio_year;
306 debug 'biblio_data' => $biblio_data;
307
308 my $category_label;
309 my $sth_categories = $dbh->prepare(q{
310 select authorised_value, lib from authorised_values where category = 'BIBCAT'
311 });
312 $sth_categories->execute();
313 while( my $row = $sth_categories->fetchrow_hashref ) {
314         $category_label->{ $row->{authorised_value} } = $row->{lib};
315
316 }
317 debug 'category_label' => $category_label;
318
319 sub html_title {
320         return qq|<html>
321 <head>
322 <meta charset="UTF-8">
323 <title>|, join(" ", @_), qq|</title>
324 <link href="style.css" type="text/css" rel="stylesheet" />
325 </head>
326 <body>
327 |;
328 }
329
330 sub html_end {
331         return qq|</body>\n</html>\n|;
332 }
333
334 mkdir 'html' unless -d 'html';
335
336 open(my $index, '>:encoding(utf-8)', 'html/index.new');
337 print $index html_title('Bibliografija Filozofskog fakulteta');
338
339 my $first_letter = '';
340
341 debug 'authors' => \@authors;
342
343 sub li_biblio {
344         my ($biblionumber) = @_;
345         return qq|<li>|,
346                 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
347                 biblioitem_html($biblionumber),
348                 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
349                 qq|</li>\n|;
350 }
351
352 sub author_html {
353         my ( $fh, $authid, $type, $label ) = @_;
354
355         return unless exists $authors->{$authid}->{$type};
356
357         print $fh qq|<h2>$label</h2>\n|;
358
359         foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
360                 my $label = $category_label->{$category} || 'Bez kategorije';
361                 print $fh qq|<h3>$label</h3>\n<ul>\n|;
362                 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
363                         print $fh li_biblio( $biblionumber );
364                 }
365                 print $fh qq|</ul>\n|;
366         }
367 }
368
369 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
370
371         my $first = substr( $row->{full_name}, 0, 1 );
372         if ( $first ne $first_letter ) {
373                 print $index qq{</ul>\n} if $first_letter;
374                 $first_letter = $first;
375                 print $index qq{<h1>$first</h1>\n<ul>\n};
376         }
377         print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
378
379         my $path = "html/$row->{authid}";
380         open(my $fh, '>:encoding(utf-8)', "$path.new");
381         print $fh html_title($row->{full_name}, "bibliografija");
382         print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
383
384         author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
385         author_html( $fh, $row->{authid}, 'sec' => 'Uredništva, prijevodi, krička izdanja' );
386
387         print $fh html_end;
388         close($fh);
389         rename "$path.new", "$path.html";
390
391 }
392
393 print $index html_end;
394 close($index);
395 rename 'html/index.new', 'html/index.html';
396
397 debug 'auth_header' => $auth_header;
398
399
400 my $department_category_author;
401 foreach my $department ( sort keys %$auth_department ) {
402         foreach my $authid ( sort @{ $auth_department->{$department} } ) {
403                 my   @categories = keys %{ $authors->{$authid}->{aut} };
404                 push @categories,  keys %{ $authors->{$authid}->{sec} };
405                 foreach my $category ( sort @categories ) {
406                         push @{ $department_category_author->{$department}->{$category} }, $authid;
407                         push @{ $department_category_author->{'ZZZ_ukupno'}->{$category} }, $authid if $department_in_sum->{$department};
408                         if ( my $group = $department_in_group->{ $department } ) {
409                                 push @{ $department_category_author->{$group}->{$category} }, $authid;
410                         } else {
411                                 $skip->{'department_not_in_group'}->{ $department }++;
412                         }
413                 }
414         }
415 }
416
417 debug 'department_category_author' => $department_category_author;
418
419 mkdir 'html/departments' unless -d 'html/departments';
420
421 sub unique_biblionumber {
422         my @v = @_;
423         my $u;
424         $u->{$_}++ foreach @v;
425         return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $a <=> $b } keys %$u;
426 }
427
428 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
429 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
430 foreach my $department ( sort keys %$department_category_author ) {
431         my $dep = $department || 'Nema odsjeka';
432         my $dep_file = unac_string('utf-8',$dep);
433         print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
434         open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
435
436         print $fh html_title($department . ' bibliografija');
437         print $fh qq|<h1>$department bibliografija</h1>\n|;
438
439         print $fh qq|<h2>Primarno autorstvo</h2>\n|;
440
441         foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
442
443                 my @authids = @{ $department_category_author->{$department}->{$category} };
444                 next unless @authids;
445
446                 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{aut}->{$category} } } grep { exists $authors->{$_}->{aut}->{$category} } @authids;
447                 my $unique;
448                 $unique->{$_}++ foreach @biblionumber;
449
450                 next unless @biblionumber;
451
452                 my $label = $category_label->{$category} || 'Bez kategorije';
453                 print $fh qq|<h3>$label</h3>\n<ul>\n|;
454
455                 print $fh li_biblio( $_ ) foreach @biblionumber;
456
457                 print $fh qq|</ul>|;
458         }
459
460
461         print $fh qq|<h2>Sekundarno autorstvo</h2>\n|;
462
463         foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
464
465                 my @authids = @{ $department_category_author->{$department}->{$category} };
466                 next unless @authids;
467
468                 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{sec}->{$category} } } grep { exists $authors->{$_}->{sec}->{$category} } @authids;
469
470                 next unless @biblionumber;
471
472                 my $label = $category_label->{$category} || 'Bez kategorije';
473                 print $fh qq|<h3>$label</h3>\n<ul>\n|;
474
475                 print $fh li_biblio( $_ ) foreach @biblionumber;
476
477                 print $fh qq|</ul>|;
478         }
479
480
481         print $fh html_end;
482         close($fh);
483         rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
484 }
485 print $dep_fh qq|</ul>\n|, html_end;
486 close($dep_fh);
487 rename 'html/departments/index.new', 'html/departments/index.html';
488
489 my $azvo_stat_biblio;
490
491 foreach my $department ( sort keys %$department_category_author ) {
492         foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
493                 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
494                         my $group = $auth_group->{$authid};
495                         if ( ! $group ) {
496                                 push @{ $skip->{no_auth_group} }, $authid;
497                                 next;
498                         }
499                         foreach my $type ( keys %{ $authors->{$authid} } ) {
500                                 next unless exists $authors->{$authid}->{$type}->{$category};
501                                 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{$group} },  @{ $authors->{$authid}->{$type}->{$category} };
502                                 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{''} },  @{ $authors->{$authid}->{$type}->{$category} };
503                         }
504                 }
505                 foreach my $type ( keys %{ $azvo_stat_biblio->{ $department }->{ $category } } ) {
506                         foreach my $group ( keys %{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } } ) {
507                                 my @biblios = unique_biblionumber @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{ $group } };
508                                 $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{ $group } = [ @biblios ];
509                         }
510                 }
511         }
512 }
513
514 debug 'azvo_stat_biblio' => $azvo_stat_biblio;
515
516 my @report_lines;
517 my @report_labels;
518
519 my $label;
520 my $sub_labels;
521 open(my $report, '<:encoding(utf-8)', 'AZVO.txt');
522 while( <$report> ) {
523         chomp;
524         if ( /^([^\t]+)\t+(.+)/ ) {
525                 $label = $1;
526                 push @report_labels, $label;
527                 my $type = [ map { m/\s+/ ? [ split(/\s+/,$_) ] : [ $_, 'aut' ] } split (/\s*\+\s*/, $2) ];
528                 push @report_lines, [ $label, @$type ];
529         } elsif ( /^\t+([^\t]+):\t+(\d+)(\w*)\t*(.*)$/ ) {
530                 push @{ $sub_labels->{$label} }, [ $1, $2, $3, $4 ];
531                 my $sub_label = $1;
532                 pop (@report_labels) if ( $report_labels[ $#report_labels ] =~ m/^$label$/ ); # remove partial name
533                 push @report_labels, $label . $sub_label;
534         } else {
535                 die "ERROR: [$_]\n";
536         }
537 }
538
539 debug 'report_lines', \@report_lines;
540 debug 'sub_labels', $sub_labels;
541 debug 'report_labels', \@report_labels;
542
543 my @departments = ( sort { lc($a) cmp lc($b) } keys %$azvo_stat_biblio );
544
545 debug 'departments' => \@departments;
546
547 my $department2col;
548 $department2col->{ $departments[$_] } = $_ foreach ( 0 .. $#departments );
549 my $label2row;
550 $label2row->{ $report_labels[$_] } = $_ foreach ( 0 .. $#report_labels );
551
552 my $table;
553
554 sub table_count {
555         my $label = shift @_;
556         my $department = shift @_;
557         my $group = shift @_;
558         my @biblionumbers = @_;
559         my $unique;
560         $unique->{$_}++ foreach @biblionumbers;
561         $table->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar keys %$unique;
562 }
563
564 foreach my $group ( '', keys %$azvo_group_title ) {
565
566 foreach my $department ( @departments ) {
567         foreach my $line ( @report_lines ) {
568                 my $label = $line->[0];
569                 my @biblionumbers;
570                 foreach ( 1 .. $#$line ) {
571                         my ( $category, $type ) = @{ $line->[ $_ ] };
572                         my $b = $azvo_stat_biblio->{ $department }->{$category}->{$type}->{$group};
573                         push @biblionumbers, @$b if $b;
574                 }
575                 if ( $sub_labels->{$label} ) {
576                         my $sub_stats;
577                         foreach my $biblionumber ( @biblionumbers ) {
578                                 my $data = $biblio_data->{$biblionumber} || die "can't find biblionumber $biblionumber";
579                                 foreach my $sub_label ( @{ $sub_labels->{$label} } ) {
580                                         my ( $sub_label, $field, $sf, $regex ) = @$sub_label;
581                                         if ( ! $regex ) {
582                                                 push @{ $sub_stats->{ $sub_label } }, $biblionumber;
583                                                 last;
584                                         }
585                                         if ( $field < 100 ) {
586                                                 if ( $data->{$field} =~ m/$regex/ ) {
587                                                         push @{ $sub_stats->{ $sub_label } }, $biblionumber;
588                                                         last;
589                                                 }
590                                         } else {
591                                                 if ( exists $data->{$field}->[0]->{$sf} && $data->{$field}->[0]->{$sf} =~ m/$regex/ ) {
592                                                         push @{ $sub_stats->{ $sub_label } }, $biblionumber;
593                                                         last;
594                                                 }
595                                         }
596                                 }
597                         }
598                         foreach my $sub_label ( keys %$sub_stats ) {
599                                 my $full_label = $label . $sub_label;
600                                 table_count $full_label, $department, $group, @{ $sub_stats->{$sub_label} };
601                         }
602                 } else {
603                         table_count $label, $department, $group, @biblionumbers;
604                 }
605         }
606 }
607
608 } # group
609
610 debug 'table', $table;
611
612 open(my $fh, '>:encoding(utf-8)', 'html/azvo.new');
613
614 print $fh html_title('AZVO tablica');
615
616 foreach my $group ( keys %$table ) {
617
618                 print $fh "<h1>$group</h1>" if $group;
619
620                 print $fh "<table border=1>\n";
621                 print $fh "<tr><th></th>";
622                 print $fh "<th>$_</th>" foreach @departments;
623                 print $fh "</tr>\n";
624
625                 foreach my $row ( 0 .. $#{ $table->{$group} } ) {
626                         print $fh "<tr><th>", $report_labels[$row], "</th>\n";
627                         print $fh " <td>", $table->{$group}->[ $row ]->[ $_ ] || '', "</td>\n" foreach 0 .. $#departments;
628                         print $fh "</tr>\n";
629                 }
630
631                 print $fh "</table>\n";
632
633 } # group
634
635 print $fh html_end;
636 close($fh);
637 rename 'html/azvo.new', 'html/azvo.html';
638