From 84f83012295c90995db48775ff32f06b8d082581 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Wed, 10 Feb 2016 12:29:06 -0700 Subject: [PATCH] Bug 15774: Add additional fields to order baskets MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This also moves the admin page for additional fields for all tables to a single common screen, and factors out display/input parsing logic. Test plan: 1. Create an additional field for a subscription (under Serials -> Add subscription fields). 2. Apply patch. 3. Visit Additional fields under administration, and verify that the field created above still shows under the list for the subscription table. 4. Create at least four fields for aqbasket for each combination of searchable/not-searchable and with/without an authorized value. 5. Create an order basket, and verify that all fields are visible and correctly save. 6. Edit the basket, verifying that changes to these additional fields are saved. 7. Add an order to the basket (contents are irrelevant). 8. Go to advanced search within acquisitions. 9. Verify that only the searchable fields show in the form, and that their contents may be searched. Signed-off-by: Séverine QUEUNE Signed-off-by: Jonathan Druart Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- C4/Acquisition.pm | 11 + Koha/AdditionalField.pm | 98 +++++++++ acqui/basket.pl | 7 + acqui/basketheader.pl | 16 ++ acqui/histsearch.pl | 7 + .../additional-fields.pl | 14 +- .../en/includes/additional-fields-display.inc | 11 + .../en/includes/additional-fields-entry.inc | 33 +++ .../prog/en/includes/admin-menu.inc | 5 +- .../prog/en/includes/filter-orders.inc | 1 + .../prog/en/includes/serials-menu.inc | 1 - .../prog/en/modules/acqui/basket.tt | 2 + .../prog/en/modules/acqui/basketheader.tt | 5 + .../en/modules/admin/additional-fields.tt | 198 ++++++++++++++++++ .../prog/en/modules/admin/admin-home.tt | 6 +- .../prog/en/modules/serials/add_fields.tt | 178 ---------------- .../prog/en/modules/serials/serials-search.tt | 16 +- .../en/modules/serials/subscription-add.tt | 33 +-- serials/serials-search.pl | 21 +- serials/subscription-add.pl | 51 ++--- 20 files changed, 431 insertions(+), 283 deletions(-) rename serials/add_fields.pl => admin/additional-fields.pl (88%) create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc create mode 100644 koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc create mode 100755 koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt delete mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/serials/add_fields.tt diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index b1f7588455..8ed768b2db 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2280,6 +2280,7 @@ sub GetHistory { my $search_children_too = $params{search_children_too} || 0; my $created_by = $params{created_by} || []; my $ordernumbers = $params{ordernumbers} || []; + my $additional_fields = $params{additional_fields} // []; my @order_loop; my $total_qty = 0; @@ -2443,6 +2444,16 @@ sub GetHistory { if ( @$ordernumbers ) { $query .= ' AND (aqorders.ordernumber IN ( ' . join (',', ('?') x @$ordernumbers ) . '))'; push @query_params, @$ordernumbers; + if ( @$additional_fields ) { + my $matching_record_ids_for_additional_fields = Koha::AdditionalField->get_matching_record_ids( { + fields => $additional_fields, + tablename => 'aqbasket', + exact_match => 0, + } ); + return [] unless @$matching_record_ids_for_additional_fields; + + # No parameterization because record IDs come directly from DB + $query .= ' AND aqbasket.basketno IN ( ' . join( ',', @$matching_record_ids_for_additional_fields ) . ' )'; } if ( C4::Context->preference("IndependentBranches") ) { diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm index 563a7f3827..7c4903a65a 100644 --- a/Koha/AdditionalField.pm +++ b/Koha/AdditionalField.pm @@ -265,6 +265,63 @@ sub get_matching_record_ids { ] } +sub update_fields_from_query { + my ( $class, $args ) = @_; + die "BAD CALL: Don't use update_fields_from_query as an instance method" + if ref $class and UNIVERSAL::can($class,'can'); + + my $query = $args->{query}; + my $additional_fields = Koha::AdditionalField->all( { tablename => $args->{tablename} } ); + for my $field ( @$additional_fields ) { + my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch; + if ( $af->{marcfield} ) { + my ( $field, $subfield ) = split /\$/, $af->{marcfield}; + $af->{values} = undef; + if ( $args->{marc_record} and $field and $subfield ) { + my $value = $args->{marc_record}->subfield( $field, $subfield ); + $af->{values} = { + $args->{record_id} => $value + }; + } + } else { + $af->{values} = { + $args->{record_id} => $query->param( 'additional_field_' . $field->{id} ) + } if defined $query->param( 'additional_field_' . $field->{id} ); + } + $af->insert_values; + } +} + +sub get_filters_from_query { + my ( $class, $args ) = @_; + die "BAD CALL: Don't use get_filters_from_query as an instance method" + if ref $class and UNIVERSAL::can($class,'can'); + + my $query = $args->{query}; + my $additional_fields = Koha::AdditionalField->all( { tablename => $args->{tablename}, searchable => 1 } ); + my @additional_field_filters; + for my $field ( @$additional_fields ) { + my $filter_value = $query->param( 'additional_field_' . $field->{id} ); + if ( defined $filter_value and $filter_value ne q|| ) { + push @additional_field_filters, { + name => $field->{name}, + value => $filter_value, + authorised_value_category => $field->{authorised_value_category}, + }; + } + } + + return \@additional_field_filters; +} + +sub get_filters_as_values { + my ( $class, $filters ) = @_; + die "BAD CALL: Don't use get_filters_as_values as an instance method" + if ref $class and UNIVERSAL::can($class,'can'); + + return { map { $_->{name} => $_->{value} } @$filters }; +} + 1; __END__ @@ -414,6 +471,47 @@ This is a static method. } ); +=head2 update_fields_from_query + +Updates fields based on user input (best paired with additional-fields-entry.pl) and optionally a MARC record. + +This is a static method. + + Koha::AdditionalField->update_fields_from_query( { + tablename => 'aqbasket', + input => $input, + record_id => $basketno, + marc_record => GetBiblio( $biblionumber ), + } ); + +=head2 get_filters_from_query + +Extracts a list of search filters from user input, to be used with C and +C. + +This is a static method. + + my $filters = Koha::AdditionalField->get_filters_from_query( { + tablename => 'aqbasket', + input => $input, + } ); + +=head2 get_filters_as_values + +Transforms the result of C into a hashref of C => C, so +user-entered filters can be redisplayed. + + $template->param( + additional_field_values => Koha::AdditionalField->get_filters_as_values( + $filters + ), + ); + + [% INCLUDE 'additional-field-entry.inc' + values=additional_field_values + available=available_additional_fields + %] + =head1 AUTHOR Jonathan Druart diff --git a/acqui/basket.pl b/acqui/basket.pl index 1b55e74763..8a09419155 100755 --- a/acqui/basket.pl +++ b/acqui/basket.pl @@ -43,6 +43,8 @@ use Koha::EDI qw( create_edi_order get_edifact_ean ); use Koha::CsvProfiles; use Koha::Patrons; +use Koha::AdditionalField; + =head1 NAME basket.pl @@ -430,6 +432,11 @@ if ( $op eq 'list' ) { has_budgets => $has_budgets, duplinbatch => $duplinbatch, csv_profiles => [ Koha::CsvProfiles->search({ type => 'sql', used_for => 'export_basket' }) ], + available_additional_fields => Koha::AdditionalField->all( { tablename => 'aqbasket' } ), + additional_field_values => Koha::AdditionalField->fetch_all_values( { + tablename => 'aqbasket', + record_id => $basketno, + } )->{$basketno}, ); } diff --git a/acqui/basketheader.pl b/acqui/basketheader.pl index f4650e8aaa..acd3d67c51 100755 --- a/acqui/basketheader.pl +++ b/acqui/basketheader.pl @@ -54,6 +54,7 @@ use C4::Acquisition qw/GetBasket NewBasket ModBasketHeader/; use C4::Contract qw/GetContracts/; use Koha::Acquisition::Booksellers; +use Koha::AdditionalField; my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( @@ -74,6 +75,8 @@ my $basket; my $op = $input->param('op'); my $is_an_edit = $input->param('is_an_edit'); +$template->param( available_additional_fields => scalar Koha::AdditionalField->all( { tablename => 'aqbasket' } ) ); + if ( $op eq 'add_form' ) { my @contractloop; if ( $basketno ) { @@ -94,6 +97,12 @@ if ( $op eq 'add_form' ) { } } $template->param( is_an_edit => 1); + $template->param( + additional_field_values => Koha::AdditionalField->fetch_all_values( { + tablename => 'aqbasket', + record_id => $basketno, + } )->{$basketno}, + ); } else { #new basket my $basket; @@ -160,6 +169,13 @@ if ( $op eq 'add_form' ) { scalar $input->param('create_items') ); } + + Koha::AdditionalField->update_fields_from_query( { + tablename => 'aqbasket', + record_id => $basketno, + query => $input, + } ); + print $input->redirect('basket.pl?basketno='.$basketno); exit 0; } diff --git a/acqui/histsearch.pl b/acqui/histsearch.pl index 248ff76eb7..a1c7fe6708 100755 --- a/acqui/histsearch.pl +++ b/acqui/histsearch.pl @@ -56,6 +56,7 @@ use C4::Output; use C4::Acquisition; use C4::Debug; use C4::Koha; +use Koha::AdditionalField; use Koha::DateUtils; my $input = new CGI; @@ -97,6 +98,12 @@ unless ( $input->param('from') ) { } $filters->{from_placed_on} = output_pref( { dt => $from_placed_on, dateformat => 'iso', dateonly => 1 } ), $filters->{to_placed_on} = output_pref( { dt => $to_placed_on, dateformat => 'iso', dateonly => 1 } ), +$filters->{additional_fields} = Koha::AdditionalField->get_filters_from_query({ + tablename => 'aqbasket', + query => $input, +} ); + +$template->param( available_additional_fields => scalar Koha::AdditionalField->all( { tablename => 'aqbasket', searchable => 1 } ) ); my $order_loop; # If we're supplied any value then we do a search. Otherwise we don't. diff --git a/serials/add_fields.pl b/admin/additional-fields.pl similarity index 88% rename from serials/add_fields.pl rename to admin/additional-fields.pl index 317f299a98..be85381f98 100755 --- a/serials/add_fields.pl +++ b/admin/additional-fields.pl @@ -27,16 +27,17 @@ my $input = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "serials/add_fields.tt", + template_name => "admin/additional-fields.tt", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => { serials => '*' }, + flagsrequired => { parameters => 1 }, debug => 1, } ); -my $op = $input->param('op') // 'list'; +my $tablename = $input->param('tablename'); +my $op = $input->param('op') // ( $tablename ? 'list' : 'list_tables' ); my $field_id = $input->param('field_id'); my @messages; @@ -65,7 +66,7 @@ if ( $op eq 'add' ) { my $inserted = 0; eval { my $af = Koha::AdditionalField->new({ - tablename => 'subscription', + tablename => $tablename, name => $name, authorised_value_category => $authorised_value_category, marcfield => $marcfield, @@ -106,18 +107,21 @@ if ( $op eq 'add_form' ) { $field = Koha::AdditionalField->new( { id => $field_id } )->fetch; } + $tablename = $field->{tablename}; + $template->param( field => $field, ); } if ( $op eq 'list' ) { - my $fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); + my $fields = Koha::AdditionalField->all( { tablename => $tablename } ); $template->param( fields => $fields ); } $template->param( op => $op, + tablename => $tablename, messages => \@messages, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc new file mode 100644 index 0000000000..41771a8fc1 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-display.inc @@ -0,0 +1,11 @@ +[% USE AuthorisedValues %] +[% FOR field IN available %] +
  • + [% field.name %]: + [% IF field.authorised_value_category %] + [% AuthorisedValues.GetByCode( field.authorised_value_category, values.${field.name} ) %] + [% ELSE %] + [% values.${field.name} %] + [% END %] +
  • +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc new file mode 100644 index 0000000000..a961e55292 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/additional-fields-entry.inc @@ -0,0 +1,33 @@ +[% USE AuthorisedValues %] +[% IF wrap_fieldset != 0 %] +
    + Additional fields +
      +[% END %] + [% FOR field IN available %] +
    1. + + [% IF field.authorised_value_category %] + (Authorised values for [% field.authorised_value_category %]) + [% ELSE %] + [% IF field.marcfield %] + + This value will be filled with the [% field.marcfield %] subfield of the selected biblio. + [% ELSE %] + + [% END %] + [% END %] +
    2. + [% END %] +[% IF wrap_fieldset != 0 %] +
    +
    +[% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index 817b5a6355..b2f32420c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -110,7 +110,7 @@ [% END %] - [% IF ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats ) %] + [% IF ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || ( CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields_baskets || CAN_user_parameters_manage_additional_fields_subscriptions ) %]
    Additional parameters
      @@ -135,6 +135,9 @@ [% IF ( CAN_user_parameters_manage_mana ) %]
    • Share content with Mana KB
    • [% END %] + [% IF ( CAN_user_parameters_manage_additional_fields_baskets || CAN_user_parameters_manage_additional_fields_subscriptions ) %] +
    • Additional fields
    • + [% END %]
    [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc index 208b2dcef2..42a3060c68 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc @@ -20,6 +20,7 @@ + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_filters wrap_fieldset=0 %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc index af85c11c69..e99b6141c7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/serials-menu.inc @@ -30,7 +30,6 @@ Manage numbering patterns
  • -
  • Add subscription fields
  • [% IF Koha.Preference('Mana') == 1 %]
  • Search on Mana
  • [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt index 43517f83ce..d07f43c103 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt @@ -275,6 +275,8 @@ [% END %] + [% INCLUDE 'additional-fields-display.inc' available=available_additional_fields values=additional_field_values %] + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt index 26ff7cd854..f6a89c7dd7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketheader.tt @@ -127,6 +127,11 @@ [% END %] + + [% IF available_additional_fields %] + [% INCLUDE 'additional-fields-entry.inc' available=available_additional_fields values=additional_field_values %] + [% END %] +
    diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt new file mode 100755 index 0000000000..a37401aa80 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt @@ -0,0 +1,198 @@ +[% USE Asset %] +[% USE AuthorisedValues %] +[% SET footerjs = 1 %] +[% INCLUDE 'doc-head-open.inc' %] +Koha › Administration › + [% SWITCH op %] + [% CASE 'add_form' %][% IF field %]Modify additional field '[% field.name %]'[% ELSE %]Add additional field[% END %] + [% CASE %]Manage additional fields + [% END %] + +[% INCLUDE 'doc-head-close.inc' %] +[% Asset.css('css/datatables.css') %] + + + + [% INCLUDE 'header.inc' %] + [% INCLUDE 'cat-search.inc' %] + + + +
    +
    +
    +
    + [% IF op == 'list' %] + + [% END %] + + [% IF messages %] + [% FOR message IN messages %] + [% IF message.code == 'insert' %] + [% IF message.number > 0 %] +
    The field has been inserted
    + [% ELSE %] +
    The field could not be inserted. Perhaps the name already exists?
    + [% END %] + [% ELSIF message.code == 'update' %] + [% IF message.number > 0 %] +
    The field has been updated
    + [% ELSE %] +
    The field could not be updated. Perhaps the name already exists?
    + [% END %] + [% ELSIF message.code == 'delete' %] + [% IF message.number > 0 %] +
    The field has been deleted
    + [% ELSE %] +
    The field could not be deleted. Check the log for errors.
    + [% END %] + [% END %] + [% END %] + [% END %] + + [% IF op == 'list_tables' %] +

    Additional fields

    +

    Select a table:

    + [% BLOCK table_option %] +
  • [% content %] ([% value %])
  • + [% END %] +
      + [% WRAPPER table_option value="aqbasket" %]Order baskets[% END %] + [% WRAPPER table_option value="subscription" %]Subscriptions[% END %] +
    + [% ELSIF op == 'list' %] +

    Additional fields for '[% tablename %]'

    + [% IF fields %] + + + + + + + + + + + + [% FOR field IN fields %] + + + + + + + + [% END %] + +
    NameAuthorised value categoryMARC fieldSearchableActions
    [% field.name %][% field.authorised_value_category %][% field.marcfield %] + [% IF field.searchable %]Yes[% ELSE %]No[% END %] + + Edit + Delete +
    + [% ELSE %] + [% IF tablename %]There are no additional fields defined for this table.[% END %] + [% END %] + [% ELSIF op == 'add_form' %] + [% IF field %] +

    Modify field

    + [% ELSE %] +

    Add field

    + [% END %] +
    +
    +
      +
    1. + + + Required +
    2. +
    3. + + +
    4. +
    5. + + +
    6. +
    7. + + [% IF field.searchable %] + + [% ELSE %] + + [% END %] +
    8. +
    +
    +
    + [% IF field %] + + [% END %] + + + + Cancel +
    +
    + [% END %] + +
    +
    + +
    +[% INCLUDE 'admin-menu.inc' %] +
    +
    + +[% MACRO jsinclude BLOCK %] + [% INCLUDE "datatables.inc" %] + +[% END %] + +[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt index 33312ed089..ee1abfc808 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt @@ -174,7 +174,7 @@ [% END %] - [% IF ( ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_mana ) %] + [% IF ( ( CAN_user_parameters_manage_search_targets || CAN_user_parameters_manage_didyoumean || CAN_user_parameters_manage_column_config || CAN_user_parameters_manage_audio_alerts || CAN_user_parameters_manage_sms_providers && Koha.Preference('SMSSendDriver') == 'Email' ) || CAN_user_parameters_manage_usage_stats || CAN_user_parameters_manage_additional_fields_baskets || CAN_user_parameters_manage_additional_fields_subscriptions || CAN_user_parameters_manage_mana ) %]

    Additional parameters

    - -
    - -
    -
    - -[% MACRO jsinclude BLOCK %] - [% INCLUDE "datatables.inc" %] - -[% END %] - -[% INCLUDE 'intranet-bottom.inc' %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt index ffdcc14ac3..80cf0d6260 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-search.tt @@ -258,21 +258,7 @@ - [% FOR field IN additional_fields_for_subscription %] -
  • - - [% IF field.authorised_value_choices %] - - [% ELSE %] - - [% END %] -
  • - [% END %] + [% INCLUDE 'additional-fields-entry.inc' available=additional_fields_for_subscription values=additional_field_filters wrap_fieldset=0 %] [% IF ( mana ) %][% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index 714bd755b6..e2f6949a79 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -451,36 +451,9 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
    [% IF additional_fields_for_subscription %] -
    -
    - Additional fields -
      - [% FOR field IN additional_fields_for_subscription %] -
    1. - - [% IF field.authorised_value_choices %] - (Authorised values for [% field.authorised_value_category | html %]) - [% ELSE %] - [% IF field.marcfield %] - - This value will be filled with the [% field.marcfield | html %] subfield of the selected biblio. - [% ELSE %] - - [% END %] - [% END %] -
    2. - [% END %] -
    -
    -
    +
    + [% INCLUDE 'additional-fields-entry.inc' available=additional_fields_for_subscription values=additional_fields %] +
    [% END %] diff --git a/serials/serials-search.pl b/serials/serials-search.pl index 5d23f211e7..976b12815c 100755 --- a/serials/serials-search.pl +++ b/serials/serials-search.pl @@ -80,19 +80,10 @@ if ( $op and $op eq "close" ) { my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription', searchable => 1 } ); -my $additional_field_filters; -for my $field ( @$additional_fields ) { - my $filter_value = $query->param('additional_field_' . $field->{id} . '_filter'); - if ( defined $filter_value and $filter_value ne q|| ) { - $additional_field_filters->{ $field->{name} } = { - value => $filter_value, - authorised_value_category => $field->{authorised_value_category}, - }; - } - if ( $field->{authorised_value_category} ) { - $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} ); - } -} +my $additional_field_filters = Koha::AdditionalField->get_filters_from_query( { + tablename => 'subscription', + query => $query, +} ); my $expiration_date_dt = $expiration_date ? dt_from_string( $expiration_date ) : undef; my @subscriptions; @@ -119,7 +110,7 @@ if ($searched){ publisher => $publisher, bookseller => $bookseller, branch => $branch, - additional_fields => [ map{ { name => $_, value => $additional_field_filters->{$_}{value}, authorised_value_category => $additional_field_filters->{$_}{authorised_value_category} } } keys %$additional_field_filters ], + additional_fields => $additional_field_filters, location => $location, expiration_date => $expiration_date_dt, }); @@ -197,7 +188,7 @@ else branches_loop => \@branches_loop, done_searched => $searched, routing => $routing, - additional_field_filters => $additional_field_filters, + additional_field_filters => Koha::AdditionalField->get_filters_as_values( $additional_field_filters ), additional_fields_for_subscription => $additional_fields, marcflavour => (uc(C4::Context->preference("marcflavour"))), mana => $mana diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index 31198c6518..7cc131da5a 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -144,14 +144,7 @@ $template->param( locations_loop=>$locations_loop, ); - -my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); -for my $field ( @$additional_fields ) { - if ( $field->{authorised_value_category} ) { - $field->{authorised_value_choices} = GetAuthorisedValues( $field->{authorised_value_category} ); - } -} -$template->param( additional_fields_for_subscription => $additional_fields ); +$template->param( additional_fields_for_subscription => scalar Koha::AdditionalField->all( { tablename => 'subscription' } ) ); my $typeloop = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } }; @@ -376,8 +369,13 @@ sub redirect_add_subscription { my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription'); $template->param( mana_msg => $result->{msg} ); } - my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); - insert_additional_fields( $additional_fields, $biblionumber, $subscriptionid ); + + Koha::AdditionalField->update_fields_from_query( { + tablename => 'subscription', + record_id => $subscriptionid, + query => $query, + marc_record => GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }) + } ); print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); return; @@ -480,34 +478,13 @@ sub redirect_mod_subscription { $skip_serialseq, $itemtype, $previousitemtype, $mana_id ); - my $additional_fields = Koha::AdditionalField->all( { tablename => 'subscription' } ); - insert_additional_fields( $additional_fields, $biblionumber, $subscriptionid ); + Koha::AdditionalField->update_fields_from_query( { + tablename => 'subscription', + record_id => $subscriptionid, + query => $query, + marc_record => GetMarcBiblio({ biblionumber => $biblionumber, embed_items => 1 }) + } ); print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); return; } - -sub insert_additional_fields { - my ( $additional_fields, $biblionumber, $subscriptionid ) = @_; - my $record = GetMarcBiblio({ - biblionumber => $biblionumber, - embed_items => 1 }); - for my $field ( @$additional_fields ) { - my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch; - if ( $af->{marcfield} ) { - my ( $field, $subfield ) = split /\$/, $af->{marcfield}; - $af->{values} = undef; - if ( $field and $subfield ) { - my $value = $record->subfield( $field, $subfield ); - $af->{values} = { - $subscriptionid => $value - }; - } - } else { - $af->{values} = { - $subscriptionid => scalar $query->param('additional_field_' . $field->{id}) - } if defined $query->param('additional_field_' . $field->{id}); - } - $af->insert_values; - } -} -- 2.39.5