use C4::Context;
use Koha::Authority::Types;
+use Koha::AuthorisedValueCategories;
use List::MoreUtils qw( uniq );
my $tagsubfield = $input->param('tagsubfield');
my $frameworkcode = $input->param('frameworkcode');
my $pkfield = "tagfield";
-my $offset = $input->param('offset') || 0;
+my $offset = $input->param('offset');
+$offset = 0 if not defined $offset or $offset < 0;
my $script_name = "/cgi-bin/koha/admin/marc_subfields_structure.pl";
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
query => $input,
type => "intranet",
authnotrequired => 0,
- flagsrequired => { parameters => 'parameters_remaining_permissions' },
+ flagsrequired => { parameters => 'manage_marc_frameworks' },
debug => 1,
}
);
-my $cache = Koha::Cache->get_instance();
+my $cache = Koha::Caches->get_instance();
my $op = $input->param('op') || "";
$tagfield =~ s/\,//g;
$sth2->finish;
$sth2 = $dbh->prepare("select distinct category from authorised_values");
$sth2->execute;
- my @authorised_values;
- push @authorised_values, "";
- while ( ( my $category ) = $sth2->fetchrow_array ) {
- push @authorised_values, $category;
- }
- push( @authorised_values, "branches" );
- push( @authorised_values, "itemtypes" );
- push( @authorised_values, "cn_source" );
+ my @av_cat = Koha::AuthorisedValueCategories->search;
+ my @authorised_values = map { $_->category_name } @av_cat;
# build thesaurus categories list
my @authtypes = uniq( "", map { $_->authtypecode } Koha::Authority::Types->search );
$row_data{maxlength} = $data->{maxlength};
$row_data{tab} = $data->{tab};
$row_data{tagsubfield} = $data->{tagsubfield};
- $row_data{subfieldcode} = $data->{'tagsubfield'} eq '@' ? '_' : $data->{'tagsubfield'};
+ $row_data{subfieldcode} = $data->{'tagsubfield'};
$row_data{urisubfieldcode} = $row_data{subfieldcode} eq '%' ? 'pct' : $row_data{subfieldcode};
$row_data{liblibrarian} = $data->{'liblibrarian'};
$row_data{libopac} = $data->{'libopac'};
update marc_subfield_structure set tagfield=?, tagsubfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, kohafield=?, tab=?, seealso=?, authorised_value=?, authtypecode=?, value_builder=?, hidden=?, isurl=?, frameworkcode=?, link=?, defaultvalue=?, maxlength=?
where tagfield=? and tagsubfield=? and frameworkcode=?
});
- my @tagsubfield = $input->param('tagsubfield');
- my @liblibrarian = $input->param('liblibrarian');
- my @libopac = $input->param('libopac');
- my @kohafield = $input->param('kohafield');
- my @tab = $input->param('tab');
- my @seealso = $input->param('seealso');
- my @hidden = $input->param('hidden');
- my @authorised_values = $input->param('authorised_value');
- my @authtypecodes = $input->param('authtypecode');
- my @value_builder = $input->param('value_builder');
- my @link = $input->param('link');
- my @defaultvalue = $input->param('defaultvalue');
- my @maxlength = $input->param('maxlength');
+ my @tagsubfield = $input->multi_param('tagsubfield');
+ my @liblibrarian = $input->multi_param('liblibrarian');
+ my @libopac = $input->multi_param('libopac');
+ my @kohafield = $input->multi_param('kohafield');
+ my @tab = $input->multi_param('tab');
+ my @seealso = $input->multi_param('seealso');
+ my @hidden = $input->multi_param('hidden');
+ my @authorised_values = $input->multi_param('authorised_value');
+ my @authtypecodes = $input->multi_param('authtypecode');
+ my @value_builder = $input->multi_param('value_builder');
+ my @link = $input->multi_param('link');
+ my @defaultvalue = $input->multi_param('defaultvalue');
+ my @maxlength = $input->multi_param('maxlength');
for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) {
my $tagfield = $input->param('tagfield');
my $tagsubfield = $tagsubfield[$i];
$tagsubfield = "@" unless $tagsubfield ne '';
- $tagsubfield = "@" if $tagsubfield eq '_';
my $liblibrarian = $liblibrarian[$i];
my $libopac = $libopac[$i];
my $repeatable = $input->param("repeatable$i") ? 1 : 0;
my $maxlength = $maxlength[$i] ? $maxlength[$i] : 9999;
if (defined($liblibrarian) && $liblibrarian ne "") {
- unless ( C4::Context->config('demo') or C4::Context->config('demo') eq 1 ) {
- if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) {
- $sth_update->execute(
+ if (marc_subfield_structure_exists($tagfield, $tagsubfield, $frameworkcode)) {
+ $sth_update->execute(
+ $tagfield,
+ $tagsubfield,
+ $liblibrarian,
+ $libopac,
+ $repeatable,
+ $mandatory,
+ $kohafield,
+ $tab,
+ $seealso,
+ $authorised_value,
+ $authtypecode,
+ $value_builder,
+ $hidden,
+ $isurl,
+ $frameworkcode,
+ $link,
+ $defaultvalue,
+ $maxlength,
+ (
$tagfield,
$tagsubfield,
- $liblibrarian,
- $libopac,
- $repeatable,
- $mandatory,
- $kohafield,
- $tab,
- $seealso,
- $authorised_value,
- $authtypecode,
- $value_builder,
- $hidden,
- $isurl,
$frameworkcode,
- $link,
- $defaultvalue,
- $maxlength,
- (
- $tagfield,
- $tagsubfield,
- $frameworkcode,
- ),
- );
- } else {
- $sth_insert->execute(
- $tagfield,
- $tagsubfield,
- $liblibrarian,
- $libopac,
- $repeatable,
- $mandatory,
- $kohafield,
- $tab,
- $seealso,
- $authorised_value,
- $authtypecode,
- $value_builder,
- $hidden,
- $isurl,
- $frameworkcode,
- $link,
- $defaultvalue,
- $maxlength,
- );
+ )
+ );
+ } else {
+ if( $frameworkcode ne q{} ) {
+ # BZ 19096: Overwrite kohafield from Default when adding a new record
+ my $rec = Koha::MarcSubfieldStructures->find( q{}, $tagfield, $tagsubfield );
+ $kohafield = $rec->kohafield if $rec;
}
+ $sth_insert->execute(
+ $tagfield,
+ $tagsubfield,
+ $liblibrarian,
+ $libopac,
+ $repeatable,
+ $mandatory,
+ $kohafield,
+ $tab,
+ $seealso,
+ $authorised_value,
+ $authtypecode,
+ $value_builder,
+ $hidden,
+ $isurl,
+ $frameworkcode,
+ $link,
+ $defaultvalue,
+ $maxlength,
+ );
}
}
}
$sth_update->finish;
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+ $cache->clear_from_cache("default_value_for_mod_marc-");
+ $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode");
exit;
}
elsif ( $op eq 'delete_confirmed' ) {
my $dbh = C4::Context->dbh;
- unless ( C4::Context->config('demo') or C4::Context->config('demo') eq 1 ) {
- my $sth =
- $dbh->prepare(
+ my $sth =
+ $dbh->prepare(
"delete from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"
- );
- $sth->execute( $tagfield, $tagsubfield, $frameworkcode );
- $sth->finish;
- }
+ );
+ $sth->execute( $tagfield, $tagsubfield, $frameworkcode );
+ $sth->finish;
$cache->clear_from_cache("MarcStructure-0-$frameworkcode");
$cache->clear_from_cache("MarcStructure-1-$frameworkcode");
+ $cache->clear_from_cache("default_value_for_mod_marc-");
+ $cache->clear_from_cache("MarcSubfieldStructure-$frameworkcode");
print $input->redirect("/cgi-bin/koha/admin/marc_subfields_structure.pl?tagfield=$tagfield&frameworkcode=$frameworkcode");
exit;