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 {
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;
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
});
qq|</li>\n|;
}
+sub unique {
+ my $unique;
+ $unique->{$_}++ foreach @_;
+ return keys %$unique;
+}
+
sub unique_biblionumber {
- my @v = @_;
- my $u;
- $u->{$_}++ foreach @v;
+ my @v = unique @_;
return sort {
$biblio_year->{$b} <=> $biblio_year->{$a} ||
$biblio_full_name->{$a} cmp $biblio_full_name->{$b} ||
$a <=> $b
- } keys %$u;
+ } @v;
}
sub author_html {
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 }++;
}
}
}
sub html_year_selection {
my $fh = shift;
- my @authids = @_;
+ my @authids = unique @_;
debug 'html_year_selection authids=', [ @authids ];
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} } ) {
- $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;
}
}
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|;
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;
+
+ next unless $csv_fh;
- print $fh li_biblio( $_ ) foreach @biblionumber;
+ 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>|;
}
}
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);
my $label = shift @_;
my $department = shift @_;
my $group = shift @_;
- my @biblionumbers = @_;
- my $unique;
- $unique->{$_}++ foreach @biblionumbers;
- my @bibs = keys %$unique;
- $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @bibs;
- $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @bibs;
+ my @biblionumbers = unique @_;
+ $table->{ffzg}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar @biblionumbers;
+ $table->{external}->{$group}->[ $label2row->{ $label } ]->[ $department2col->{$department} ] = scalar grep { $biblio_author_external->{$_} } @biblionumbers;
}
foreach my $group ( '', keys %$azvo_group_title ) {
rename 'html/azvo.new', 'html/azvo.html';
rename 'html/azvo2.new', 'html/azvo2.html';
+unlink $pid_file;
+