Bug 18398: Update C4::Message enqueue to use $patron->notice_email_address
[koha-ffzg.git] / authorities / authorities.pl
index e4063d9..538f7cd 100755 (executable)
@@ -24,13 +24,13 @@ use CGI qw ( -utf8 );
 use C4::Auth qw( get_template_and_user );
 use C4::Output qw( output_html_with_http_headers );
 use C4::AuthoritiesMarc qw( AddAuthority ModAuthority GetAuthority GetTagsLabels GetAuthMARCFromKohaField FindDuplicateAuthority );
-use C4::ImportBatch qw( GetImportRecordMarc );
 use C4::Context;
 use Date::Calc qw( Today );
 use MARC::File::USMARC;
 use MARC::File::XML;
 use C4::Biblio qw( TransformHtmlToMarc );
 use Koha::Authority::Types;
+use Koha::Import::Records;
 use Koha::ItemTypes;
 use vars qw( $tagslib);
 use vars qw( $authorised_values_sth);
@@ -48,21 +48,6 @@ builds list, depending on authorised value...
 
 =cut
 
-sub MARCfindbreeding_auth {
-    my ( $id ) = @_;
-    my ($marc, $encoding) = GetImportRecordMarc($id);
-    if ($marc) {
-        my $record = MARC::Record->new_from_usmarc($marc);
-        if ( !defined(ref($record)) ) {
-                return -1;
-        } else {
-            return $record, $encoding;
-        }
-    } else {
-        return -1;
-    }
-}
-
 sub build_authorized_values_list {
     my ( $tag, $subfield, $value, $dbh, $authorised_values_sth,$index_tag,$index_subfield ) = @_;
 
@@ -127,9 +112,17 @@ sub create_input {
         $max_length = 40;
     }
 
-    # if there is no value provided but a default value in parameters, get it
-    if ($value eq '') {
-        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue} if !$cgi->param('authid'); # only for new records
+    # Apply optional framework default value when it is a new record,
+    # or when editing as new (duplicating a record),
+    # based on the ApplyFrameworkDefaults setting.
+    # Substitute date parts, user name
+    my $applydefaults = C4::Context->preference('ApplyFrameworkDefaults');
+    if ( $value eq '' && (
+        ( $applydefaults =~ /new/ && !$cgi->param('authid') ) ||
+        ( $applydefaults =~ /duplicate/ && $cgi->param('op') eq 'duplicate' ) ||
+        ( $applydefaults =~ /imported/ && $cgi->param('breedingid') )
+    ) ) {
+        $value = $tagslib->{$tag}->{$subfield}->{defaultvalue};
         if (!defined $value) {
             $value = q{};
         }
@@ -329,7 +322,7 @@ sub GetMandatoryFieldZ3950 {
 }
 
 sub build_tabs {
-    my ( $template, $record, $dbh, $encoding,$input ) = @_;
+    my ( $template, $record, $dbh, $input ) = @_;
 
     # fill arrays
     my @loop_data = ();
@@ -365,7 +358,7 @@ sub build_tabs {
 
             # if MARC::Record is not empty =>use it as master loop, then add missing subfields that should be in the tab.
             # if MARC::Record is empty => use tab as master loop.
-            if ( $record != -1 && ( $record->field($tag) || $tag eq '000' ) ) {
+            if ( $record && ( $record->field($tag) || $tag eq '000' ) ) {
                 my @fields;
                 if ( $tag ne '000' ) {
                                 @fields = $record->field($tag);
@@ -571,13 +564,14 @@ $template->param(nonav   => $nonav,index=>$myindex,authtypecode=>$authtypecode,b
 $tagslib = GetTagsLabels(1,$authtypecode);
 $mandatory_z3950 = GetMandatoryFieldZ3950($authtypecode);
 
-my $record=-1;
-my $encoding="";
-if (($authid) && !($breedingid)){
-    $record = GetAuthority($authid);
-}
+my $record;
 if ($breedingid) {
-    ( $record, $encoding ) = MARCfindbreeding_auth( $breedingid );
+    my $import_record = Koha::Import::Records->find($breedingid);
+    if ($import_record) {
+        $record = $import_record->get_marc_record();
+    }
+} elsif ($authid) {
+    $record = GetAuthority($authid);
 }
 
 my ($oldauthnumtagfield,$oldauthnumtagsubfield);
@@ -619,7 +613,7 @@ if ($op eq "add") {
         exit;
     } else {
     # it may be a duplicate, warn the user and do nothing
-        build_tabs($template, $record, $dbh, $encoding,$input);
+        build_tabs($template, $record, $dbh, $input);
         build_hidden_data;
         $template->param(authid =>$authid,
                         duplicateauthid     => $duplicateauthid,
@@ -640,7 +634,7 @@ if ($op eq "duplicate")
         {
                 $authid = "";
         }
-        build_tabs ($template, $record, $dbh,$encoding,$input);
+        build_tabs ($template, $record, $dbh, $input);
         build_hidden_data;
         $template->param(oldauthtypetagfield=>$oldauthtypetagfield, oldauthtypetagsubfield=>$oldauthtypetagsubfield,
                         oldauthnumtagfield=>$oldauthnumtagfield, oldauthnumtagsubfield=>$oldauthnumtagsubfield,