3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
9 use Data::Dump qw(dump);
15 use lib '/srv/koha_ffzg';
20 my $dbh = C4::Context->dbh;
23 my ($title, $data) = @_;
24 print "# $title ",dump($data), $/ if $ENV{DEBUG};
27 my $xslfilename = 'compact.xsl';
35 my $sth_auth = $dbh->prepare(q{
38 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name,
39 ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="a"]') as department
44 while( my $row = $sth_auth->fetchrow_hashref ) {
45 if ( $row->{department} !~ m/Filozofski fakultet u Zagrebu/ ) {
46 push @{ $skip->{nije_ffzg} }, $row;
49 $auth_header->{ $row->{authid} } = $row->{full_name};
50 $row->{department} =~ s/, Filozofski fakultet u Zagrebu.*$//;
51 $row->{department} =~ s/^.+\.\s*//;
53 push @{ $auth_department->{ $row->{department} } }, $row->{authid};
58 debug 'auth_department' => $auth_department;
64 my $sth_select_authors = $dbh->prepare(q{
75 -- ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
76 -- ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
77 -- ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
79 -- and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
80 -- order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
86 my $parser = XML::LibXML->new();
87 $parser->recover_silently(0); # don't die when you find &, >, etc
88 my $style_doc = $parser->parse_file($xslfilename);
89 my $xslt = XML::LibXSLT->new();
90 my $parsed = $xslt->parse_stylesheet($style_doc);
95 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
98 my ($biblionumber, $parse_only) = @_;
100 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber} && ! $parse_only;
102 my $xmlrecord = $marcxml->{$biblionumber} || confess "missing $biblionumber marcxml";
104 print $xml_fh $xmlrecord if $ENV{XML};
106 my $source = eval { $parser->parse_string($xmlrecord) };
108 # warn "SKIP $biblionumber corrupt XML";
109 push @{ $skip->{XML_corrupt} }, $biblionumber;
114 $biblio_parsed->{$biblionumber} = $source;
118 my $transformed = $parsed->transform($source);
119 $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
121 delete $biblio_parsed->{$biblionumber};
123 return $biblio_html->{$biblionumber};
126 $sth_select_authors->execute();
127 while( my $row = $sth_select_authors->fetchrow_hashref ) {
128 # warn dump($row),$/;
132 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
134 my $doc = biblioitem_html( $row->{biblionumber}, 1 );
136 # warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
140 my $root = $doc->documentElement;
142 my @leaders = $root->getElementsByLocalName('leader');
144 my $leader = $leaders[0]->textContent;
145 warn "leader $leader\n";
158 foreach my $elt ($root->getChildrenByLocalName('*')) {
159 my $tag = $elt->getAttribute('tag');
161 next unless exists $extract->{ $tag };
163 if ($elt->localname eq 'controlfield') {
164 if ( $tag eq '008' ) {
165 my $year = substr($elt->textContent, 7, 4 );
166 if ( $year !~ m/^\d+$/ ) {
168 push @{ $skip->{invalid_year} }, $row->{biblionumber};
170 $biblio_year->{ $row->{biblionumber} } = $data->{year} = $year;
173 } elsif ($elt->localname eq 'datafield') {
175 foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
176 my $sf = $sfelt->getAttribute('code');
177 next unless $sf =~ m/$extract->{$tag}/;
178 if ( exists $sf_data->{$sf} ) {
179 $sf_data->{$sf} .= " " . $sfelt->textContent();
181 $sf_data->{$sf} = $sfelt->textContent();
184 push @{ $data->{$tag} }, $sf_data if $sf_data;
188 if ( $data->{year} < 2008 ) {
189 push @{ $skip->{year_lt_2008} }, $row->{biblionumber};
191 } elsif ( $data->{year} > 2013 ) {
192 push @{ $skip->{year_gt_2013} }, $row->{biblionumber};
196 # warn "# ", $row->{biblionumber}, " data ",dump($data);
198 my $category = $data->{942}->[0]->{'t'};
200 # warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
201 push @{ $skip->{no_category} }, $row->{biblionumber};
208 if ( exists $data->{100} ) {
209 my @first_author = map { $_->{'9'} } @{ $data->{100} };
210 foreach my $authid ( @first_author ) {
211 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
219 if ( exists $data->{700} ) {
220 foreach my $auth ( @{ $data->{700} } ) {
221 my $authid = $auth->{9} || next;
222 my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
224 $type_stats->{$type}++;
226 if ( $type =~ m/(edt|trl|com|ctb)/ ) {
227 push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
228 push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber};
229 } elsif ( $type =~ m/aut/ ) {
231 $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
233 $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
235 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
238 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
241 # warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
242 $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
249 debug 'authors' => $authors;
250 debug 'type_stats' => $type_stats;
251 debug 'skip' => $skip;
252 debug 'biblio_year' => $biblio_year;
255 my $sth_categories = $dbh->prepare(q{
256 select authorised_value, lib from authorised_values where category = 'BIBCAT'
258 $sth_categories->execute();
259 while( my $row = $sth_categories->fetchrow_hashref ) {
260 $category_label->{ $row->{authorised_value} } = $row->{lib};
263 debug 'category_label' => $category_label;
268 <meta charset="UTF-8">
269 <title>|, join(" ", @_), qq|</title>
270 <link href="style.css" type="text/css" rel="stylesheet" />
277 return qq|</body>\n</html\n|;
280 mkdir 'html' unless -d 'html';
282 open(my $index, '>:encoding(utf-8)', 'html/index.new');
283 print $index html_title('Bibliografija Filozofskog fakulteta');
285 my $first_letter = '';
287 debug 'authors' => \@authors;
290 my ($biblionumber) = @_;
292 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
293 biblioitem_html($biblionumber),
294 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
299 my ( $fh, $authid, $type, $label ) = @_;
301 return unless exists $authors->{$authid}->{$type};
303 print $fh qq|<h2>$label</h2>\n|;
305 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
306 my $label = $category_label->{$category} || 'Bez kategorije';
307 print $fh qq|<h3>$label</h3>\n<ul>\n|;
308 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
309 print $fh li_biblio( $biblionumber );
311 print $fh qq|</ul>\n|;
315 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
317 my $first = substr( $row->{full_name}, 0, 1 );
318 if ( $first ne $first_letter ) {
319 print $index qq{</ul>\n} if $first_letter;
320 $first_letter = $first;
321 print $index qq{<h1>$first</h1>\n<ul>\n};
323 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
325 my $path = "html/$row->{authid}";
326 open(my $fh, '>:encoding(utf-8)', "$path.new");
327 print $fh html_title($row->{full_name}, "bibliografija");
328 print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
330 author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
331 author_html( $fh, $row->{authid}, 'sec' => 'Uredništva, prijevodi, krička izdanja' );
335 rename "$path.new", "$path.html";
339 print $index html_end;
341 rename 'html/index.new', 'html/index.html';
343 debug 'auth_header' => $auth_header;
346 my $department_category_author;
347 foreach my $department ( sort keys %$auth_department ) {
348 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
349 my @categories = keys %{ $authors->{$authid}->{aut} };
350 push @categories, keys %{ $authors->{$authid}->{sec} };
351 foreach my $category ( sort @categories ) {
352 push @{ $department_category_author->{$department}->{$category} }, $authid;
357 debug 'department_category_author' => $department_category_author;
359 mkdir 'html/departments' unless -d 'html/departments';
361 sub unique_biblionumber {
364 $u->{$_}++ foreach @v;
365 return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $a <=> $b } keys %$u;
368 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
369 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
370 foreach my $department ( sort keys %$department_category_author ) {
371 my $dep = $department || 'Nema odsjeka';
372 my $dep_file = unac_string('utf-8',$dep);
373 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
374 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
376 print $fh html_title($department . ' bibliografija');
377 print $fh qq|<h1>$department bibliografija</h1>\n|;
379 print $fh qq|<h2>Primarno autorstvo</h2>\n|;
381 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
383 my @authids = @{ $department_category_author->{$department}->{$category} };
384 next unless @authids;
386 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{aut}->{$category} } } grep { exists $authors->{$_}->{aut}->{$category} } @authids;
388 $unique->{$_}++ foreach @biblionumber;
390 next unless @biblionumber;
392 my $label = $category_label->{$category} || 'Bez kategorije';
393 print $fh qq|<h3>$label</h3>\n<ul>\n|;
395 print $fh li_biblio( $_ ) foreach @biblionumber;
401 print $fh qq|<h2>Sekundarno autorstvo</h2>\n|;
403 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
405 my @authids = @{ $department_category_author->{$department}->{$category} };
406 next unless @authids;
408 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{sec}->{$category} } } grep { exists $authors->{$_}->{sec}->{$category} } @authids;
410 next unless @biblionumber;
412 my $label = $category_label->{$category} || 'Bez kategorije';
413 print $fh qq|<h3>$label</h3>\n<ul>\n|;
415 print $fh li_biblio( $_ ) foreach @biblionumber;
423 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
425 print $dep_fh qq|</ul>\n|, html_end;
427 rename 'html/departments/index.new', 'html/departments/index.html';
429 my $azvo_stat_authors;
430 my $azvo_stat_biblio;
432 foreach my $department ( sort keys %$department_category_author ) {
433 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
434 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
435 foreach my $type ( keys %{ $authors->{$authid} } ) {
436 next unless exists $authors->{$authid}->{$type}->{$category};
437 $azvo_stat_authors->{ $department }->{ $category }->{ $type } += $#{ $authors->{$authid}->{$type}->{$category} } + 1;
438 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } }, @{ $authors->{$authid}->{$type}->{$category} };
441 foreach my $type ( keys %{ $azvo_stat_biblio->{ $department }->{ $category } } ) {
442 my @biblios = unique_biblionumber @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } };
443 $azvo_stat_biblio->{ $department }->{ $category }->{ $type } = $#biblios + 1;
448 debug 'azvo_stat_authors' => $azvo_stat_authors;
449 debug 'azvo_stat_biblio' => $azvo_stat_biblio;
452 open(my $fh, '>', 'html/azvo.new');
457 rename 'html/azvo.new', 'html/azvo.html';