Log.pm and Suggestions.pm - simple (correct) Dates.pm integration
[koha.git] / C4 / AuthoritiesMarc.pm
index 1a727bb..d0af4e6 100644 (file)
@@ -516,30 +516,24 @@ sub AddAuthority {
     $sth->execute($authid,$authtypecode,$record->as_usmarc,$record->as_xml_record($format));
     $sth->finish;
   }else{
-  ##Insert the recordID in MARC record 
-    unless ($record->field('001') && $record->field('001')->data() eq $authid){
-        $record->delete_field($record->field('001'));
-        $record->insert_fields_ordered(MARC::Field->new('001',$authid));
-    }
-    # check for field 100 in UNIMARC
-    if (($format eq "UNIMARCAUTH") && !$record->subfield('100','a')) {
-        $record->leader("     nx  j22             ");
-        my $date=POSIX::strftime("%Y%m%d",localtime);    
-        if ($record->field('100')){
-            $record->field('100')->update('a'=>$date."afrey50      ba0");
-        } else {      
-            $record->append_fields(
-            MARC::Field->new('100',' ',' '
-                ,'a'=>$date."afrey50      ba0")
-            );
-        }
-    }
-    # field 152 contains authtypecode (unused field in MARC21, correct place in UNIMARC)
-    $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
-    $dbh->do("lock tables auth_header WRITE");
-    my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
-    $sth->execute($record->as_usmarc,$record->as_xml_record($format),$authid);
-    $sth->finish;
+      $record->add_fields('001',$authid) unless ($record->field('001'));
+      if (($format eq "UNIMARCAUTH") && (!$record->subfield('100','a'))){
+            $record->leader("     nx  j22             ");
+            my $date=POSIX::strftime("%Y%m%d",localtime);    
+            if ($record->field('100')){
+              $record->field('100')->update('a'=>$date."afrey50      ba0");
+            } else {      
+              $record->append_fields(
+                MARC::Field->new('100',' ',' '
+                  ,'a'=>$date."afrey50      ba0")
+              );
+            }      
+      }    
+      $record->add_fields('152','','','b'=>$authtypecode) unless ($record->field('152'));
+      $dbh->do("lock tables auth_header WRITE");
+      my $sth=$dbh->prepare("update auth_header set marc=?,marcxml=? where authid=?");
+      $sth->execute($record->as_usmarc,$record->as_xml_record($format),$authid);
+      $sth->finish;
   }
   $dbh->do("unlock tables");
   ModZebra($authid,'specialUpdate',"authorityserver",$record);
@@ -659,7 +653,8 @@ sub GetAuthType {
     my ($authtypecode) = @_;
     my $dbh=C4::Context->dbh;
     my $sth;
-    if ($authtypecode){
+    if (defined $authtypecode){ # NOTE - in MARC21 framework, '' is a valid authority 
+                                # type
       $sth=$dbh->prepare("select * from auth_types where authtypecode=?");
       $sth->execute($authtypecode);
     } else {
@@ -797,7 +792,12 @@ sub BuildSummary{
   my @fields = $record->fields();
   my $reported_tag;
   # if the library has a summary defined, use it. Otherwise, build a standard one
-  if ($summary) {
+  # FIXME - it appears that the summary field in the authority frameworks
+  #         can work as a display template.  However, this doesn't
+  #         suit the MARC21 version, so for now the "templating"
+  #         feature will be enabled only for UNIMARC for backwards
+  #         compatibility.
+  if ($summary and C4::Context->preference('marcflavour') eq 'UNIMARC') {
     my @fields = $record->fields();
     #             $reported_tag = '$9'.$result[$counter];
     foreach my $field (@fields) {
@@ -874,7 +874,12 @@ sub BuildSummary{
       $summary.= '<p><div class="label">'.$seeheading.'</div></p>' if ($seeheading);
       } else {
       # construct MARC21 summary
+          # FIXME - looping over 1XX is questionable
+          # since MARC21 authority should have only one 1XX
           foreach my $field ($record->field('1..')) {
+              next if "152" eq $field->tag(); # FIXME - 152 is not a good tag to use
+                                              # in MARC21 -- purely local tags really ought to be
+                                              # 9XX
               if ($record->field('100')) {
                   $heading.= $field->as_string('abcdefghjklmnopqrstvxyz68');
               } elsif ($record->field('110')) {
@@ -908,14 +913,12 @@ sub BuildSummary{
               }
           } #See From
           foreach my $field ($record->field('4..')) {
-              $seeheading.= "&nbsp;&nbsp;&nbsp;".$field->as_string()."<br />";
-              $seeheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see:</i> ".$seeheading."<br />";
+              $seeheading.= "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>used for/see from:</i> ".$field->as_string();
           } #See Also
           foreach my $field ($record->field('5..')) {
-              $altheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$field->as_string()."<br />";
-              $altheading.= "&nbsp;&nbsp;&nbsp;".$field->as_string()."<br />";
-              $altheading.= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$altheading."<br />";
+              $altheading.= "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<i>see also:</i> ".$field->as_string();
           }
+          $summary .= ": " if $summary;
           $summary.=$heading.$seeheading.$altheading;
       }
   }