X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fmarc_subfields_structure.pl;h=25196491b14cb14c06b61aa2db3fa49604e28bf8;hb=refs%2Fheads%2Fkoha_ffzg;hp=bfaa3dc68140b639e705a42df11c3f330f16d527;hpb=8c14c25521eac92a2cb62ab5330deac2e2d5343d;p=koha.git diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index bfaa3dc681..25196491b1 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -24,6 +24,7 @@ use CGI qw ( -utf8 ); use C4::Context; use Koha::Authority::Types; +use Koha::AuthorisedValueCategories; use List::MoreUtils qw( uniq ); @@ -64,7 +65,8 @@ my $tagfield = $input->param('tagfield'); 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( @@ -73,11 +75,11 @@ 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; @@ -128,14 +130,8 @@ if ( $op eq 'add_form' ) { $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 ); @@ -176,7 +172,7 @@ if ( $op eq 'add_form' ) { $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'}; @@ -267,7 +263,6 @@ elsif ( $op eq 'add_validate' ) { 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; @@ -285,55 +280,58 @@ elsif ( $op eq 'add_validate' ) { 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, + ); } } } @@ -341,7 +339,8 @@ elsif ( $op eq 'add_validate' ) { $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-$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; @@ -375,17 +374,16 @@ elsif ( $op eq 'delete_confirm' ) { } 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-$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;