modified report for departments by authors
[koha-bibliografija] / html.pl
diff --git a/html.pl b/html.pl
index 9b1f23d..e9194b3 100755 (executable)
--- a/html.pl
+++ b/html.pl
@@ -114,7 +114,7 @@ while( my $row = $sth_auth->fetchrow_hashref ) {
 debug 'department_in_group' => $department_in_group;
 
 foreach my $department ( keys %$department_in_sum ) {
-       $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
+#      $department_in_sum->{$department} = 0 unless $department =~ m/(centar|croaticum|katedra|odsjek)/i;
 }
 
 debug 'auth_department' => $auth_department;
@@ -128,10 +128,11 @@ my $marcxml;
 
 my $sth_select_authors  = $dbh->prepare(q{
 select
-       biblionumber,
+       biblioitems.biblionumber,
        itemtype,
-       marcxml
+       metadata as marcxml
 from biblioitems
+join biblio_metadata on (biblio_metadata.biblionumber = biblioitems.biblionumber)
 where
        agerestriction > 0
 });
@@ -466,7 +467,7 @@ sub count_author_years {
 #              next if $type =~ m/^_/; # FIXME
                foreach my $category ( keys %{ $authors->{$authid}->{$type} } ) {
                        foreach my $biblionumber ( unique_biblionumber @{ $authors->{$authid}->{$type}->{$category} } ) {
-                               push @{ $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category } }, $biblionumber;
+                               $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++;
                        }
                }
        }
@@ -492,7 +493,8 @@ sub html_year_selection {
        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>&nbsp;\n|;
                foreach my $type_cat ( keys %{ $years->{$year} } ) {
-                       my $count = scalar unique @{ $years->{$year}->{$type_cat} };
+                       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}++;
@@ -541,6 +543,7 @@ var type_cat_count = |, encode_json($type_cat_count), q|;
 
 }
 
+my $authid_fullname;
 
 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
 
@@ -552,6 +555,8 @@ foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
        }
        print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
 
+       $authid_fullname->{ $row->{authid} } = $row->{full_name};
+
        my $path = "html/$row->{authid}";
        open(my $fh, '>:encoding(utf-8)', "$path.new");
        print $fh html_title($row->{full_name}, "bibliografija");
@@ -578,6 +583,7 @@ rename 'html/index.new', 'html/index.html';
 
 debug 'auth_header' => $auth_header;
 
