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);
94 my $biblio_in_database;
96 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
99 my ($biblionumber, $parse_only) = @_;
101 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber} && ! $parse_only;
103 my $xmlrecord = $marcxml->{$biblionumber} || confess "missing $biblionumber marcxml";
105 print $xml_fh $xmlrecord if $ENV{XML};
107 my $source = eval { $parser->parse_string($xmlrecord) };
109 # warn "SKIP $biblionumber corrupt XML";
110 push @{ $skip->{XML_corrupt} }, $biblionumber;
115 $biblio_parsed->{$biblionumber} = $source;
119 my $transformed = $parsed->transform($source);
120 $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
122 delete $biblio_parsed->{$biblionumber};
124 return $biblio_html->{$biblionumber};
127 $sth_select_authors->execute();
128 while( my $row = $sth_select_authors->fetchrow_hashref ) {
129 # warn dump($row),$/;
133 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
135 my $doc = biblioitem_html( $row->{biblionumber}, 1 );
137 # warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
141 my $root = $doc->documentElement;
143 my @leaders = $root->getElementsByLocalName('leader');
145 my $leader = $leaders[0]->textContent;
146 warn "leader $leader\n";
159 foreach my $elt ($root->getChildrenByLocalName('*')) {
160 my $tag = $elt->getAttribute('tag');
162 next unless exists $extract->{ $tag };
164 if ($elt->localname eq 'controlfield') {
165 if ( $tag eq '008' ) {
166 my $year = substr($elt->textContent, 7, 4 );
167 if ( $year !~ m/^\d+$/ ) {
169 push @{ $skip->{invalid_year} }, $row->{biblionumber};
171 $biblio_year->{ $row->{biblionumber} } = $data->{year} = $year;
174 } elsif ($elt->localname eq 'datafield') {
176 foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
177 my $sf = $sfelt->getAttribute('code');
178 next unless $sf =~ m/$extract->{$tag}/;
179 if ( exists $sf_data->{$sf} ) {
180 $sf_data->{$sf} .= " " . $sfelt->textContent();
182 $sf_data->{$sf} = $sfelt->textContent();
185 push @{ $data->{$tag} }, $sf_data if $sf_data;
189 if ( $data->{year} < 2008 ) {
190 push @{ $skip->{year_lt_2008} }, $row->{biblionumber};
192 } elsif ( $data->{year} > 2013 ) {
193 push @{ $skip->{year_gt_2013} }, $row->{biblionumber};
197 # warn "# ", $row->{biblionumber}, " data ",dump($data);
199 my $category = $data->{942}->[0]->{'t'};
201 # warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
202 push @{ $skip->{no_category} }, $row->{biblionumber};
206 if ( my $in_database = $data->{942}->[0]->{'r'} ) {
207 $biblio_in_database->{ $row->{biblionumber} } = $in_database;
212 if ( exists $data->{100} ) {
213 my @first_author = map { $_->{'9'} } @{ $data->{100} };
214 foreach my $authid ( @first_author ) {
215 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
223 if ( exists $data->{700} ) {
224 foreach my $auth ( @{ $data->{700} } ) {
225 my $authid = $auth->{9} || next;
226 my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
228 $type_stats->{$type}++;
230 if ( $type =~ m/(edt|trl|com|ctb)/ ) {
231 push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
232 push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber};
233 } elsif ( $type =~ m/aut/ ) {
235 $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
237 $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
239 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
242 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
245 # warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
246 $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
253 debug 'authors' => $authors;
254 debug 'type_stats' => $type_stats;
255 debug 'skip' => $skip;
256 debug 'biblio_year' => $biblio_year;
257 debug 'biblio_in_database' => $biblio_in_database;
260 my $sth_categories = $dbh->prepare(q{
261 select authorised_value, lib from authorised_values where category = 'BIBCAT'
263 $sth_categories->execute();
264 while( my $row = $sth_categories->fetchrow_hashref ) {
265 $category_label->{ $row->{authorised_value} } = $row->{lib};
268 debug 'category_label' => $category_label;
273 <meta charset="UTF-8">
274 <title>|, join(" ", @_), qq|</title>
275 <link href="style.css" type="text/css" rel="stylesheet" />
282 return qq|</body>\n</html\n|;
285 mkdir 'html' unless -d 'html';
287 open(my $index, '>:encoding(utf-8)', 'html/index.new');
288 print $index html_title('Bibliografija Filozofskog fakulteta');
290 my $first_letter = '';
292 debug 'authors' => \@authors;
295 my ($biblionumber) = @_;
297 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
298 biblioitem_html($biblionumber),
299 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
304 my ( $fh, $authid, $type, $label ) = @_;
306 return unless exists $authors->{$authid}->{$type};
308 print $fh qq|<h2>$label</h2>\n|;
310 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
311 my $label = $category_label->{$category} || 'Bez kategorije';
312 print $fh qq|<h3>$label</h3>\n<ul>\n|;
313 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
314 print $fh li_biblio( $biblionumber );
316 print $fh qq|</ul>\n|;
320 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
322 my $first = substr( $row->{full_name}, 0, 1 );
323 if ( $first ne $first_letter ) {
324 print $index qq{</ul>\n} if $first_letter;
325 $first_letter = $first;
326 print $index qq{<h1>$first</h1>\n<ul>\n};
328 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
330 my $path = "html/$row->{authid}";
331 open(my $fh, '>:encoding(utf-8)', "$path.new");
332 print $fh html_title($row->{full_name}, "bibliografija");
333 print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
335 author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
336 author_html( $fh, $row->{authid}, 'sec' => 'Uredništva, prijevodi, krička izdanja' );
340 rename "$path.new", "$path.html";
344 print $index html_end;
346 rename 'html/index.new', 'html/index.html';
348 debug 'auth_header' => $auth_header;
351 my $department_category_author;
352 foreach my $department ( sort keys %$auth_department ) {
353 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
354 my @categories = keys %{ $authors->{$authid}->{aut} };
355 push @categories, keys %{ $authors->{$authid}->{sec} };
356 foreach my $category ( sort @categories ) {
357 push @{ $department_category_author->{$department}->{$category} }, $authid;
362 debug 'department_category_author' => $department_category_author;
364 mkdir 'html/departments' unless -d 'html/departments';
366 sub unique_biblionumber {
369 $u->{$_}++ foreach @v;
370 return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $a <=> $b } keys %$u;
373 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
374 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
375 foreach my $department ( sort keys %$department_category_author ) {
376 my $dep = $department || 'Nema odsjeka';
377 my $dep_file = unac_string('utf-8',$dep);
378 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
379 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
381 print $fh html_title($department . ' bibliografija');
382 print $fh qq|<h1>$department bibliografija</h1>\n|;
384 print $fh qq|<h2>Primarno autorstvo</h2>\n|;
386 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
388 my @authids = @{ $department_category_author->{$department}->{$category} };
389 next unless @authids;
391 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{aut}->{$category} } } grep { exists $authors->{$_}->{aut}->{$category} } @authids;
393 $unique->{$_}++ foreach @biblionumber;
395 next unless @biblionumber;
397 my $label = $category_label->{$category} || 'Bez kategorije';
398 print $fh qq|<h3>$label</h3>\n<ul>\n|;
400 print $fh li_biblio( $_ ) foreach @biblionumber;
406 print $fh qq|<h2>Sekundarno autorstvo</h2>\n|;
408 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
410 my @authids = @{ $department_category_author->{$department}->{$category} };
411 next unless @authids;
413 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{sec}->{$category} } } grep { exists $authors->{$_}->{sec}->{$category} } @authids;
415 next unless @biblionumber;
417 my $label = $category_label->{$category} || 'Bez kategorije';
418 print $fh qq|<h3>$label</h3>\n<ul>\n|;
420 print $fh li_biblio( $_ ) foreach @biblionumber;
428 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
430 print $dep_fh qq|</ul>\n|, html_end;
432 rename 'html/departments/index.new', 'html/departments/index.html';
434 my $azvo_stat_authors;
435 my $azvo_stat_biblio;
437 foreach my $department ( sort keys %$department_category_author ) {
438 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
439 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
440 foreach my $type ( keys %{ $authors->{$authid} } ) {
441 next unless exists $authors->{$authid}->{$type}->{$category};
442 $azvo_stat_authors->{ $department }->{ $category }->{ $type } += $#{ $authors->{$authid}->{$type}->{$category} } + 1;
443 push @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } }, @{ $authors->{$authid}->{$type}->{$category} };
446 foreach my $type ( keys %{ $azvo_stat_biblio->{ $department }->{ $category } } ) {
447 my @biblios = unique_biblionumber @{ $azvo_stat_biblio->{ $department }->{ $category }->{ $type } };
448 $azvo_stat_biblio->{ $department }->{ $category }->{ $type } = $#biblios + 1;
453 debug 'azvo_stat_authors' => $azvo_stat_authors;
454 debug 'azvo_stat_biblio' => $azvo_stat_biblio;
457 open(my $fh, '>', 'html/azvo.new');
462 rename 'html/azvo.new', 'html/azvo.html';