Bug 9044: (follow-up) fix merge conflict typo that broke this script
[koha.git] / C4 / AuthoritiesMarc.pm
index f316b17..7443f36 100644 (file)
@@ -379,9 +379,9 @@ Get the record and tries to guess the adequate authtypecode from its content.
 =cut
 
 sub GuessAuthTypeCode {
-    my ($record) = @_;
+    my ($record, $heading_fields) = @_;
     return unless defined $record;
-my $heading_fields = {
+    $heading_fields //= {
     "MARC21"=>{
         '100'=>{authtypecode=>'PERSO_NAME'},
         '110'=>{authtypecode=>'CORPO_NAME'},
@@ -520,7 +520,7 @@ sub GetTagsLabels {
         $res->{$tag}->{repeatable} = $repeatable;
   }
   $sth=      $dbh->prepare(
-"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl 
+"SELECT tagfield,tagsubfield,liblibrarian,libopac,tab, mandatory, repeatable,authorised_value,frameworkcode as authtypecode,value_builder,kohafield,seealso,hidden,isurl,defaultvalue
 FROM auth_subfield_structure 
 WHERE authtypecode=? 
 ORDER BY tagfield,tagsubfield"
@@ -535,12 +535,13 @@ ORDER BY tagfield,tagsubfield"
     my $hidden;
     my $isurl;
     my $link;
+    my $defaultvalue;
 
     while (
         ( $tag,         $subfield,   $liblibrarian,   , $libopac,      $tab,
         $mandatory,     $repeatable, $authorised_value, $authtypecode,
         $value_builder, $kohafield,  $seealso,          $hidden,
-        $isurl,            $link )
+        $isurl,         $defaultvalue, $link )
         = $sth->fetchrow
       )
     {
@@ -556,6 +557,7 @@ ORDER BY tagfield,tagsubfield"
         $res->{$tag}->{$subfield}->{hidden}           = $hidden;
         $res->{$tag}->{$subfield}->{isurl}            = $isurl;
         $res->{$tag}->{$subfield}->{link}            = $link;
+        $res->{$tag}->{$subfield}->{defaultvalue}     = $defaultvalue;
     }
     return $res;
 }
@@ -953,7 +955,11 @@ sub BuildSummary {
 # construct UNIMARC summary, that is quite different from MARC21 one
 # accepted form
         foreach my $field ($record->field('2..')) {
-            push @authorized, { heading => $field->as_string('abcdefghijlmnopqrstuvwxyz'), field => $field->tag() };
+            push @authorized, {
+                heading => $field->as_string('abcdefghijlmnopqrstuvwxyz'),
+                hemain  => $field->subfield('a'),
+                field   => $field->tag(),
+            };
         }
 # rejected form(s)
         foreach my $field ($record->field('3..')) {
@@ -961,7 +967,12 @@ sub BuildSummary {
         }
         foreach my $field ($record->field('4..')) {
             my $thesaurus = $field->subfield('2') ? "thes. : ".$thesaurus{"$field->subfield('2')"}." : " : '';
-            push @seefrom, { heading => $thesaurus . $field->as_string('abcdefghijlmnopqrstuvwxyz'), type => 'seefrom', field => $field->tag() };
+            push @seefrom, {
+                heading => $thesaurus . $field->as_string('abcdefghijlmnopqrstuvwxyz'),
+                hemain  => $field->subfield('a'),
+                type    => 'seefrom',
+                field   => $field->tag(),
+            };
         }
 
         # see :
@@ -972,6 +983,7 @@ sub BuildSummary {
                 field   => $_->tag,
                 type    => $type,
                 heading => $heading,
+                hemain  => $_->subfield('a'),
                 search  => $heading,
                 authid  => $_->subfield('9'),
             }
@@ -979,8 +991,8 @@ sub BuildSummary {
 
         # Other forms
         @otherscript = map { {
-            lang      => $_->subfield('8') || '',
-            term      => $_->subfield('a'),
+            lang      => length ($_->subfield('8')) == 6 ? substr ($_->subfield('8'), 3, 3) : $_->subfield('8') || '',
+            term      => $_->subfield('a') . ($_->subfield('b') ? ', ' . $_->subfield('b') : ''),
             direction => 'ltr',
             field     => $_->tag,
         } } $record->field('7..');
@@ -1022,9 +1034,17 @@ sub BuildSummary {
                 $subfields_to_report = 'vxyz';
             }
             if ($subfields_to_report) {
-                push @authorized, { heading => $field->as_string($subfields_to_report), field => $tag };
+                push @authorized, {
+                    heading => $field->as_string($subfields_to_report),
+                    hemain  => $field->subfield( substr($subfields_to_report, 0, 1) ),
+                    field   => $tag,
+                };
             } else {
-                push @authorized, { heading => $field->as_string(), field => $tag };
+                push @authorized, {
+                    heading => $field->as_string(),
+                    hemain  => $field->subfield('a'),
+                    field   => $tag,
+                };
             }
         }
         foreach my $field ($record->field('4..')) { #See From
@@ -1035,9 +1055,19 @@ sub BuildSummary {
                 $type = 'earlier' if $type && $type ne 'n';
             }
             if ($type eq 'subfi') {
-                push @seefrom, { heading => $field->as_string($marc21subfields), type => ($field->subfield('i') || ''), field => $field->tag() };
+                push @seefrom, {
+                    heading => $field->as_string($marc21subfields),
+                    hemain  => $field->subfield( substr($marc21subfields, 0, 1) ),
+                    type    => ($field->subfield('i') || ''),
+                    field   => $field->tag(),
+                };
             } else {
-                push @seefrom, { heading => $field->as_string($marc21subfields), type => $type, field => $field->tag() };
+                push @seefrom, {
+                    heading => $field->as_string($marc21subfields),
+                    hemain  => $field->subfield( substr($marc21subfields, 0, 1) ),
+                    type    => $type,
+                    field   => $field->tag(),
+                };
             }
         }
         foreach my $field ($record->field('5..')) { #See Also
@@ -1050,18 +1080,20 @@ sub BuildSummary {
             if ($type eq 'subfi') {
                 push @seealso, {
                     heading => $field->as_string($marc21subfields),
-                    type => $field->subfield('i'),
-                    field => $field->tag(),
-                    search => $field->as_string($marc21subfields) || '',
-                    authid => $field->subfield('9') || ''
+                    hemain  => $field->subfield( substr($marc21subfields, 0, 1) ),
+                    type    => $field->subfield('i'),
+                    field   => $field->tag(),
+                    search  => $field->as_string($marc21subfields) || '',
+                    authid  => $field->subfield('9') || ''
                 };
             } else {
                 push @seealso, {
                     heading => $field->as_string($marc21subfields),
-                    type => $type,
-                    field => $field->tag(),
-                    search => $field->as_string($marc21subfields) || '',
-                    authid => $field->subfield('9') || ''
+                    hemain  => $field->subfield( substr($marc21subfields, 0, 1) ),
+                    type    => $type,
+                    field   => $field->tag(),
+                    search  => $field->as_string($marc21subfields) || '',
+                    authid  => $field->subfield('9') || ''
                 };
             }
         }
@@ -1089,6 +1121,7 @@ sub BuildSummary {
         }
     }
     $summary{mainentry} = $authorized[0]->{heading};
+    $summary{mainmainentry} = $authorized[0]->{hemain};
     $summary{authorized} = \@authorized;
     $summary{notes} = \@notes;
     $summary{seefrom} = \@seefrom;