+=cut
+
+sub BuildAuthHierarchy{
+ my $record = shift @_;
+ my $class = shift @_;
+ my $authid_constructed = shift @_;
+ return unless ($record && $record->field('001'));
+ my $authid=$record->field('001')->data();
+ my %cell;
+ my $parents=""; my $children="";
+ my (@loopparents,@loopchildren);
+ my $marcflavour = C4::Context->preference('marcflavour');
+ my $relationshipsf = $marcflavour eq 'UNIMARC' ? '5' : 'w';
+ foreach my $field ($record->field('5..')){
+ my $subfauthid=_get_authid_subfield($field);
+ if ($subfauthid && $field->subfield($relationshipsf) && $field->subfield('a')){
+ my $relationship = substr($field->subfield($relationshipsf), 0, 1);
+ if ($relationship eq 'h'){
+ push @loopchildren, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
+ }
+ elsif ($relationship eq 'g'){
+ push @loopparents, { "authid"=>$subfauthid,"value"=>$field->subfield('a')};
+ }
+# brothers could get in there with an else
+ }
+ }
+ $cell{"parents"}=\@loopparents;
+ $cell{"children"}=\@loopchildren;
+ $cell{"class"}=$class;
+ $cell{"authid"}=$authid;
+ $cell{"current_value"} =1 if ($authid eq $authid_constructed);
+ $cell{"value"}=C4::Context->preference('marcflavour') eq 'UNIMARC' ? $record->subfield('2..',"a") : $record->subfield('1..', 'a');
+ return \%cell;
+}
+
+=head2 BuildAuthHierarchyBranch
+
+ $branch = &BuildAuthHierarchyBranch( $tree, $authid[, $cnt])
+
+Return a data structure representing an authority hierarchy
+given a list of authorities representing a single branch in
+an authority hierarchy tree. $authid is the current node in
+the tree (which may or may not be somewhere in the middle).
+$cnt represents the level of the upper-most item, and is only
+used when BuildAuthHierarchyBranch is called recursively (i.e.,
+don't ever pass in anything but zero to it).