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';
20 my $dbh = C4::Context->dbh;
22 my $xslfilename = 'compact.xsl';
27 my $sth_select_authors = $dbh->prepare(q{
30 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="9"]') as first_author,
31 ExtractValue(marcxml,'//datafield[@tag="700"]/subfield[@code="9"]') as other_authors,
32 ExtractValue(marcxml,'//datafield[@tag="942"]/subfield[@code="t"]') as category,
38 and SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) between 2008 and 2013
39 order by SUBSTR(ExtractValue(marcxml,'//controlfield[@tag="008"]'),8,4) desc
42 $sth_select_authors->execute();
43 while( my $row = $sth_select_authors->fetchrow_hashref ) {
45 if ( $row->{first_author} || $row->{itemtype} !~ m/^KNJ/ ) {
46 my $all_authors = join(' ', $row->{first_author}, $row->{other_authors});
47 foreach my $authid ( split(/\s+/, $all_authors) ) {
48 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
49 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
52 my $xml = XMLin( $row->{marcxml}, ForceArray => [ 'subfield' ] );
53 foreach my $f700 ( map { $_->{subfield} } grep { $_->{tag} eq 700 } @{ $xml->{datafield} } ) {
56 foreach my $sf ( @$f700 ) {
57 if ( $sf->{code} eq '4' && $sf->{content} =~ m/^edt/ ) {
59 } elsif ( $sf->{code} eq '9' ) {
60 $authid = $sf->{content};
63 if ( $authid && $is_edt ) {
64 # warn "# ++ ", $row->{biblionumber}, " $authid f700 ", dump( $f700 );
65 push @{ $authors->{$authid}->{ $row->{category} } }, $row->{biblionumber};
66 $marcxml->{ $row->{biblionumber} } = $row->{marcxml};
68 # warn "# -- ", $row->{biblionumber}, " f700 ", dump( $f700 );
78 my $all_authids = join(',', grep { length($_) > 0 } keys %$authors);
79 my $sth_auth = $dbh->prepare(q{
82 ExtractValue(marcxml,'//datafield[@tag="100"]/subfield[@code="a"]') as full_name,
83 ExtractValue(marcxml,'//datafield[@tag="680"]/subfield[@code="a"]') as department
86 authid in (} . $all_authids . q{)
90 while( my $row = $sth_auth->fetchrow_hashref ) {
91 $auth_header->{ $row->{authid} } = $row->{full_name};
92 $row->{department} =~ s/, Filozofski fakultet u Zagrebu\s*// || next;
93 $row->{department} =~ s/^.+\.\s*//;
94 push @{ $auth_department->{ $row->{department} } }, $row->{authid};
101 my $sth_categories = $dbh->prepare(q{
102 select authorised_value, lib from authorised_values where category = 'BIBCAT'
104 $sth_categories->execute();
105 while( my $row = $sth_categories->fetchrow_hashref ) {
106 $category_label->{ $row->{authorised_value} } = $row->{lib};
109 #warn dump( $category_label );
114 <meta charset="UTF-8">
115 <title>|, join(" ", @_), qq|</title>
116 <link href="style.css" type="text/css" rel="stylesheet" />
123 return qq|</body>\n</html\n|;
128 sub biblioitem_html {
129 my $biblionumber = shift;
131 return $biblio_html->{$biblionumber} if exists $biblio_html->{$biblionumber};
133 my $xmlrecord = $marcxml->{$biblionumber} || die "missing $biblionumber marcxml";
135 my $parser = XML::LibXML->new();
136 $parser->recover_silently(0); # don't die when you find &, >, etc
137 my $source = $parser->parse_string($xmlrecord);
138 my $style_doc = $parser->parse_file($xslfilename);
140 my $xslt = XML::LibXSLT->new();
141 my $parsed = $xslt->parse_stylesheet($style_doc);
142 my $transformed = $parsed->transform($source);
143 return $biblio_html->{$biblionumber} = $parsed->output_string( $transformed );
147 mkdir 'html' unless -d 'html';
149 open(my $index, '>:encoding(utf-8)', 'html/index.new');
150 print $index html_title('Bibliografija Filozogskog fakulteta');
152 my $first_letter = '';
154 foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) {
156 my $first = substr( $row->{full_name}, 0, 1 );
157 if ( $first ne $first_letter ) {
158 print $index qq{</ul>\n} if $first_letter;
159 $first_letter = $first;
160 print $index qq{<h1>$first</h1>\n<ul>\n};
162 print $index qq{<li><a href="}, $row->{authid}, qq{.html">}, $row->{full_name}, "</a></li>\n";
164 my $path = "html/$row->{authid}";
165 open(my $fh, '>:encoding(utf-8)', "$path.new");
166 print $fh html_title($row->{full_name}, "bibliografija");
167 foreach my $category ( sort keys %{ $authors->{ $row->{authid} } } ) {
168 my $label = $category_label->{$category} || 'Bez kategorije';
169 print $fh qq|<h1>$label</h1>\n<ul>\n|;
170 foreach my $biblionumber ( @{ $authors->{ $row->{authid} }->{$category} } ) {
172 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
173 biblioitem_html($biblionumber),
174 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
177 print $fh qq|</ul>\n|;
181 rename "$path.new", "$path.html";
185 print $index html_end;
187 rename 'html/index.new', 'html/index.html';
189 #print dump( $authors );
191 print dump( $auth_header );
193 print dump( $auth_department );
196 my $department_category_author;
197 foreach my $department ( sort keys %$auth_department ) {
198 foreach my $authid ( sort @{ $auth_department->{$department} } ) {
199 foreach my $category ( sort keys %{ $authors->{$authid} } ) {
200 push @{ $department_category_author->{$department}->{$category} }, $authid;
205 print dump( $department_category_author );
207 mkdir 'html/departments' unless -d 'html/departments';
209 open(my $dep_fh, '>:encoding(utf-8)', 'html/departments/index.new');
210 print $dep_fh html_title('Odsijeci Filozofskog fakulteta u Zagrebu'), qq|<ul>\n|;
211 foreach my $department ( sort keys %$department_category_author ) {
212 my $dep = $department || 'Nema odsjeka';
213 my $dep_file = unac_string('utf-8',$dep);
214 print $dep_fh qq|<li><a href="$dep_file.html">$dep</a></li>\n|;
215 open(my $fh, '>:encoding(utf-8)', "html/departments/$dep_file.new");
216 print $fh html_title($department . ' bibliografija');
217 foreach my $category ( sort keys %{ $department_category_author->{$department} } ) {
218 my $label = $category_label->{$category} || 'Bez kategorije';
219 print $fh qq|<h1>$label</h1>\n<ul>\n|;
221 foreach my $authid ( @{ $department_category_author->{$department}->{$category} } ) {
222 foreach my $biblionumber ( @{ $authors->{$authid}->{$category} } ) {
224 qq|<a href="https://koha.ffzg.hr/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber">$biblionumber</a>|,
225 biblioitem_html($biblionumber),
226 qq|<a href="https://koha.ffzg.hr:8443/cgi-bin/koha/cataloguing/addbiblio.pl?biblionumber=$biblionumber">edit</a>|,
235 rename "html/departments/$dep_file.new", "html/departments/$dep_file.html";
237 print $dep_fh qq|</ul>\n|, html_end;
239 rename 'html/departments/index.new', 'html/departments/index.html';