From 3687d029f833da2e0abb7fadaa79656fa1324d5a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 29 Aug 2013 13:37:40 +0200 Subject: [PATCH] Bug 10855: New fields on adding/updating a subscription This patch adds the ability to add values for additional fields when adding/updating a subscription. Test plan (test the following on adding a new subscription and on editing an existent one): - add/edit a subscription. - verify all additional fields appears into the "Additional fields" block. - fill a value for af1 and af3. - fill others values if you are adding a new subscription. - save. - verify values appears on the detail of the subscription page. - verify the af2 field is automatically filled with the specified marc field of the notice. Signed-off-by: Brendan Gallagher --- C4/Serials.pm | 10 +++++ .../prog/en/modules/serials/subscription-add.tt | 34 ++++++++++++++++ .../prog/en/modules/serials/subscription-detail.tt | 25 +++++++++++- serials/subscription-add.pl | 41 ++++++++++++++++++++ serials/subscription-detail.pl | 8 ++++ 5 files changed, 117 insertions(+), 1 deletion(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 49325cb..35eb582 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -31,6 +31,7 @@ use C4::Log; # logaction use C4::Debug; use C4::Serials::Frequency; use C4::Serials::Numberpattern; +use Koha::AdditionalField; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -293,7 +294,16 @@ sub GetSubscription { my $sth = $dbh->prepare($query); $sth->execute($subscriptionid); my $subscription = $sth->fetchrow_hashref; + $subscription->{cannotedit} = not can_edit_subscription( $subscription ); + + # Add additional fields to the subscription into a new key "additional_fields" + my $additional_field_values = Koha::AdditionalField->fetch_all_values({ + tablename => 'subscription', + record_id => $subscriptionid, + }); + $subscription->{additional_fields} = $additional_field_values->{$subscriptionid}; + return $subscription; } 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 8401968..7150dd5 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 @@ -821,6 +821,40 @@ $(document).ready(function() { + + [% 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 %]) + [% ELSE %] + [% IF field.marcfield %] + + This value will be filled with the [% field.marcfield %] subfield of the selected biblio. + [% ELSE %] + + [% END %] + [% END %] +
  2. + [% END %] +
+
+
+ [% END %] +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index b684e5e..9222779 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -1,4 +1,5 @@ [% USE Branches %] +[% USE KohaAuthorisedValues %] [% INCLUDE 'doc-head-open.inc' %] Koha › Serials › Details for subscription #[% subscriptionid %] [% INCLUDE 'doc-head-close.inc' %] @@ -122,7 +123,29 @@ $(document).ready(function() { - + + + [% IF additional_fields_for_subscription %] +
+
+
+ Additional fields: +
    + [% FOR field IN additional_fields_for_subscription %] +
  1. + [% field.name %]: + [% IF field.authorised_value_category %] + [% KohaAuthorisedValues.GetByCode( field.authorised_value_category, additional_fields.${field.name} ) %] + [% ELSE %] + [% additional_fields.${field.name} %] + [% END %] +
  2. + [% END %] +
+
+
+
+ [% END %]
diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index fa75f06..cf6ac58 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -32,6 +32,7 @@ use C4::Serials; use C4::Serials::Frequency; use C4::Serials::Numberpattern; use C4::Letters; +use Koha::AdditionalField; use Carp; #use Smart::Comments; @@ -153,6 +154,16 @@ my $locations_loop = GetAuthorisedValues("LOC",$subs->{'location'}); $template->param(branchloop => $branchloop, locations_loop=>$locations_loop, ); + + +my $additional_fields = Koha::AdditionalField->all( { table => '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 ); + # prepare template variables common to all $op conditions: if ($op!~/^mod/) { my $letters = get_letter_loop(); @@ -341,6 +352,16 @@ sub redirect_add_subscription { $skip_serialseq ); + my $additional_fields = Koha::AdditionalField->all( { table => 'subscription' } ); + my @additional_field_values; + for my $field ( @$additional_fields ) { + my $af = Koha::AdditionalField->new({ id => $field->{id} }); + $af->{values} = { + $subscriptionid => $query->param('additional_fields_' . $field->{name}) + }; + $af->insert_values; + } + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); return; } @@ -416,6 +437,26 @@ sub redirect_mod_subscription { $skip_serialseq ); + my $additional_fields = Koha::AdditionalField->all( { table => 'subscription' } ); + my @additional_field_values; + for my $field ( @$additional_fields ) { + my $af = Koha::AdditionalField->new({ id => $field->{id} })->fetch; + if ( $af->{marcfield} ) { + my $record = GetMarcBiblio( $biblionumber, 1 ); + my ( $field, $subfield ) = split /\$/, $af->{marcfield}; + next unless $field and $subfield; + my $value = $record->subfield( $field, $subfield ); + $af->{values} = { + $subscriptionid => $value + }; + } else { + $af->{values} = { + $subscriptionid => $query->param('additional_fields_' . $field->{name}) + }; + } + $af->insert_values; + } + print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); return; } diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index ebdc415..be1a3a7 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -139,6 +139,14 @@ if ( defined $subscriptionid ) { } } +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( subscriptionid => $subscriptionid, serialslist => \@serialslist, -- 1.7.10.4