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 print $fh qq|<h2>$label</h2>\n|;
251 foreach my $category ( sort keys %{ $authors->{$authid}->{$type} } ) {
252 my $label = $category_label->{$category} || 'Bez kategorije';
253 print $fh qq|<h3>$label</h3>\n<ul>\n|;
254 foreach my $biblionumber ( @{ $authors->{$authid}->{$type}->{$category} } ) {
256 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
257 biblioitem_html($biblionumber),
258 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
261 print $fh qq|</ul>\n|;
265 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
267 my $first = substr( $row->{full_name}, 0, 1 );
268 if ( $first ne $first_letter ) {
269 print $index qq{</ul>\n} if $first_letter;
270 $first_letter = $first;
271 print $index qq{<h1>$first</h1>\n<ul>\n};
273 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
275 my $path = "html/$row->{authid}";
276 open(my $fh, '>:encoding(utf-8)', "$path.new");
277 print $fh html_title($row->{full_name}, "bibliografija");
278 print $fh qq|<h1>$row->{full_name} - bibliografija za razdoblje 2008-2013</h1>|;
280 author_html( $fh, $row->{authid}, 'aut' => 'Primarno autorstvo' );
281 author_html( $fh, $row->{authid}, 'sec' => 'Sekundarno autorstvo' );
285 rename "$path.new", "$path.html";
289 print $index html_end;
291 rename 'html/index.new', 'html/index.html';
293 debug 'auth_header' => $auth_header;
296 my $department_category_author;
297 foreach my $department ( sort keys %$auth_department ) {
298 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
299 foreach my $category ( sort keys %{ $authors->{$authid} } ) {
300 push @{ $department_category_author->{$department}->{$category} }, $authid;
305 debug 'department_category_author' => $department_category_author;
307 mkdir 'html/departments' unless -d 'html/departments';
309 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
310 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
311 foreach my $department ( sort keys %$department_category_author ) {
312 my $dep = $department || 'Nema odsjeka';
313 my $dep_file = unac_string('utf-8',$dep);
314 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
315 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
316 print $fh html_title($department . ' bibliografija');
317 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
318 my $label = $category_label->{$category} || 'Bez kategorije';
319 print $fh qq|<h1>$label</h1>\n<ul>\n|;
321 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
322 foreach my $biblionumber ( @{ $authors->{$authid}->{$category} } ) {
324 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
325 biblioitem_html($biblionumber),
326 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
335 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
337 print $dep_fh qq|</ul>\n|, html_end;
339 rename 'html/departments/index.new', 'html/departments/index.html';
341 debug 'skip' => $skip;