3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
9 use Data::Dump qw(dump);
16 use POSIX qw(strftime);
19 use lib '/srv/koha_ffzg';
24 my $pid_file = '/dev/shm/bibliografija.pid';
27 open(my $fh, '<', $pid_file);
29 no autodie; # it will die on kill
30 kill 0, $pid || die "$0 allready running as pid $pid";
32 open(my $fh, '>', $pid_file);
38 my $dbh = C4::Context->dbh;
41 my ($title, $data) = @_;
42 print "# $title ",dump($data), $/ if $ENV{DEBUG};
45 my $xslfilename = 'compact.xsl';
47 my $azvo_group_title = {
48 'znanstveno nastavni' => qr/(profes|docent|znanstveni savjetnik|znanstveni suradnik)/i,
49 'lektori i predavači' => qr/(lektor|predavač)/i,
50 'asistenti i novaci' => qr/(asistent|novak)/i,
53 my $department_groups = {
54 'AAB_humanističke' => qr/(anglistiku|arheologiju|antropologiju|filozofiju|fonetiku|germanistiku|hungarologiju|indologiju|slavenske|filologiju|komparativnu|kroatistiku|lingvistiku|povijest|romanistiku|talijanistiku)/i,
55 'AAC_društvene' => qr/(informacijske|pedagogiju|psihologiju|sociologiju)/i,
62 my $department_in_sum;
63 my $department_in_group;
67 my $sth_auth = $dbh->prepare(q{
70 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name,
71 ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="a"]') as department,
72 ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="i"]') as academic_title
77 while( my $row = $sth_auth->fetchrow_hashref ) {
78 if ( $row->{department} !~ m/Filozofski fakultet u Zagrebu/ ) {
79 push @{ $skip->{nije_ffzg} }, $row;
82 $auth_header->{ $row->{authid} } = $row->{full_name};
83 $row->{department} =~ s/, Filozofski fakultet u Zagrebu.*$//;
84 $row->{department} =~ s/^.+\.\s*//;
85 $row->{department} =~ s/\s+$//s;
87 foreach my $title ( keys %$azvo_group_title ) {
88 if ( $row->{academic_title} =~ $azvo_group_title->{$title} ) {
94 $row->{academic_group} = $group;
95 $auth_group->{ $row->{authid} } = $group;
96 $skip->{group_stat}->{$group}++;
98 push @{ $skip->{no_academic_group} }, $row;
101 # warn "# ", dump( $row );
102 push @{ $auth_department->{ $row->{department} } }, $row->{authid};
104 $department_in_sum->{ $row->{department} }++;
105 foreach my $name ( keys %$department_groups ) {
106 my $regex = $department_groups->{$name};
107 if ( $row->{department} =~ $regex ) {
108 $department_in_group->{ $row->{department} } = $name;
114 debug 'department_in_group' => $department_in_group;
116 foreach my $department ( keys %$department_in_sum ) {
117 # $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
120 debug 'auth_department' => $auth_department;
121 store $auth_department, '/dev/shm/auth_department.storable';
122 debug 'auth_group' => $auth_group;
123 debug 'department_in_sum' => $department_in_sum;
129 my $sth_select_authors = $dbh->prepare(q{
131 biblioitems.biblionumber,
135 join biblio_metadata on (biblio_metadata.biblionumber = biblioitems.biblionumber)
141 -- ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
142 -- ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
143 -- ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
145 -- and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
146 -- order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
150 my $biblio_full_name;
153 my $parser = XML::LibXML->new();
154 $parser->recover_silently(0); # don't die when you find &, >, etc
155 my $style_doc = $parser->parse_file($xslfilename);
156 my $xslt = XML::LibXSLT->new();
157 my $parsed = $xslt->parse_stylesheet($style_doc);
162 my $biblio_author_external;
164 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
166 sub biblioitem_html {
167 my ($biblionumber, $parse_only) = @_;
169 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber} && ! $parse_only;
171 my $xmlrecord = $marcxml->{$biblionumber} || confess "missing $biblionumber marcxml";
173 print $xml_fh $xmlrecord if $ENV{XML};
175 my $source = eval { $parser->parse_string($xmlrecord) };
177 # warn "SKIP $biblionumber corrupt XML";
178 push @{ $skip->{XML_corrupt} }, $biblionumber;
183 $biblio_parsed->{$biblionumber} = $source;
187 my $transformed = $parsed->transform($source);
188 $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
190 delete $biblio_parsed->{$biblionumber};
192 return $biblio_html->{$biblionumber};
195 $sth_select_authors->execute();
196 while( my $row = $sth_select_authors->fetchrow_hashref ) {
197 # warn dump($row),$/;
201 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
203 my $doc = biblioitem_html( $row->{biblionumber}, 1 );
205 # warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
209 my $root = $doc->documentElement;
211 my @leaders = $root->getElementsByLocalName('leader');
213 my $leader = $leaders[0]->textContent;
214 warn "leader $leader\n";
229 foreach my $elt ($root->getChildrenByLocalName('*')) {
230 my $tag = $elt->getAttribute('tag');
232 next unless exists $extract->{ $tag };
234 if ($elt->localname eq 'controlfield') {
235 if ( $tag eq '008' ) {
236 my $content = $elt->textContent;
237 my $year = substr($content, 7, 4 );
238 if ( $year !~ m/^\d+$/ ) {
240 push @{ $skip->{invalid_year} }, $row->{biblionumber};
242 $biblio_year->{ $row->{biblionumber} } = $data->{year} = $year;
243 $data->{'008'} = $content;
246 } elsif ($elt->localname eq 'datafield') {
248 foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
249 my $sf = $sfelt->getAttribute('code');
250 next unless $sf =~ m/$extract->{$tag}/;
251 if ( exists $sf_data->{$sf} ) {
252 $sf_data->{$sf} .= " " . $sfelt->textContent();
254 $sf_data->{$sf} = $sfelt->textContent();
257 push @{ $data->{$tag} }, $sf_data if $sf_data;
261 if ( ! defined $data->{year} ) {
262 warn "MISSING year in ", $row->{biblionumber};
263 =for remove-year-limit
264 } elsif ( $data->{year} < 2008 ) {
265 push @{ $skip->{year_lt_2008} }, $row->{biblionumber};
267 } elsif ( $data->{year} > 2013 ) {
268 push @{ $skip->{year_gt_2013} }, $row->{biblionumber};
273 # warn "# ", $row->{biblionumber}, " data ",dump($data);
275 my $category = $data->{942}->[0]->{'t'};
277 # warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
278 push @{ $skip->{no_category} }, $row->{biblionumber};
284 if ( exists $data->{100} ) {
288 if ( ! exists $_->{9} ) {
289 $biblio_author_external->{ $row->{biblionumber} }++;
291 } elsif ( exists $auth_header->{ $_->{9} } ) {
298 foreach my $authid ( @first_author ) {
299 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
301 $biblio_full_name->{ $row->{biblionumber} } = $data->{100}->[0]->{a};
306 $biblio_full_name->{ $row->{biblionumber} } ||= $data->{245}->[0]->{a};
310 if ( exists $data->{700} ) {
313 if ( ! exists $_->{9} ) {
314 $biblio_author_external->{ $row->{biblionumber} }++;
316 } elsif ( exists $auth_header->{ $_->{9} } ) {
323 foreach my $auth ( @other_authors ) {
324 my $authid = $auth->{9} || next;
325 my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
327 $type_stats->{$type}++;
329 my @types = split(/[\s\/]+/, $type);
331 foreach my $type ( @types ) {
332 my $type = substr($type,0,3);
333 $type_stats->{_count_each_type}->{$type}++;
335 if ( $type =~ m/(edt|trl|com|ctb)/ ) {
336 push @{ $authors->{$authid}->{__sec}->{ $category } }, $row->{biblionumber};
337 push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber};
338 $type =~ s/(com|ctb)/_ostalo/;
339 push @{ $authors->{$authid}->{$type}->{ $category } }, $row->{biblionumber};
341 } elsif ( $type =~ m/aut/ ) {
343 $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
345 $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
347 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
350 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
353 # warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
354 $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
361 $biblio_data->{ $row->{biblionumber} } = $data;
365 debug 'authors' => $authors;
366 store $authors, '/dev/shm/authors.storable';
367 debug 'type_stats' => $type_stats;
368 debug 'skip' => $skip;
369 debug 'biblio_year' => $biblio_year;
370 debug 'biblio_full_name' => $biblio_full_name;
371 debug 'biblio_data' => $biblio_data;
372 debug 'biblio_author_external' => $biblio_author_external;
375 my $sth_categories = $dbh->prepare(q{
376 select authorised_value, lib from authorised_values where category = 'BIBCAT'
378 $sth_categories->execute();
379 while( my $row = $sth_categories->fetchrow_hashref ) {
380 $category_label->{ $row->{authorised_value} } = $row->{lib};
383 debug 'category_label' => $category_label;
388 <meta charset="UTF-8">
389 <title>|, join(" ", @_), qq|</title>
390 <link href="style.css" type="text/css" rel="stylesheet" />
391 <script src="//code.jquery.com/jquery-1.11.2.js"></script>
392 <script src="filters.js"></script>
400 qq|<small style="color:gray">Zadnji puta osvježeno: |,
401 strftime("%Y-%m-%d %H:%M:%S\n", localtime()),
402 qq|</body>\n</html>\n|;
405 mkdir 'html' unless -d 'html';
407 open(my $index, '>:encoding(utf-8)', 'html/index.new');
408 print $index html_title('Bibliografija Filozofskog fakulteta');
410 my $first_letter = '';
412 debug 'authors' => \@authors;
415 my ($biblionumber) = @_;
416 return qq|<li class="y|, $biblio_year->{$biblionumber}, qq|">|,
417 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
418 biblioitem_html($biblionumber),
419 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
425 $unique->{$_}++ foreach @_;
426 return keys %$unique;
429 sub unique_biblionumber {
432 $biblio_year->{$b} <=> $biblio_year->{$a} ||
433 $biblio_full_name->{$a} cmp $biblio_full_name->{$b} ||
439 my ( $fh, $authid, $type, $label ) = @_;
441 return unless exists $authors->{$authid}->{$type};
443 print $fh qq|<a name="$type"><h2>$label</h2></a>\n|;
445 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
446 my $label = $category_label->{$category} || 'Bez kategorije';
447 print $fh qq|<a name="$type-$category"><h3>$label</h3></a>\n<ol>\n|;
448 foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
449 print $fh li_biblio( $biblionumber );
451 print $fh qq|</ol>\n|;
455 my @toc_type_label = (
456 'aut' => 'Primarno autorstvo',
457 'edt' => 'Uredništva',
458 'trl' => 'Prijevodi',
459 '_ostalo' => 'Ostalo',
463 sub count_author_years {
466 foreach my $type ( keys %{ $authors->{$authid} } ) {
467 # next if $type =~ m/^_/; # FIXME
468 foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) {
469 foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
470 $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++;
477 sub html_year_selection {
479 my @authids = unique @_;
481 debug 'html_year_selection authids=', [ @authids ];
483 print $fh qq|<span id="years">Godine:\n|;
484 my $type_cat_count = {};
487 foreach my $authid ( @authids ) {
488 $years = count_author_years( $years, $authid );
491 debug 'years' => $years;
493 foreach my $year ( sort { $b <=> $a } keys %$years ) {
494 print $fh qq|<label><input name="year_selection" value="$year" type=checkbox onClick="toggle_year($year, this)" checked="checked">$year</label> \n|;
495 foreach my $type_cat ( keys %{ $years->{$year} } ) {
496 my $count = scalar keys %{ $years->{$year}->{$type_cat} };
497 $years->{$year}->{$type_cat} = $count; # remove biblionumbers and use count
498 $type_cat_count->{ $type_cat } += $count;
499 my ($type,$cat) = split(/-/, $type_cat);
500 $type_cat_count->{_toc}->{$type}->{$cat}++;
501 $type_cat_count->{_toc_count}->{$type} += $count;
506 <input type=button value="all" onClick="all_years(1)">
507 <input type=button value="none" onClick="all_years(0)">
510 print $fh qq|</span>|;
515 var years = |, encode_json($years), q|;
517 var type_cat_count = |, encode_json($type_cat_count), q|;
523 debug 'type_cat_count' => $type_cat_count;
526 print $fh qq|<ul id="toc">\n|;
528 while ( $i < $#toc_type_label ) {
529 my $type = $toc_type_label[$i++] || die "type";
530 my $label = $toc_type_label[$i++] || die "label";
531 next unless exists $type_cat_count->{_toc}->{$type};
532 print $fh qq| <li class="toc" id="toc-$type"><a href="#$type">$label</a> <tt id="toc-count-$type">$type_cat_count->{_toc_count}->{$type}</tt></li>\n <ul>\n|;
533 foreach my $category ( sort keys %{ $type_cat_count->{_toc}->{$type} } ) {
534 my $label = $category_label->{$category} || 'Bez kategorije';
535 my $count = $type_cat_count->{ $type . '-' . $category };
536 my $cat_html = $category;
537 $cat_html =~ s/\./-/g;
538 print $fh qq| <li class="toc" id="toc-$category"><a href="#$type-$category">$label</a> <tt id="toc-count-$type-$cat_html">$count</tt></li>\n|;
540 print $fh qq| </ul>\n|;
542 print $fh qq|</ul>\n|;
548 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
550 my $first = substr( $row->{full_name}, 0, 1 );
551 if ( $first ne $first_letter ) {
552 print $index qq{</ul>\n} if $first_letter;
553 $first_letter = $first;
554 print $index qq{<h1>$first</h1>\n<ul>\n};
556 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
558 $authid_fullname->{ $row->{authid} } = $row->{full_name};
560 my $path = "html/$row->{authid}";
561 open(my $fh, '>:encoding(utf-8)', "$path.new");
562 print $fh html_title($row->{full_name}, "bibliografija");
563 print $fh qq|<h1>$row->{full_name} - bibliografija</h1>\n|;
565 html_year_selection $fh => $row->{authid};
568 while ( $i < $#toc_type_label ) {
569 my $type = $toc_type_label[$i++] || die "type";
570 my $label = $toc_type_label[$i++] || die "label";
571 author_html( $fh, $row->{authid}, $type => $label );
576 rename "$path.new", "$path.html";
580 print $index html_end;
582 rename 'html/index.new', 'html/index.html';
584 debug 'auth_header' => $auth_header;
586 debug 'authid_fullname' => $authid_fullname;
588 my $department_category_author;
589 foreach my $department ( sort keys %$auth_department ) {
590 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
591 my @categories = keys %{ $authors->{$authid}->{aut} };
592 push @categories, keys %{ $authors->{$authid}->{__sec} };
593 foreach my $category ( sort @categories ) {
594 push @{ $department_category_author->{$department}->{$category} }, $authid;
595 push @{ $department_category_author->{'AAA_ukupno'}->{$category} }, $authid if $department_in_sum->{$department};
596 if ( my $group = $department_in_group->{ $department } ) {
597 push @{ $department_category_author->{$group}->{$category} }, $authid;
599 $skip->{'department_not_in_group'}->{ $department }++;
605 debug 'department_category_author' => $department_category_author;
608 sub department_html {
609 my ( $fh, $department, $type, $label, $csv_fh ) = @_;
611 print $fh qq|<a name="$type"><h2>$label</h2></a>\n|;
613 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
615 my @authids = @{ $department_category_author->{$department}->{$category} };
616 next unless @authids;
618 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{$type}->{$category} } } grep { exists $authors->{$_}->{$type}->{$category} } @authids;
620 next unless @biblionumber;
622 my $cat_label = $category_label->{$category} || 'Bez kategorije';
623 print $fh qq|<a name="$type-$category"><h3>$cat_label</h3></a>\n<ol>\n|;
625 foreach my $bib_num ( @biblionumber ) {
626 my @li = li_biblio( $bib_num );
627 my $li_html = join('', @li);
628 $li_html =~ s{<a name="(col-\d+)"/a>}{<!-- $1 -->}gs;
635 foreach ( split(/<a name="col-/, $li[4]) ) {
636 if ( s{^(\d+)"></a>}{} ) {
641 warn "SKIPPED: Can't find col in [$_] from $li[4]" unless m/^<[^>]+>$/;
644 my $html = join("\t", @html);
646 $html =~ s{</?[^>]*>}{}gs;
647 $html =~ s{\s+$}{}gs;
648 print $csv_fh "$bib_num\t$year\t$type\t$label\t$category\t$cat_label\t$html\n";
657 mkdir 'html/departments' unless -d 'html/departments';
659 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
660 print $dep_fh html_title('Odsjeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
661 foreach my $department ( sort keys %$department_category_author ) {
662 my $dep = $department || 'Nema odsjeka';
663 my $dep_file = unac_string('utf-8',$dep);
664 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
665 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
667 print $fh html_title($department . ' bibliografija');
668 print $fh qq|<h1>$department bibliografija</h1>\n|;
671 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
672 push @authids, @{ $department_category_author->{$department}->{$category} };
674 html_year_selection $fh => @authids;
677 if ( $department eq 'AAA_ukupno' ) {
678 open($csv_fh, '>:encoding(utf-8)', "html/departments/$department.csv");
682 while ( $i < $#toc_type_label ) {
683 my $type = $toc_type_label[$i++] || die "type";
684 my $label = $toc_type_label[$i++] || die "label";
685 department_html( $fh, $department, $type, $label, $csv_fh );
688 close($csv_fh) if $csv_fh;
692 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
695 print $dep_fh qq|</ul>\n|, html_end;
697 rename 'html/departments/index.new', 'html/departments/index.html';
699 my $azvo_stat_biblio;
701 foreach my $department ( sort keys %$department_category_author ) {
702 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
703 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
704 my $group = $auth_group->{$authid};
706 push @{ $skip->{no_auth_group} }, $authid;
709 foreach my $type ( keys %{ $authors->{$authid} } ) {
710 next unless exists $authors->{$authid}->{$type}->{$category};
711 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{$group} }, @{ $authors->{$authid}->{$type}->{$category} };
712 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{''} }, @{ $authors->{$authid}->{$type}->{$category} };
715 foreach my $type ( keys %{ $azvo_stat_biblio->{ $department }->{ $category } } ) {
716 foreach my $group ( keys %{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } } ) {
717 my @biblios = unique_biblionumber @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{ $group } };
718 $azvo_stat_biblio->{ $department }->{ $category }->{ $type }->{ $group } = [ @biblios ];
724 debug 'azvo_stat_biblio' => $azvo_stat_biblio;
731 open(my $report, '<:encoding(utf-8)', 'nAZVO.txt');
734 if ( /^([^\t]+)\t+(.+)/ ) {
736 push @report_labels, $label;
737 my $type = [ map { m/\s+/ ? [ split(/\s+/,$_) ] : [ $_, 'aut' ] } split (/\s*\+\s*/, $2) ];
738 push @report_lines, [ $label, @$type ];
739 } elsif ( /^\t+([^\t]+):\t+(\d+)(\w*)\t*(.*)$/ ) {
740 push @{ $sub_labels->{$label} }, [ $1, $2, $3, $4 ];
742 pop (@report_labels) if ( $report_labels[ $#report_labels ] =~ m/^$label$/ ); # remove partial name
743 push @report_labels, $label . $sub_label;
749 debug 'report_lines', \@report_lines;
750 debug 'sub_labels', $sub_labels;
751 debug 'report_labels', \@report_labels;
753 my @departments = ( sort { lc($a) cmp lc($b) } keys %$azvo_stat_biblio );
755 debug 'departments' => \@departments;
758 $department2col->{ $departments[$_] } = $_ foreach ( 0 .. $#departments );
760 $label2row->{ $report_labels[$_] } = $_ foreach ( 0 .. $#report_labels );
765 my $label = shift @_;
766 my $department = shift @_;
767 my $group = shift @_;
768 my @biblionumbers = unique @_;
769 $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @biblionumbers;
770 $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @biblionumbers;
773 foreach my $group ( '', keys %$azvo_group_title ) {
775 foreach my $department ( @departments ) {
776 foreach my $line ( @report_lines ) {
777 my $label = $line->[0];
779 foreach ( 1 .. $#$line ) {
780 my ( $category, $type ) = @{ $line->[ $_ ] };
781 my $b = $azvo_stat_biblio->{ $department }->{$category}->{$type}->{$group};
782 push @biblionumbers, @$b if $b;
784 if ( $sub_labels->{$label} ) {
786 foreach my $biblionumber ( @biblionumbers ) {
787 my $data = $biblio_data->{$biblionumber} || die "can't find biblionumber $biblionumber";
788 foreach my $sub_label ( @{ $sub_labels->{$label} } ) {
789 my ( $sub_label, $field, $sf, $regex ) = @$sub_label;
791 push @{ $sub_stats->{ $sub_label } }, $biblionumber;
794 if ( $field < 100 ) {
795 if ( $data->{$field} =~ m/$regex/ ) {
796 push @{ $sub_stats->{ $sub_label } }, $biblionumber;
800 if ( exists $data->{$field}->[0]->{$sf} && $data->{$field}->[0]->{$sf} =~ m/$regex/ ) {
801 push @{ $sub_stats->{ $sub_label } }, $biblionumber;
807 foreach my $sub_label ( keys %$sub_stats ) {
808 my $full_label = $label . $sub_label;
809 table_count $full_label, $department, $group, @{ $sub_stats->{$sub_label} };
812 table_count $label, $department, $group, @biblionumbers;
819 #debug 'table', $table;
821 open(my $fh, '>:encoding(utf-8)', 'html/azvo.new');
822 open(my $fh2, '>:encoding(utf-8)', 'html/azvo2.new');
829 print $fh html_title('AZVO tablica - FFZG');
830 print $fh2 html_title('AZVO tablica - kolaboracija sa FFZG');
832 foreach my $group ( keys %{ $table->{ffzg} } ) {
834 print_fh "<h1>$group</h1>" if $group;
836 print_fh "<table border=1>\n";
837 print_fh "<tr><th></th>";
838 print_fh "<th>$_</th>" foreach @departments;
841 foreach my $row ( 0 .. $#{ $table->{ffzg}->{$group} } ) {
842 print_fh "<tr><th>", $report_labels[$row], "</th>\n";
843 foreach ( 0 .. $#departments ) {
845 print $fh $table->{ffzg}->{$group}->[ $row ]->[ $_ ] || '';
846 print $fh2 $table->{external}->{$group}->[ $row ]->[ $_ ] || '';
852 print_fh "</table>\n";
859 rename 'html/azvo.new', 'html/azvo.html';
860 rename 'html/azvo2.new', 'html/azvo2.html';
864 foreach my $department ( @departments ) {
865 foreach my $line ( @report_lines ) {
866 my $label = $line->[0];
868 foreach ( 1 .. $#$line ) {
869 my ( $category, $type ) = @{ $line->[ $_ ] };
871 foreach my $authid ( @{ $auth_department->{$department} } ) {
872 next unless exists $authors->{$authid}->{$type}->{$category};
873 my @biblionumbers = grep { $biblio_year->{$_} >= 2012 } @{ $authors->{$authid}->{$type}->{$category} };
875 $dep_au_count->{ $department }->{ $authid }->{ $label } += scalar @biblionumbers;
881 debug 'dep_au_count', $dep_au_count;
883 mkdir 'html/dep_au' unless -d 'html/dep_au';
884 open(my $dep_fh, '>', 'html/dep_au/index.new');
885 print $dep_fh html_title('Odsjeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
886 foreach my $department ( sort keys %{ $dep_au_count } ) {
888 my $dep = $department || 'Nema odsjeka';
889 my $dep_file = unac_string('utf-8',$dep);
890 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
891 open(my $fh, '>:encoding(utf-8)', "html/dep_au/$dep_file.new");
893 print $fh html_title($department . ' bibliografija tablica');
896 print $fh qq|<table>\n<tr><th></th><th>|
897 , join('</th><th>', @report_labels )
901 foreach my $authid ( keys %{ $dep_au_count->{ $department } } ) {
902 print $fh qq|<tr><th>$authid_fullname->{$authid}</th><th>|
903 , join('</th><th>', map { $dep_au_count->{$department}->{$authid}->{$_} || '-' } @report_labels )
909 print $fh qq|</table>\n|;
913 rename "html/dep_au/$dep_file.new", "html/dep_au/$dep_file.html";
916 print $dep_fh html_end;
918 rename "html/dep_au/index.new", "html/dep_au/index.html";