diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 46825165ef..786dcdfe00 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -52,6 +52,11 @@ $VERSION = 0.01; &MARCaddword &MARCdelword &char_decode &FindDuplicate + &BuildSummary + &BuildUnimarcHierarchies + &BuildUnimarcHierarchy + &AUTHsavetrees + &AUTHgetheader ); sub authoritysearch { @@ -66,8 +71,14 @@ sub authoritysearch { # the authtypecode. Then, search on $a of this tag_to_report # also store main entry MARC tag, to extract it at end of search my $mainentrytag; - my $sth = $dbh->prepare("select auth_tag_to_report from auth_types where authtypecode=?"); - $sth->execute($authtypecode); + my $sth; + if ($authtypecode){ + $sth= $dbh->prepare('select auth_tag_to_report from auth_types where authtypecode=?'); + $sth->execute($authtypecode); + }else{ + $sth= $dbh->prepare('select auth_tag_to_report from auth_types'); + $sth->execute; + } my ($tag_to_report) = $sth->fetchrow; $mainentrytag = $tag_to_report; for (my $i=0;$i<$#{$tags};$i++) { @@ -123,14 +134,25 @@ sub authoritysearch { my $sth; - if ($sql_where2) { - $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"); - warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"; - } else { - $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"); - warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"; - } - $sth->execute($authtypecode); + if ($authtypecode){ + if ($sql_where2) { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"); + warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"; + } else { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"); + warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"; + } + $sth->execute("$authtypecode"); + } else { + if ($sql_where2) { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and $sql_where2 and ($sql_where1)"); + warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and $sql_where2 and ($sql_where1)"; + } else { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and $sql_where1"); + warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and $sql_where1"; + } + $sth->execute; + } my @result = (); while (my ($authid) = $sth->fetchrow) { push @result,$authid; @@ -1079,6 +1101,195 @@ sub FindDuplicate { return; } +sub BuildSummary{ + my $record = shift @_; + my $summary = shift @_; + ##TODO : use langages from authorised_values + ## AND Thesaurii from auth_types + my %language; + $language{'fre'}="Français"; + $language{'eng'}="Anglais"; + $language{'ger'}="Allemand"; + $language{'ita'}="Italien"; + $language{'spa'}="Espagnol"; + my %thesaurus; + $thesaurus{'1'}="Peuples"; + $thesaurus{'2'}="Anthroponymes"; + $thesaurus{'3'}="Oeuvres"; + $thesaurus{'4'}="Chronologie"; + $thesaurus{'5'}="Lieux"; + $thesaurus{'6'}="Sujets"; + #thesaurus a remplir + if ($summary) { + my @fields = $record->fields(); + foreach my $field (@fields) { + my $tag = $field->tag(); + my $tagvalue = $field->as_string(); + $summary =~ s/\[(.?.?.?.?)$tag\*(.*?)]/$1$tagvalue$2\[$1$tag$2]/g; + if ($tag<10) { + } else { + my @subf = $field->subfields; + for my $i (0..$#subf) { + my $subfieldcode = $subf[$i][0]; + my $subfieldvalue = $subf[$i][1]; + my $tagsubf = $tag.$subfieldcode; + $summary =~ s/\[(.?.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue$2\[$1$tagsubf$2]/g; + } + } + } + $summary =~ s/\[(.*?)]//g; + $summary =~ s/\n/
/g; + } else { + my $heading; + my $authid; + my $altheading; + my $seealso; + my $broaderterms; + my $narrowerterms; + my $see; + my $seeheading; + my $notes; + my @fields = $record->fields(); + if (C4::Context->preference('marcflavour') eq 'UNIMARC') { + # construct UNIMARC summary, that is quite different from MARC21 one + # accepted form + foreach my $field ($record->field('2..')) { + $heading.= $field->subfield('a'); + $authid=$field->subfield('3'); + } + # rejected form(s) + foreach my $field ($record->field('3..')) { + $notes.= ''.$field->subfield('a')."\n"; + } + foreach my $field ($record->field('4..')) { + my $thesaurus = "thes. : ".$thesaurus{"$field->subfield('2')"}." : " if ($field->subfield('2')); + $see.= ''.$thesaurus.$field->subfield('a')." -- \n"; + } + # see : + foreach my $field ($record->field('5..')) { + + if (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'g')) { + $broaderterms.= ' '.$field->subfield('a')." -- \n"; + } elsif (($field->subfield('5')) && ($field->subfield('a')) && ($field->subfield('5') eq 'h')){ + $narrowerterms.= ''.$field->subfield('a')." -- \n"; + } elsif ($field->subfield('a')) { + $seealso.= ''.$field->subfield('a')." -- \n"; + } + } + # // form + foreach my $field ($record->field('7..')) { + my $lang = substr($field->subfield('8'),3,3); + $seeheading.= ' En '.$language{$lang}.' : '.$field->subfield('a')."
\n"; + } + $broaderterms =~s/-- \n$//; + $narrowerterms =~s/-- \n$//; + $seealso =~s/-- \n$//; + $see =~s/-- \n$//; + $summary = "".$heading."
".($notes?"$notes
":""); + $summary.= '

TG : '.$broaderterms.'

' if ($broaderterms); + $summary.= '

TS : '.$narrowerterms.'

' if ($narrowerterms); + $summary.= '

TA : '.$seealso.'

' if ($seealso); + $summary.= '

EP : '.$see.'

' if ($see); + $summary.= '

'.$seeheading.'

' if ($seeheading); + } + } + return $summary; +} + +sub BuildUnimarcHierarchies{ + my $authid = shift @_; +# warn "authid : $authid"; + my $force = shift @_; + my @globalresult; + my $dbh=C4::Context->dbh; + my $hierarchies; + my $data = AUTHgetheader($dbh,$authid); + + if ($data->{'authtrees'} and not $force){ + return $data->{'authtrees'}; + } elsif ($data->{'authtrees'}){ + $hierarchies=$data->{'authtrees'}; + } else { + my $record = AUTHgetauthority($dbh,$authid); + my $found; + my ($result,$total)=authoritysearch($dbh,['5503'],['and'],'',['='],[$authid],0,100); + if ($total){ + foreach my $parentauthid (map { $_->{'authid'} } @$result){ + my $parentrecord = AUTHgetauthority($dbh,$parentauthid); + #checking results + foreach my $field ($parentrecord->field('550')){ + if (($field->subfield('3')) && ($field->subfield('3') eq $authid) && ($field->subfield('5')) && ($field->subfield('5') eq 'h')) { + my $localresult=$hierarchies; + my $trees; + $trees = BuildUnimarcHierarchies($parentauthid); + my @trees; + if ($trees=~/;/){ + @trees = split(/;/,$trees); + } else { + push @trees, $trees; + } + foreach (@trees){ + $_.= ",$authid"; + } + @globalresult = (@globalresult,@trees); + } + $found=1; + } + } + $hierarchies=join(";",@globalresult); + } + #Unless there is no ancestor, I am alone. + $hierarchies="$authid" unless ($hierarchies); + } + AUTHsavetrees($authid,$hierarchies); + return $hierarchies; +} + +sub BuildUnimarcHierarchy{ + my $record = shift @_; + my $class = shift @_; + my $authid=$record->subfield('250','3'); + my %cell; + my $parents=""; my $children=""; + my (@loopparents,@loopchildren); + foreach my $field ($record->field('550')){ + if ($field->subfield('5') && $field->subfield('a')){ + if ($field->subfield('5') eq 'h'){ + push @loopchildren, { "childauthid"=>$field->subfield('3'),"childvalue"=>$field->subfield('a')}; + }elsif ($field->subfield('5') eq 'g'){ + push @loopparents, { "parentauthid"=>$field->subfield('3'),"parentvalue"=>$field->subfield('a')}; + } + # brothers could get in there with an else + } + } + $cell{"ifparents"}=1 if (scalar(@loopparents)>0); + $cell{"ifchildren"}=1 if (scalar(@loopchildren)>0); + $cell{"loopparents"}=\@loopparents if (scalar(@loopparents)>0); + $cell{"loopchildren"}=\@loopchildren if (scalar(@loopchildren)>0); + $cell{"class"}=$class; + $cell{"authid"}=$authid; + $cell{"value"}=$record->subfield('250',"a"); + return \%cell; +} + +sub AUTHgetheader{ + my $authid = shift @_; + my $sql= "SELECT * from auth_header WHERE authid = ?"; + my $dbh=C4::Context->dbh; + my $rq= $dbh->prepare($sql); + $rq->execute($authid); + my $data= $rq->fetchrow_hashref; + return $data; +} + +sub AUTHsavetrees{ + my $authid = shift @_; + my $trees = shift @_; + my $sql= "UPDATE IGNORE auth_header set authtrees=? WHERE authid = ?"; + my $dbh=C4::Context->dbh; + my $rq= $dbh->prepare($sql); + $rq->execute($trees,$authid); +} END { } # module clean-up code here (global destructor) @@ -1094,6 +1305,17 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.9.2.19 2006/07/31 10:15:42 hdl +# BugFixing : MARCdetail : displayin field values with ESCAPE=HTML (in order to manage '<''>' characters) +# +# Adding Hierarchy display for authorities. +# Please Note That it relies on the fact that authorities id are stored in $3 of authorities notice. +# And Broader terms is supposed to be indicated by a g for 550$5 subfield, narrower term : an h for the same subfield. +# +# It CAN SURELY be generalised but only with a bunch of sytem preferences. +# +# I added the ability to do a search on ANY authtypecode. +# # Revision 1.9.2.18 2006/07/25 12:30:51 tipaul # adding some informations to the array that is passed as result to an authority search : mainly, the tag_to_report & the $3 information (unimarc specific) # diff --git a/authorities/detail.pl b/authorities/detail.pl index eeda2eb33c..0db3634cde 100755 --- a/authorities/detail.pl +++ b/authorities/detail.pl @@ -54,6 +54,15 @@ use C4::Koha; use HTML::Template; my $query=new CGI; +# open template +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "authorities/detail.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => {catalogue => 1}, + debug => 1, + }); my $dbh=C4::Context->dbh; @@ -61,7 +70,37 @@ my $authid = $query->param('authid'); my $authtypecode = &AUTHfind_authtypecode($dbh,$authid); my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode); -my $record =AUTHgetauthority($dbh,$authid); +my $record; +if (C4::Context->preference("AuthDisplayHierarchy")){ + my $trees=BuildUnimarcHierarchies($authid); +# warn "trees :$trees"; + my @trees = split /;/,$trees ; + push @trees,$trees unless (@trees); + my @loophierarchies; + foreach my $tree (@trees){ +# warn "tree :$tree"; + + my @tree=split /,/,$tree; + push @tree,$tree unless (@tree); + my $cnt=0; + my @loophierarchy; + foreach my $element (@tree){ +# warn "tree :$element"; + my %cell; + my $elementdata = AUTHgetauthority($dbh,$element); + $record= $elementdata if ($authid==$element); + push @loophierarchy, BuildUnimarcHierarchy($elementdata,"child".$cnt); + $cnt++; + } + push @loophierarchies, { 'loopelement' =>\@loophierarchy}; + $template->param( + 'displayhierarchy' =>C4::Context->preference("AuthDisplayHierarchy"), + 'loophierarchies' =>\@loophierarchies, + ); + } +} else { + $record=AUTHgetauthority($dbh,$authid); +} my $count = AUTHcount_usage($authid); # find the marc field/subfield used in biblio by this authority @@ -73,15 +112,6 @@ while (my ($tagfield) = $sth->fetchrow) { } chop $biblio_fields; -# open template -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "authorities/detail.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => {catalogue => 1}, - debug => 1, - }); # fill arrays my @loop_data =(); diff --git a/koha-tmpl/intranet-tmpl/default/en/catalogue/MARCdetail.tmpl b/koha-tmpl/intranet-tmpl/default/en/catalogue/MARCdetail.tmpl index d4b8559b21..317adee596 100644 --- a/koha-tmpl/intranet-tmpl/default/en/catalogue/MARCdetail.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/catalogue/MARCdetail.tmpl @@ -96,9 +96,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -124,7 +124,7 @@ - + &operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -152,9 +152,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -180,9 +180,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -208,9 +208,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -236,9 +236,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -264,9 +264,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -292,9 +292,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -320,9 +320,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> @@ -348,9 +348,9 @@ - + - &operator==&type=intranet&value="> + \'&operator==&type=intranet&value="> //images/filefind.png" height="15" title="Search on "> diff --git a/koha-tmpl/intranet-tmpl/default/en/includes/hierarchy.css b/koha-tmpl/intranet-tmpl/default/en/includes/hierarchy.css new file mode 100644 index 0000000000..6107422181 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/includes/hierarchy.css @@ -0,0 +1,108 @@ +#hierarchies { + background-color:#FFF; + color:#000000; + border:2px solid #000000; + padding:5px; + width:90%; + -moz-border-radius:6px; + position:relative; + display:block; +} +#hierarchy { + border:1px solid #000000; + padding:5px; + width:90%; + -moz-border-radius:6px; + position:relative; + display:block; +} +.child { + display:none; + margin-left : 50%; + width:150%; +} +.child a:hover{ + background-color:#BFCFFF; +} +.parent { + display:none; + margin-left : -50%; +} +.parent a:hover{ + background-color:#BFCFFF; +} +.child0{ + width : 10%; + text-align : left; +} +.child0 a:hover{ + background-color:#BFCFFF; +} +.child1{ + width : 10%; + text-align : left; + margin-left : 11%; +} +.child1 a:hover{ + background-color:#BFCFFF; +} +.child2{ + width : 10%; + text-align : left; + margin-left : 22%; +} +.child2 a:hover{ + background-color:#BFCFFF; +} +.child3{ + width : 10%; + text-align : left; + margin-left : 33%; +} +.child3 a:hover{ + background-color:#BFCFFF; +} +.child4{ + width : 10%; + text-align : left; + margin-left : 44%; +} +.child4 a:hover{ + background-color:#BFCFFF; +} +.child5{ + width : 10%; + text-align : left; + margin-left : 55%; +} +.child5 a:hover{ + background-color:#BFCFFF; +} +.child6{ + width : 10%; + text-align : left; + margin-left : 66%; +} +.child6 a:hover{ + background-color:#BFCFFF; +} +.child7{ + width : 10%; + text-align : left; + margin-left : 77%; +} +.child7 a:hover{ + background-color:#BFCFFF; +} +.child8{ + width : 10%; + text-align : left; + margin-left : 88%; +} +.child8 a:hover{ + background-color:#BFCFFF; +} +.parents{ + display:inline; + cursor:crosshair; +} \ No newline at end of file diff --git a/updater/updatedatabase b/updater/updatedatabase index 16c2986c1e..723ee85ec5 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -871,7 +871,9 @@ my %tabledata = ( }, value => 'Fill with appropriate value...', explanation => 'ISBD', - type => 'free' + type => 'Textarea', + options => '150|50' + }, { uniquefieldrequired => 'variable', @@ -1395,6 +1397,21 @@ my %tabledata = ( "contains the MARC biblio tags of person authorities to fill biblio.author with when importing biblio", type => 'free', }, + { + uniquefieldrequired => 'variable', + variable => 'AuthDisplayHierarchy', + value => '1', + forceupdate => { + 'explanation' => 1, + ' + type' => 1 + }, + explanation => +"Display hierarchies in details for Authorities.", + type => 'YesNo', + value =>0, + }, + ], ); @@ -1476,6 +1493,17 @@ my %fielddefinitions = ( extra => '' }, ], + auth_header =>[ + { + field => 'authtrees', + type => 'text', + null => 'NULL', + key => '', + default => '', + extra => '' + }, + ], + ); #------------------- @@ -2138,6 +2166,17 @@ $sth->finish; exit; # $Log$ +# Revision 1.100.2.49 2006/07/31 10:15:42 hdl +# BugFixing : MARCdetail : displayin field values with ESCAPE=HTML (in order to manage '<''>' characters) +# +# Adding Hierarchy display for authorities. +# Please Note That it relies on the fact that authorities id are stored in $3 of authorities notice. +# And Broader terms is supposed to be indicated by a g for 550$5 subfield, narrower term : an h for the same subfield. +# +# It CAN SURELY be generalised but only with a bunch of sytem preferences. +# +# I added the ability to do a search on ANY authtypecode. +# # Revision 1.100.2.48 2006/07/28 01:13:41 sushi # updated 'labels_conf' table. #