From 16a919d9191dd4221f7f370cfcd36555428ea9fa Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 Jul 2022 17:00:29 +0200 Subject: [PATCH] Bug 29001: Fix framework edition when subfields are reordered MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit There is a flaw when subfields are ordered, the inputs are not retrieved correctly. We should not rely on the order but use an id instead. Test plan: Create, edit subfields Modify values from the different subfields Confirm that values are correctly saved Signed-off-by: Thibault Kero Signed-off-by: Joonas Kylmälä Signed-off-by: Tomas Cohen Arazi --- admin/marc_subfields_structure.pl | 56 ++++++++----------- .../modules/admin/marc_subfields_structure.tt | 47 ++++++++-------- 2 files changed, 48 insertions(+), 55 deletions(-) diff --git a/admin/marc_subfields_structure.pl b/admin/marc_subfields_structure.pl index a492e5c568..6f14212280 100755 --- a/admin/marc_subfields_structure.pl +++ b/admin/marc_subfields_structure.pl @@ -18,6 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; +use Encode qw( encode_utf8 ); use C4::Output qw( output_html_with_http_headers ); use C4::Auth qw( get_template_and_user ); use CGI qw ( -utf8 ); @@ -211,42 +212,31 @@ if ( $op eq 'add_form' ) { elsif ( $op eq 'add_validate' ) { my $dbh = C4::Context->dbh; $template->param( tagfield => "$input->param('tagfield')" ); - 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'); + my $tagfield = $input->param('tagfield'); + my @tagsubfield = $input->multi_param('tagsubfield'); + my @tab_ids = $input->multi_param('tab_id'); my $display_order; - for ( my $i = 0 ; $i <= $#tagsubfield ; $i++ ) { - my $tagfield = $input->param('tagfield'); - my $tagsubfield = $tagsubfield[$i]; + for my $tagsubfield ( @tagsubfield ) { $tagsubfield = "@" unless $tagsubfield ne ''; - my $liblibrarian = $liblibrarian[$i]; - my $libopac = $libopac[$i]; - my $repeatable = $input->param("repeatable$i") ? 1 : 0; - my $mandatory = $input->param("mandatory$i") ? 1 : 0; - my $important = $input->param("important$i") ? 1 : 0; - my $kohafield = $kohafield[$i]; - my $tab = $tab[$i]; - my $seealso = $seealso[$i]; - my $authorised_value = $authorised_values[$i]; - my $authtypecode = $authtypecodes[$i]; - my $value_builder = $value_builder[$i]; - my $hidden = $hidden[$i]; #input->param("hidden$i"); - my $isurl = $input->param("isurl$i") ? 1 : 0; - my $link = $link[$i]; - my $defaultvalue = $defaultvalue[$i]; - my $maxlength = $maxlength[$i] ? $maxlength[$i] : 9999; - + my $id = shift @tab_ids; + my $liblibrarian = $input->param("liblibrarian_$id"); + my $libopac = $input->param("libopac_$id"); + my $repeatable = $input->param("repeatable_$id") ? 1 : 0; + my $mandatory = $input->param("mandatory_$id") ? 1 : 0; + my $important = $input->param("important_$id") ? 1 : 0; + my $kohafield = $input->param("kohafield_$id"); + my $tab = $input->param("tab_$id"); + my $seealso = $input->param("seealso_$id"); + my $authorised_value = $input->param("authorised_values_$id"); + my $authtypecode = $input->param("authtypecodes_$id"); + my $value_builder = $input->param("value_builder_$id"); + my $hidden = $input->param("hidden_$id"); + my $isurl = $input->param("isurl_$id") ? 1 : 0; + my $link = $input->param("link_$id"); + my $defaultvalue = $input->param("defaultvalue_$id"); + my $maxlength = $input->param("maxlength_$id") || 9999; + if (defined($liblibrarian) && $liblibrarian ne "") { my $mss = Koha::MarcSubfieldStructures->find({tagfield => $tagfield, tagsubfield => $tagsubfield, frameworkcode => $frameworkcode }); if ($mss) { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt index 0ee1b7d199..acaceaef34 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/marc_subfields_structure.tt @@ -161,48 +161,51 @@ [% IF ( subfieldcode == 0 || subfieldcode ) %]
  • Subfield code: - [% loo.subfieldcode | html %] + [% loo.subfieldcode | html %] + +
  • [% ELSE %]
  • +
  • [% END %]
  • - +
  • - +
  • [% IF loo.repeatable %] - + [% ELSE %] - + [% END %]
  • [% IF loo.mandatory %] - + [% ELSE %] - + [% END %]
  • [% IF loo.important %] - + [% ELSE %] - + [% END %]
  • - [%- IF ( loo.tab == -1 ) -%] [%- ELSE -%] @@ -233,17 +236,17 @@
    1. - +
    2. - +
    3. [% IF loo.hidden_protected %] - + [% ELSE %] - + [% END %] @@ -260,21 +263,21 @@
    4. [% IF loo.isurl %] - + [% ELSE %] - + [% END %] If checked, it means that the subfield is a URL and can be clicked
    5. - +
      An index name, e.g. title or Local-Number
    6. - [% FOREACH value IN loo.kohafields %] [% IF ( value == loo.kohafield ) %] @@ -284,7 +287,7 @@ [% END %] - +
    @@ -296,7 +299,7 @@
    1. - [% FOREACH value IN loo.authorised_values %] [% IF ( value == loo.authorised_value ) %] @@ -309,7 +312,7 @@
    2. - [% FOREACH value IN loo.authtypes %] [% IF ( value == loo.authtypecode ) %] @@ -321,7 +324,7 @@
    3. - [% FOREACH value IN loo.value_builders %] [% IF ( value == loo.value_builder ) %] -- 2.39.5