+debug 'authid_fullname' => $authid_fullname;
 
 my $department_category_author;
 foreach my $department ( sort keys %$auth_department ) {
@@ -600,7 +606,7 @@ debug 'department_category_author' => $department_category_author;
 
 
 sub department_html {
-       my ( $fh, $department, $type, $label ) = @_;
+       my ( $fh, $department, $type, $label, $csv_fh ) = @_;
 
        print $fh qq|<a name="$type"><h2>$label</h2></a>\n|;
 
@@ -613,10 +619,34 @@ sub department_html {
 
                next unless @biblionumber;
 
-               my $label = $category_label->{$category} || 'Bez kategorije';
-               print $fh qq|<a name="$type-$category"><h3>$label</h3></a>\n<ol>\n|;
+               my $cat_label = $category_label->{$category} || 'Bez kategorije';
+               print $fh qq|<a name="$type-$category"><h3>$cat_label</h3></a>\n<ol>\n|;
+
+               foreach my $bib_num ( @biblionumber ) {
+                       my @li = li_biblio( $bib_num );
+                       my $li_html = join('', @li);
+                       $li_html =~ s{<a name="(col-\d+)"/a>}{<!-- $1 -->}gs;
+                       print $fh $li_html;
 
-               print $fh li_biblio( $_ ) foreach @biblionumber;
+                       next unless $csv_fh;
+
+                       my $year = $li[1];
+                       my @html;
+                       foreach ( split(/<a name="col-/, $li[4]) ) {
+                               if ( s{^(\d+)"></a>}{} ) {
+                                       my $nr = $1;
+                                       s{\s+}{ }gs;
+                                       $html[$nr] = $_;
+                               } else {
+                                       warn "SKIPPED: Can't find col in [$_] from $li[4]" unless m/^<[^>]+>$/;
+                               }
+                       }
+                       my $html = join("\t", @html);
+
+                       $html =~ s{</?[^>]*>}{}gs;
+                       $html =~ s{\s+$}{}gs;
+                       print $csv_fh "$bib_num\t$year\t$type\t$label\t$category\t$cat_label\t$html\n";
+               }
 
                print $fh qq|</ol>|;
        }
@@ -643,16 +673,24 @@ foreach my $department ( sort keys %$department_category_author ) {
        }
        html_year_selection $fh => @authids;
 
+       my $csv_fh;
+       if ( $department eq 'AAA_ukupno' ) {
+               open($csv_fh, '>:encoding(utf-8)', "html/departments/$department.csv");
+       }
+
        my $i = 0;
        while ( $i < $#toc_type_label ) {
                my $type  = $toc_type_label[$i++] || die "type";
                my $label = $toc_type_label[$i++] || die "label";
-               department_html( $fh, $department, $type, $label );
+               department_html( $fh, $department, $type, $label, $csv_fh );
        }
 
+       close($csv_fh) if $csv_fh;
+
        print $fh html_end;
        close($fh);
        rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
+
 }
 print $dep_fh qq|</ul>\n|, html_end;
 close($dep_fh);
@@ -690,7 +728,7 @@ my @report_labels;
 
 my $label;
 my $sub_labels;
-open(my $report, '<:encoding(utf-8)', 'AZVO.txt');
+open(my $report, '<:encoding(utf-8)', 'nAZVO.txt');
 while( <$report> ) {
        chomp;
        if ( /^([^\t]+)\t+(.+)/ ) {
@@ -778,7 +816,7 @@ foreach my $department ( @departments ) {
 
 } # group
 
-debug 'table', $table;
+#debug 'table', $table;
 
 open(my $fh, '>:encoding(utf-8)', 'html/azvo.new');
 open(my $fh2, '>:encoding(utf-8)', 'html/azvo2.new');
@@ -821,5 +859,63 @@ close($fh2);
 rename 'html/azvo.new', 'html/azvo.html';
 rename 'html/azvo2.new', 'html/azvo2.html';
 
+my $dep_au_count;
+
+foreach my $department ( @departments ) {
+       foreach my $line ( @report_lines ) {
+               my $label = $line->[0];
+               my @biblionumbers;
+               foreach ( 1 .. $#$line ) {
+                       my ( $category, $type ) = @{ $line->[ $_ ] };
+
+                       foreach my $authid ( @{ $auth_department->{$department} } ) {
+                               next unless exists $authors->{$authid}->{$type}->{$category};
+                               my @biblionumbers = @{ $authors->{$authid}->{$type}->{$category} };
+
+                               $dep_au_count->{ $department }->{ $authid }->{ $label } += scalar @biblionumbers;
+                       }
+               }
+       }
+}
+
+debug 'dep_au_count', $dep_au_count;
+
+mkdir 'html/dep_au' unless -d 'html/dep_au';
+open(my $dep_fh, '>', 'html/dep_au/index.new');
+print $dep_fh html_title('Odsjeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
+foreach my $department ( sort keys %{ $dep_au_count } ) {
+
+       my $dep = $department || 'Nema odsjeka';
+       my $dep_file = unac_string('utf-8',$dep);
+       print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
+       open(my $fh, '>:encoding(utf-8)', "html/dep_au/$dep_file.new");
+
+       print $fh html_title($department . ' bibliografija tablica');
+       
+       # FIXME table
+       print $fh qq|<table>\n<tr><th></th><th>|
+               , join('</th><th>', @report_labels )
+               , qq|</th></tr>\n|
+               ;
+
+       foreach my $authid ( keys %{ $dep_au_count->{ $department } } ) {
+               print $fh qq|<tr><th>$authid_fullname->{$authid}</th><th>|
+                               , join('</th><th>', map { $dep_au_count->{$department}->{$authid}->{$_} || '-' } @report_labels )
+                               , qq|</th></tr>\n|
+                               ;
+       }
+
+
+       print $fh qq|</table>\n|;
+
+       print $fh html_end;
+       close($fh);
+       rename "html/dep_au/$dep_file.new", "html/dep_au/$dep_file.html";
+}
+
+print $dep_fh html_end;
+close($dep_fh);
+rename "html/dep_au/index.new", "html/dep_au/index.html";
+
 unlink $pid_file;