+ print $fh qq|</ol>\n|;
+ }
+}
+
+my @toc_type_label = (
+'aut' => 'Primarno autorstvo',
+'edt' => 'Uredništva',
+'trl' => 'Prijevodi',
+'_ostalo' => 'Ostalo',
+);
+
+
+sub count_author_years {
+ my $years = shift;
+ my ($authid) = @_;
+ foreach my $type ( keys %{ $authors->{$authid} } ) {
+# next if $type =~ m/^_/; # FIXME
+ foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) {
+ foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
+ $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++;
+ }
+ }
+ }
+ return $years;
+}
+
+sub html_year_selection {
+ my $fh = shift;
+ my @authids = unique @_;
+
+ debug 'html_year_selection authids=', [ @authids ];
+
+ print $fh qq|<span id="years">Godine:\n|;
+ my $type_cat_count = {};
+ my $years;
+
+ foreach my $authid ( @authids ) {
+ $years = count_author_years( $years, $authid );
+ }
+
+ debug 'years' => $years;
+
+ foreach my $year ( sort { $b <=> $a } keys %$years ) {
+ print $fh qq|<label><input name="year_selection" value="$year" type=checkbox onClick="toggle_year($year, this)" checked="checked">$year</label> \n|;
+ foreach my $type_cat ( keys %{ $years->{$year} } ) {
+ my $count = scalar keys %{ $years->{$year}->{$type_cat} };
+ $years->{$year}->{$type_cat} = $count; # remove biblionumbers and use count
+ $type_cat_count->{ $type_cat } += $count;
+ my ($type,$cat) = split(/-/, $type_cat);
+ $type_cat_count->{_toc}->{$type}->{$cat}++;
+ $type_cat_count->{_toc_count}->{$type} += $count;
+ }
+ }
+
+ print $fh qq|
+<input type=button value="all" onClick="all_years(1)">
+<input type=button value="none" onClick="all_years(0)">
+ |;
+
+ print $fh qq|</span>|;
+
+ print $fh q|
+<script>
+
+var years = |, encode_json($years), q|;
+
+var type_cat_count = |, encode_json($type_cat_count), q|;
+
+</script>
+
+ |;
+
+ debug 'type_cat_count' => $type_cat_count;
+
+ # TOC
+ print $fh qq|<ul id="toc">\n|;
+ my $i = 0;
+ while ( $i < $#toc_type_label ) {
+ my $type = $toc_type_label[$i++] || die "type";
+ my $label = $toc_type_label[$i++] || die "label";
+ next unless exists $type_cat_count->{_toc}->{$type};
+ 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|;
+ foreach my $category ( sort keys %{ $type_cat_count->{_toc}->{$type} } ) {
+ my $label = $category_label->{$category} || 'Bez kategorije';
+ my $count = $type_cat_count->{ $type . '-' . $category };
+ my $cat_html = $category;
+ $cat_html =~ s/\./-/g;
+ 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|;
+ }
+ print $fh qq| </ul>\n|;