3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
9 use Data::Dump qw(dump);
14 use lib '/srv/koha_ffzg';
19 my $dbh = C4::Context->dbh;
22 my ($title, $data) = @_;
23 print "# $title ",dump($data), $/;
26 my $xslfilename = 'compact.xsl';
34 my $sth_auth = $dbh->prepare(q{
37 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name,
38 ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="a"]') as department
43 while( my $row = $sth_auth->fetchrow_hashref ) {
44 $auth_header->{ $row->{authid} } = $row->{full_name};
45 $row->{department} =~ s/, Filozofski fakultet u Zagrebu\s*// || next;
46 $row->{department} =~ s/^.+\.\s*//;
47 push @{ $auth_department->{ $row->{department} } }, $row->{authid};
53 debug 'auth_department' => $auth_department;
59 my $sth_select_authors = $dbh->prepare(q{
70 -- ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
71 -- ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
72 -- ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
74 -- and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
75 -- order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
81 my $parser = XML::LibXML->new();
82 $parser->recover_silently(0); # don't die when you find &, >, etc
83 my $style_doc = $parser->parse_file($xslfilename);
84 my $xslt = XML::LibXSLT->new();
85 my $parsed = $xslt->parse_stylesheet($style_doc);
89 open(my $xml_fh, '>', '/tmp/bibliografija.xml') if $ENV{XML};
92 my $biblionumber = shift;
94 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber};
96 my $xmlrecord = $marcxml->{$biblionumber} || die "missing $biblionumber marcxml";
98 print $xml_fh $xmlrecord if $ENV{XML};
100 my $source = eval { $parser->parse_string($xmlrecord) };
102 # warn "SKIP $biblionumber corrupt XML";
103 push @{ $skip->{XML_corrupt} }, $biblionumber;
107 my $transformed = $parsed->transform($source);
108 $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
110 return ( $biblio_html->{$biblionumber}, $source ) if wantarray;
111 return $biblio_html->{$biblionumber};
114 $sth_select_authors->execute();
115 while( my $row = $sth_select_authors->fetchrow_hashref ) {
116 # warn dump($row),$/;
120 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
122 my ( undef, $doc ) = biblioitem_html( $row->{biblionumber} );
124 warn "ERROR can't parse MARCXML ", $row->{biblionumber}, " ", $row->{marcxml}, "\n";
128 my $root = $doc->documentElement;
130 my @leaders = $root->getElementsByLocalName('leader');
132 my $leader = $leaders[0]->textContent;
133 warn "leader $leader\n";
146 foreach my $elt ($root->getChildrenByLocalName('*')) {
147 my $tag = $elt->getAttribute('tag');
149 next unless exists $extract->{ $tag };
151 if ($elt->localname eq 'controlfield') {
152 if ( $tag eq '008' ) {
153 $biblio_year->{ $row->{biblionumber} } = $elt->textContent;
156 } elsif ($elt->localname eq 'datafield') {
158 foreach my $sfelt ($elt->getChildrenByLocalName('subfield')) {
159 my $sf = $sfelt->getAttribute('code');
160 next unless $sf =~ m/$extract->{$tag}/;
161 if ( exists $sf_data->{$sf} ) {
162 $sf_data->{$sf} .= " " . $sfelt->textContent();
164 $sf_data->{$sf} = $sfelt->textContent();
167 push @{ $data->{$tag} }, $sf_data if $sf_data;
171 # warn "# ", $row->{biblionumber}, " data ",dump($data);
173 my $category = $data->{942}->[0]->{'t'};
175 # warn "# SKIP ", $row->{biblionumber}, " no category in ", dump($data);
176 push @{ $skip->{no_category} }, $row->{biblionumber};
181 if ( exists $data->{100} ) {
182 my @first_author = map { $_->{'9'} } @{ $data->{100} };
183 foreach my $authid ( @first_author ) {
184 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
188 if ( exists $data->{700} ) {
189 foreach my $auth ( @{ $data->{700} } ) {
190 my $authid = $auth->{9} || next;
191 my $type = $auth->{4} || next; #die "no 4 in ",dump($data);
193 $type_stats->{$type}++;
195 if ( $type =~ m/aut/ ) {
196 push @{ $authors->{$authid}->{aut}->{ $category } }, $row->{biblionumber};
197 } elsif ( $type =~ m/(edt|trl|com|ctb)/ ) {
198 push @{ $authors->{$authid}->{sec}->{ $category } }, $row->{biblionumber};
200 # warn "# SKIP ", $row->{biblionumber}, ' no 700$4 in ', dump($data);
201 push @{ $skip->{ 'no_700$4' } }, $row->{biblionumber};
208 debug 'authors' => $authors;
209 debug 'type_stats' => $type_stats;
212 my $sth_categories = $dbh->prepare(q{
213 select authorised_value, lib from authorised_values where category = 'BIBCAT'
215 $sth_categories->execute();
216 while( my $row = $sth_categories->fetchrow_hashref ) {
217 $category_label->{ $row->{authorised_value} } = $row->{lib};
220 debug 'category_label' => $category_label;
225 <meta charset="UTF-8">
226 <title>|, join(" ", @_), qq|</title>
227 <link href="style.css" type="text/css" rel="stylesheet" />
234 return qq|</body>\n</html\n|;
237 mkdir 'html' unless -d 'html';
239 open(my $index, '>:encoding(utf-8)', 'html/index.new');
240 print $index html_title('Bibliografija Filozofskog fakulteta');
242 my $first_letter = '';
244 debug 'authors' => \@authors;
247 my ( $fh, $authid, $type, $label ) = @_;
249 return unless exists $authors->{$authid}->{$type};
251 print $fh qq|<h2>$label</h2>\n|;
253 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
254 my $label = $category_label->{$category} || 'Bez kategorije';
255 print $fh qq|<h3>$label</h3>\n<ul>\n|;
256 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
258 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
259 biblioitem_html($biblionumber),
260 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
263 print $fh qq|</ul>\n|;
267 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
269 my $first = substr( $row->{full_name}, 0, 1 );
270 if ( $first ne $first_letter ) {
271 print $index qq{</ul>\n} if $first_letter;
272 $first_letter = $first;
273 print $index qq{<h1>$first</h1>\n<ul>\n};
275 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
277 my $path = "html/$row->{authid}";
278 open(my $fh, '>:encoding(utf-8)', "$path.new");
279 print $fh html_title($row->{full_name}, "bibliografija");
280 print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
282 author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
283 author_html( $fh, $row->{authid}, 'sec' => 'Sekundarno autorstvo' );
287 rename "$path.new", "$path.html";
291 print $index html_end;
293 rename 'html/index.new', 'html/index.html';
295 debug 'auth_header' => $auth_header;
298 my $department_category_author;
299 foreach my $department ( sort keys %$auth_department ) {
300 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
301 foreach my $category ( sort keys %{ $authors->{$authid} } ) {
302 push @{ $department_category_author->{$department}->{$category} }, $authid;
307 debug 'department_category_author' => $department_category_author;
309 mkdir 'html/departments' unless -d 'html/departments';
311 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
312 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
313 foreach my $department ( sort keys %$department_category_author ) {
314 my $dep = $department || 'Nema odsjeka';
315 my $dep_file = unac_string('utf-8',$dep);
316 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
317 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
318 print $fh html_title($department . ' bibliografija');
319 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
320 my $label = $category_label->{$category} || 'Bez kategorije';
321 print $fh qq|<h1>$label</h1>\n<ul>\n|;
323 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
324 foreach my $biblionumber ( @{ $authors->{$authid}->{$category} } ) {
326 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
327 biblioitem_html($biblionumber),
328 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
337 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
339 print $dep_fh qq|</ul>\n|, html_end;
341 rename 'html/departments/index.new', 'html/departments/index.html';
343 debug 'skip' => $skip;