X-Git-Url: http://git.rot13.org/?p=koha-bibliografija;a=blobdiff_plain;f=html.pl;h=3d9cfce0e96fcec5c2542e6ee1011e4f403af5c6;hp=ad942ffeb8d5a918475e0cc029b3fddf904e8e09;hb=7fc6c0fdd35f196bb3dfc317fdd4c19816f2eb55;hpb=0940e8776aee0223107b22529af6d5ea52703f47 diff --git a/html.pl b/html.pl index ad942ff..3d9cfce 100755 --- a/html.pl +++ b/html.pl @@ -21,6 +21,20 @@ use C4::Context; use XML::LibXML; use XML::LibXSLT; +my $pid_file = '/dev/shm/bibliografija.pid'; +{ + if ( -e $pid_file ) { + open(my $fh, '<', $pid_file); + my $pid = <$fh>; + no autodie; # it will die on kill + kill 0, $pid || die "$0 allready running as pid $pid"; + } + open(my $fh, '>', $pid_file); + print $fh $$; + close($fh); +} + + my $dbh = C4::Context->dbh; sub debug { @@ -100,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; @@ -449,10 +463,10 @@ sub count_author_years { my $years = shift; my ($authid) = @_; foreach my $type ( keys %{ $authors->{$authid} } ) { - next if $type =~ m/^_/; +# 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 }++; + $years->{ $biblio_year->{ $biblionumber } }->{ $type . '-' . $category }->{ $biblionumber }++; } } } @@ -478,10 +492,12 @@ sub html_year_selection { foreach my $year ( sort { $b <=> $a } keys %$years ) { print $fh qq| \n|; foreach my $type_cat ( keys %{ $years->{$year} } ) { - $type_cat_count->{ $type_cat } += $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}++; - $type_cat_count->{_toc_count}->{$type} += $years->{$year}->{$type_cat}; + $type_cat_count->{_toc_count}->{$type} += $count; } } @@ -585,7 +601,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|

$label

\n|; @@ -598,10 +614,33 @@ sub department_html { next unless @biblionumber; - my $label = $category_label->{$category} || 'Bez kategorije'; - print $fh qq|

$label

\n
    \n|; + my $cat_label = $category_label->{$category} || 'Bez kategorije'; + print $fh qq|

    $cat_label

    \n
      \n|; + + foreach my $bib_num ( @biblionumber ) { + my @li = li_biblio( $bib_num ); + my $li_html = join('', @li); + $li_html =~ s{}{}gs; + print $fh $li_html; + + next unless $csv_fh; + + my $year = $li[1]; + my @html; + foreach ( split(/}{} ) { + s{\s+}{ }gs; + $html[$1] = $_; + } else { + warn "SKIPPED: Can't find col in [$_] from $li[4]" unless m/^<[^>]+>$/; + } + } + my $html = join("\t", @html); - print $fh li_biblio( $_ ) foreach @biblionumber; + $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|
    |; } @@ -628,16 +667,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|\n|, html_end; close($dep_fh); @@ -806,3 +853,5 @@ close($fh2); rename 'html/azvo.new', 'html/azvo.html'; rename 'html/azvo2.new', 'html/azvo2.html'; +unlink $pid_file; +