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);
=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 ) = @_;
$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{};
}
}
sub build_tabs {
- my ( $template, $record, $dbh, $encoding,$input ) = @_;
+ my ( $template, $record, $dbh, $input ) = @_;
# fill arrays
my @loop_data = ();
# 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);
$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);
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,
{
$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,