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,
37 and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
38 order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
41 $sth_select_authors->execute();
42 while( my $row = $sth_select_authors->fetchrow_hashref ) {
44 if ( $row->{first_author} || $row->{itemtype} !~ m/^KNJ/ ) {
45 my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
46 foreach my $authid ( split(/\s+/, $all_authors) ) {
47 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
48 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
51 my $xml = XMLin( $row->{marcxml}, ForceArray => [ 'subfield' ] );
52 foreach my $f700 ( map { $_->{subfield} } grep { $_->{tag} eq 700 } @{ $xml->{datafield} } ) {
55 foreach my $sf ( @$f700 ) {
56 if ( $sf->{code} eq '4' && $sf->{content} =~ m/^edt/ ) {
58 } elsif ( $sf->{code} eq '9' ) {
59 $authid = $sf->{content};
62 if ( $authid && $is_edt ) {
63 # warn "# ++ ", $row->{biblionumber}, " $authid f700 ", dump( $f700 );
64 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
65 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
67 # warn "# -- ", $row->{biblionumber}, " f700 ", dump( $f700 );
76 my $all_authids = join(',', grep { length($_) > 0 } keys %$authors);
77 my $sth_auth = $dbh->prepare(q{
80 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name
83 ExtractValue(marcxml,'//datafield[@tag="024"]/subfield[@code="a"]') <> '' and
84 authid in (} . $all_authids . q{)
88 while( my $row = $sth_auth->fetchrow_hashref ) {
90 $auth_header->{ $row->{authid} } = $row->{full_name};
96 my $sth_categories = $dbh->prepare(q{
97 select authorised_value, lib from authorised_values where category = 'BIBCAT'
99 $sth_categories->execute();
100 while( my $row = $sth_categories->fetchrow_hashref ) {
101 $category_label->{ $row->{authorised_value} } = $row->{lib};
104 #warn dump( $category_label );
109 <meta charset="UTF-8">
110 <title>|, join(" ", @_), qq|</title>
111 <link href="style.css" type="text/css" rel="stylesheet" />
118 return qq|</body>\n</html\n|;
122 sub biblioitem_html {
123 my $biblionumber = shift;
125 my $xmlrecord = $marcxml->{$biblionumber} || die "missing $biblionumber marcxml";
127 my $parser = XML::LibXML->new();
128 $parser->recover_silently(0); # don't die when you find &, >, etc
129 my $source = $parser->parse_string($xmlrecord);
130 my $style_doc = $parser->parse_file($xslfilename);
132 my $xslt = XML::LibXSLT->new();
133 my $parsed = $xslt->parse_stylesheet($style_doc);
134 my $transformed = $parsed->transform($source);
135 return $parsed->output_string( $transformed );
139 mkdir 'html' unless -d 'html';
141 open(my $index, '>:encoding(utf-8)', 'html/index.html');
142 print $index html_title('Bibliografija Filozogskog fakulteta');
144 my $first_letter = '';
146 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
148 my $first = substr( $row->{full_name}, 0, 1 );
149 if ( $first ne $first_letter ) {
150 print $index qq{</ul>\n} if $first_letter;
151 $first_letter = $first;
152 print $index qq{<h1>$first</h1>\n<ul>\n};
154 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
156 open(my $fh, '>:encoding(utf-8)', "html/$row->{authid}.html");
157 print $fh html_title($row->{full_name}, "bibliografija");
158 foreach my $category ( sort keys %{ $authors->{ $row->{authid} } } ) {
159 my $label = $category_label->{$category} || 'Bez kategorije';
160 print $fh qq|<h1>$label</h1>\n<ul>\n|;
161 foreach my $biblionumber ( @{ $authors->{ $row->{authid} }->{$category} } ) {
162 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|;
164 print $fh qq|</ul>\n|;
171 print $index html_end;
173 #print dump( $authors );
175 #print dump( $auth_header );