3 # LC_COLLATE=hr_HR.utf8 KOHA_CONF=/etc/koha/sites/ffzg/koha-conf.xml ./html.pl
9 use Data::Dump qw(dump);
13 use lib '/srv/koha_ffzg';
19 my $dbh = C4::Context->dbh;
21 my $xslfilename = 'compact.xsl';
26 my $sth_select_authors = $dbh->prepare(q{
29 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
30 ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
31 ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
36 and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
37 order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
40 $sth_select_authors->execute();
41 while( my $row = $sth_select_authors->fetchrow_hashref ) {
43 if ( $row->{first_author} ) {
44 my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
45 foreach my $authid ( split(/\s+/, $all_authors) ) {
46 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
47 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
50 my $xml = XMLin( $row->{marcxml}, ForceArray => [ 'subfield' ] );
51 foreach my $f700 ( map { $_->{subfield} } grep { $_->{tag} eq 700 } @{ $xml->{datafield} } ) {
54 foreach my $sf ( @$f700 ) {
55 if ( $sf->{code} eq '4' && $sf->{content} =~ m/^edt/ ) {
57 } elsif ( $sf->{code} eq '9' ) {
58 $authid = $sf->{content};
61 if ( $authid && $is_edt ) {
62 warn "# ++ ", $row->{biblionumber}, " $authid f700 ", dump( $f700 );
63 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
64 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
66 warn "# -- ", $row->{biblionumber}, " f700 ", dump( $f700 );
75 my $all_authids = join(',', grep { length($_) > 0 } keys %$authors);
76 my $sth_auth = $dbh->prepare(q{
79 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name
82 ExtractValue(marcxml,'//datafield[@tag="024"]/subfield[@code="a"]') <> '' and
83 authid in (} . $all_authids . q{)
87 while( my $row = $sth_auth->fetchrow_hashref ) {
89 $auth_header->{ $row->{authid} } = $row->{full_name};
95 my $sth_categories = $dbh->prepare(q{
96 select authorised_value, lib from authorised_values where category = 'BIBCAT'
98 $sth_categories->execute();
99 while( my $row = $sth_categories->fetchrow_hashref ) {
100 $category_label->{ $row->{authorised_value} } = $row->{lib};
103 warn dump( $category_label );
108 <meta charset="UTF-8">
109 <title>|, join(" ", @_), qq|</title>
110 <link href="style.css" type="text/css" rel="stylesheet" />
117 return qq|</body>\n</html\n|;
121 sub biblioitem_html {
122 my $biblionumber = shift;
124 my $xmlrecord = $marcxml->{$biblionumber} || die "missing $biblionumber marcxml";
126 my $parser = XML::LibXML->new();
127 $parser->recover_silently(0); # don't die when you find &, >, etc
128 my $source = $parser->parse_string($xmlrecord);
129 my $style_doc = $parser->parse_file($xslfilename);
131 my $xslt = XML::LibXSLT->new();
132 my $parsed = $xslt->parse_stylesheet($style_doc);
133 my $transformed = $parsed->transform($source);
134 return $parsed->output_string( $transformed );
138 mkdir 'html' unless -d 'html';
140 open(my $index, '>:encoding(utf-8)', 'html/index.html');
141 print $index html_title('Bibliografija Filozogskog fakulteta');
145 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
147 my $first = substr( $row->{full_name}, 0, 1 );
148 if ( $first ne $first_letter ) {
149 print $index qq{</ul>\n} if $first_letter;
150 $first_letter = $first;
151 print $index qq{<h1>$first</h1>\n<ul>\n};
153 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
155 open(my $fh, '>:encoding(utf-8)', "html/$row->{authid}.html");
156 print $fh html_title($row->{full_name}, "bibliografija");
157 foreach my $category ( sort keys %{ $authors->{ $row->{authid} } } ) {
158 my $label = $category_label->{$category} || 'Bez kategorije';
159 print $fh qq|<h1>$label</h1>\n<ul>\n|;
160 foreach my $biblionumber ( @{ $authors->{ $row->{authid} }->{$category} } ) {
161 print $fh qq|<li><a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|, biblioitem_html($biblionumber), qq|</li>\n|;
163 print $fh qq|</ul>\n|;
170 print $index html_end;
172 print dump( $authors );
174 print dump( $auth_header );