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), $/;
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 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
97 my $biblionumber = shift;
99 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber};
101 my $xmlrecord = $marcxml->{$biblionumber} || confess "missing $biblionumber marcxml";
103 print $xml_fh $xmlrecord if $ENV{XML};
105 my $source = eval { $parser->parse_string($xmlrecord) };
107 # warn "SKIP $biblionumber corrupt XML";
108 push @{ $skip->{XML_corrupt} }, $biblionumber;
112 my $transformed = $parsed->transform($source);
113 $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
115 return ( $biblio_html->{$biblionumber}, $source ) if wantarray;
116 return $biblio_html->{$biblionumber};
119 $sth_select_authors->execute();
120 while( my $row = $sth_select_authors->fetchrow_hashref ) {
121 # warn dump($row),$/;
125 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
127 my ( undef, $doc ) = biblioitem_html( $row->{biblionumber} );
129 # warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
133 my $root = $doc->documentElement;
135 my @leaders = $root->getElementsByLocalName('leader');
137 my $leader = $leaders[0]->textContent;
138 warn "leader $leader\n";
151 foreach my $elt ($root->getChildrenByLocalName('*')) {
152 my $tag = $elt->getAttribute('tag');
154 next unless exists $extract->{ $tag };
156 if ($elt->localname eq 'controlfield') {
157 if ( $tag eq '008' ) {
158 my $year = substr($elt->textContent, 7, 4 );
159 if ( $year !~ m/^\d+$/ ) {
161 push @{ $skip->{invalid_year} }, $row->{biblionumber};
163 $biblio_year->{ $row->{biblionumber} } = $data->{year} = $year;
166 } elsif ($elt->localname eq 'datafield') {
168 foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
169 my $sf = $sfelt->getAttribute('code');
170 next unless $sf =~ m/$extract->{$tag}/;
171 if ( exists $sf_data->{$sf} ) {
172 $sf_data->{$sf} .= " " . $sfelt->textContent();
174 $sf_data->{$sf} = $sfelt->textContent();
177 push @{ $data->{$tag} }, $sf_data if $sf_data;
181 if ( $data->{year} < 2008 ) {
182 push @{ $skip->{year_lt_2008} }, $row->{biblionumber};
184 } elsif ( $data->{year} > 2013 ) {
185 push @{ $skip->{year_gt_2013} }, $row->{biblionumber};
189 # warn "# ", $row->{biblionumber}, " data ",dump($data);
191 my $category = $data->{942}->[0]->{'t'};
193 # warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
194 push @{ $skip->{no_category} }, $row->{biblionumber};
201 if ( exists $data->{100} ) {
202 my @first_author = map { $_->{'9'} } @{ $data->{100} };
203 foreach my $authid ( @first_author ) {
204 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
212 if ( exists $data->{700} ) {
213 foreach my $auth ( @{ $data->{700} } ) {
214 my $authid = $auth->{9} || next;
215 my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
217 $type_stats->{$type}++;
219 if ( $type =~ m/(edt|trl|com|ctb)/ ) {
220 push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
221 push @{ $authors->{$authid}->{$1}->{ $category } }, $row->{biblionumber};
222 } elsif ( $type =~ m/aut/ ) {
224 $have_edt = grep { exists $_->{4} && $_->{4} =~ m/edt/ } @{ $data->{700} } if ! defined $have_edt;
226 $skip->{ have_700_edt }->{ $row->{biblionumber} }++;
228 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
231 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
234 # warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
235 $skip->{ 'no_700$4' }->{ $row->{biblionumber} }++;
242 debug 'authors' => $authors;
243 debug 'type_stats' => $type_stats;
244 debug 'skip' => $skip;
245 debug 'biblio_year' => $biblio_year;
248 my $sth_categories = $dbh->prepare(q{
249 select authorised_value, lib from authorised_values where category = 'BIBCAT'
251 $sth_categories->execute();
252 while( my $row = $sth_categories->fetchrow_hashref ) {
253 $category_label->{ $row->{authorised_value} } = $row->{lib};
256 debug 'category_label' => $category_label;
261 <meta charset="UTF-8">
262 <title>|, join(" ", @_), qq|</title>
263 <link href="style.css" type="text/css" rel="stylesheet" />
270 return qq|</body>\n</html\n|;
273 mkdir 'html' unless -d 'html';
275 open(my $index, '>:encoding(utf-8)', 'html/index.new');
276 print $index html_title('Bibliografija Filozofskog fakulteta');
278 my $first_letter = '';
280 debug 'authors' => \@authors;
283 my ($biblionumber) = @_;
285 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
286 biblioitem_html($biblionumber),
287 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
292 my ( $fh, $authid, $type, $label ) = @_;
294 return unless exists $authors->{$authid}->{$type};
296 print $fh qq|<h2>$label</h2>\n|;
298 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
299 my $label = $category_label->{$category} || 'Bez kategorije';
300 print $fh qq|<h3>$label</h3>\n<ul>\n|;
301 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
302 print $fh li_biblio( $biblionumber );
304 print $fh qq|</ul>\n|;
308 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
310 my $first = substr( $row->{full_name}, 0, 1 );
311 if ( $first ne $first_letter ) {
312 print $index qq{</ul>\n} if $first_letter;
313 $first_letter = $first;
314 print $index qq{<h1>$first</h1>\n<ul>\n};
316 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
318 my $path = "html/$row->{authid}";
319 open(my $fh, '>:encoding(utf-8)', "$path.new");
320 print $fh html_title($row->{full_name}, "bibliografija");
321 print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
323 author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
324 author_html( $fh, $row->{authid}, 'sec' => 'Sekundarno autorstvo' );
328 rename "$path.new", "$path.html";
332 print $index html_end;
334 rename 'html/index.new', 'html/index.html';
336 debug 'auth_header' => $auth_header;
339 my $department_category_author;
340 foreach my $department ( sort keys %$auth_department ) {
341 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
342 my @categories = keys %{ $authors->{$authid}->{aut} };
343 push @categories, keys %{ $authors->{$authid}->{sec} };
344 foreach my $category ( sort @categories ) {
345 push @{ $department_category_author->{$department}->{$category} }, $authid;
350 debug 'department_category_author' => $department_category_author;
352 mkdir 'html/departments' unless -d 'html/departments';
354 sub unique_biblionumber {
357 $u->{$_}++ foreach @v;
358 return sort { $biblio_year->{$b} <=> $biblio_year->{$a} || $a <=> $b } keys %$u;
361 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
362 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
363 foreach my $department ( sort keys %$department_category_author ) {
364 my $dep = $department || 'Nema odsjeka';
365 my $dep_file = unac_string('utf-8',$dep);
366 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
367 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
369 print $fh html_title($department . ' bibliografija');
370 print $fh qq|<h1>$department bibliografija</h1>\n|;
372 print $fh qq|<h2>Primarno autorstvo</h2>\n|;
374 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
376 my @authids = @{ $department_category_author->{$department}->{$category} };
377 next unless @authids;
379 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{aut}->{$category} } } grep { exists $authors->{$_}->{aut}->{$category} } @authids;
381 $unique->{$_}++ foreach @biblionumber;
383 next unless @biblionumber;
385 my $label = $category_label->{$category} || 'Bez kategorije';
386 print $fh qq|<h3>$label</h3>\n<ul>\n|;
388 print $fh li_biblio( $_ ) foreach @biblionumber;
394 print $fh qq|<h2>Sekundarno autorstvo</h2>\n|;
396 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
398 my @authids = @{ $department_category_author->{$department}->{$category} };
399 next unless @authids;
401 my @biblionumber = unique_biblionumber map { @{ $authors->{$_}->{sec}->{$category} } } grep { exists $authors->{$_}->{sec}->{$category} } @authids;
403 next unless @biblionumber;
405 my $label = $category_label->{$category} || 'Bez kategorije';
406 print $fh qq|<h3>$label</h3>\n<ul>\n|;
408 print $fh li_biblio( $_ ) foreach @biblionumber;
416 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
418 print $dep_fh qq|</ul>\n|, html_end;
420 rename 'html/departments/index.new', 'html/departments/index.html';
424 foreach my $department ( sort keys %$department_category_author ) {
425 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
426 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
427 foreach my $type ( keys %{ $authors->{$authid} } ) {
428 next unless exists $authors->{$authid}->{$type}->{$category};
429 $azvo_stat->{ $department }->{ $category }->{ $type } += $#{ $authors->{$authid}->{$type}->{$category} } + 1;
435 debug 'azvo_stat' => $azvo_stat;
438 open(my $fh, '>', 'html/azvo.new');
443 rename 'html/azvo.new', 'html/azvo.html';