From c132e47efba6ebe1b8dc6922c12a6fe6349a7afc Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 19 Dec 2016 16:22:17 -0300 Subject: [PATCH] Bug 13757: (followup) Staff interface changes This patch adds proper extended attributes display and handling on the patron modifications moderation page (members-update.pl). It also adds changes checking to the opac-memberentry.pl page so it only saves a modification request if there are changes (it only checked regular fields and not the extended ones). --- .../prog/en/modules/members/members-update.tt | 10 +++++++ .../bootstrap/en/modules/opac-memberentry.tt | 14 ++------- members/members-update.pl | 19 ++++++++---- opac/opac-memberentry.pl | 35 ++++++++++++++++++---- 4 files changed, 55 insertions(+), 23 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt index 736cd6e..5e65ed7 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/members-update.tt @@ -62,10 +62,17 @@ [% CASE 'altcontactcountry' %]Alternate contact: Country [% CASE 'altcontactphone' %]Alternate contact: Phone [% CASE 'smsalertnumber' %]SMS alert number +[% CASE 'extended_attributes' %]Additional attributes and identifiers [% CASE %][% field %] [% END %] [% END %] +[% BLOCK display_extended_attributes %] + [% FOREACH attr IN attributes %] + [% attr.code %]: [% IF pending %][% attr.value %][% ELSE %][% attr.attribute %][% END %]
+ [% END %] +[% END %] +
@@ -111,6 +118,9 @@ [% ELSIF key == 'branchcode' %] [% Branches.GetName( borrowers.$borrowernumber.$key ) %] [% Branches.GetName( pm.$key ) %] + [% ELSIF ( key == 'extended_attributes' ) %] + [% PROCESS display_extended_attributes attributes=borrowers.$borrowernumber.$key %] + [% PROCESS display_extended_attributes attributes=pm.$key pending=1 %] [% ELSE %] [% borrowers.$borrowernumber.$key %] [% pm.$key %] diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 422e1a8..91cbae4 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -911,8 +911,8 @@ [% IF ( pa.type.authorised_value_category ) %] - [% ELSE %] - [%# To keep the form inputs lined up in the POST %] - - [% END %] [% ELSE %] [% IF ( pa.type.authorised_value_category ) %] [% AuthorisedValues.GetByCode( pa.type.authorised_value, pa_value.value, 1 ) %] [% ELSE %] [% pa_value.value | html_line_break %] [% END %] - [% IF ( pa_value.password ) %] - (Password: *******) - [% END %] [% END %] [% END %] diff --git a/members/members-update.pl b/members/members-update.pl index 636b8b9..24179e6 100755 --- a/members/members-update.pl +++ b/members/members-update.pl @@ -16,14 +16,16 @@ # You should have received a copy of the GNU General Public License # along with Koha; if not, see . -use strict; -use warnings; +use Modern::Perl; use CGI qw ( -utf8 ); + use C4::Auth; use C4::Output; use C4::Context; use C4::Members; +use C4::Members::Attributes qw( GetBorrowerAttributes ); +use Koha::Patron::Attributes; use Koha::Patron::Modifications; my $query = new CGI; @@ -51,14 +53,19 @@ my $pending_modifications = my $borrowers; foreach my $pm (@$pending_modifications) { - $borrowers->{ $pm->{'borrowernumber'} } = - GetMember( borrowernumber => $pm->{'borrowernumber'} ); - + $borrowers->{ $pm->{borrowernumber} } + = GetMember( borrowernumber => $pm->{borrowernumber} ); + my $patron_attributes = Koha::Patron::Attributes->search( + { borrowernumber => $pm->{borrowernumber} } ); + $borrowers->{ $pm->{'borrowernumber'} }->{extended_attributes} + = $patron_attributes; } $template->param( PendingModifications => $pending_modifications, - borrowers => $borrowers, + borrowers => $borrowers ); output_html_with_http_headers $query, $cookie, $template->output; + +1; diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index a7a94b5..0401fa4 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -21,12 +21,13 @@ use CGI qw ( -utf8 ); use Digest::MD5 qw( md5_base64 md5_hex ); use Encode qw( encode ); use JSON; -use List::MoreUtils qw( each_array uniq ); +use List::MoreUtils qw( any each_array uniq ); use String::Random qw( random_string ); use C4::Auth; use C4::Output; use C4::Members; +use C4::Members::Attributes qw( GetBorrowerAttributes ); use C4::Form::MessagingPreferences; use Koha::Patrons; use Koha::Patron::Modification; @@ -251,7 +252,9 @@ elsif ( $action eq 'update' ) { } else { my %borrower_changes = DelUnchangedFields( $borrowernumber, %borrower ); - if (%borrower_changes) { + my $extended_attributes_changes = ExtendedAttributesMatch( $borrowernumber, $attributes ); + + if ( %borrower_changes || $extended_attributes_changes ) { ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-memberentry-update-submitted.tt", @@ -283,6 +286,7 @@ elsif ( $action eq 'update' ) { action => 'edit', nochanges => 1, borrower => GetMember( borrowernumber => $borrowernumber ), + patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ), csrf_token => Koha::Token->new->generate_csrf({ id => $borrower->{userid}, secret => md5_base64( Encode::encode( 'UTF-8', C4::Context->config('pass') ) ), @@ -468,6 +472,28 @@ sub DelEmptyFields { return %borrower; } +sub ExtendedAttributesMatch { + my ( $borrowernumber, $entered_attributes ) = @_; + + my @patron_attributes_arr = GetBorrowerAttributes( $borrowernumber, 1 ); + my $patron_attributes = $patron_attributes_arr[0]; + + if ( scalar @{$entered_attributes} != scalar @{$patron_attributes} ) { + return 1; + } + + foreach my $attr ( @{$patron_attributes} ) { + next if any { + $_->{code} eq $attr->{code} and $_->{value} eq $attr->{value}; + } + @{$entered_attributes}; + return 1; + } + + return 0; +} + + sub GeneratePatronAttributesForm { my ( $borrowernumber, $entered_attributes ) = @_; @@ -538,9 +564,8 @@ sub ParsePatronAttributes { my @codes = $cgi->multi_param('patron_attribute_code'); my @values = $cgi->multi_param('patron_attribute_value'); - my @passwords = $cgi->multi_param('patron_attribute_password'); - my $ea = each_array( @codes, @values, @passwords ); + my $ea = each_array( @codes, @values ); my @attributes; my %dups = (); @@ -549,7 +574,7 @@ sub ParsePatronAttributes { next if exists $dups{$code}->{$value}; $dups{$code}->{$value} = 1; - push @attributes, { code => $code, value => $value, password => $password }; + push @attributes, { code => $code, value => $value }; } return \@attributes; -- 2.7.4