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).

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
This commit is contained in:
Tomás Cohen Arazi 2016-12-19 16:22:17 -03:00 committed by Kyle M Hall
parent bfa3f41032
commit 925e664f42
4 changed files with 55 additions and 23 deletions

View file

@ -62,10 +62,17 @@
[% CASE 'altcontactcountry' %]<span>Alternate contact: Country</span>
[% CASE 'altcontactphone' %]<span>Alternate contact: Phone</span>
[% CASE 'smsalertnumber' %]<span>SMS alert number</span>
[% CASE 'extended_attributes' %]<span>Additional attributes and identifiers</span>
[% CASE %][% field %]
[% END %]
[% END %]
[% BLOCK display_extended_attributes %]
[% FOREACH attr IN attributes %]
<span>[% attr.code %]: [% IF pending %][% attr.value %][% ELSE %][% attr.attribute %][% END %]</span><br/>
[% END %]
[% END %]
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> &rsaquo; Update patron records</div>
<div id="doc2" class="yui-t7">
@ -111,6 +118,9 @@
[% ELSIF key == 'branchcode' %]
<td>[% Branches.GetName( borrowers.$borrowernumber.$key ) %]</td>
<td>[% Branches.GetName( pm.$key ) %]</td>
[% ELSIF ( key == 'extended_attributes' ) %]
<td>[% PROCESS display_extended_attributes attributes=borrowers.$borrowernumber.$key %]</td>
<td>[% PROCESS display_extended_attributes attributes=pm.$key pending=1 %]</td>
[% ELSE %]
<td>[% borrowers.$borrowernumber.$key %]</td>
<td>[% pm.$key %]</td>

View file

@ -911,8 +911,8 @@
[% IF ( pa.type.authorised_value_category ) %]
<select id="[% form_id %]" name="patron_attribute_value">
<option value=""></option>
[% FOREACH auth_val IN AuthorisedValues.Get( pa.type.authorised_value_category, pa_value.value || '', 1 ) %]
[% IF ( auth_val.selected ) %]
[% FOREACH auth_val IN AuthorisedValues.Get( pa.type.authorised_value_category, 1 ) %]
[% IF ( auth_val.authorised_value == pa_value.value ) %]
<option value="[% auth_val.authorised_value %]" selected="selected">
[%# Yes, lib; GetAuthorisedValues takes care of intelligently setting this from lib_opac %]
[% auth_val.lib %]
@ -931,22 +931,12 @@
[% IF ( pa.type.repeatable ) %]
<a href="#" class="clone-attribute">New</a>
[% END %]
[% IF ( pa.type.password_allowed ) %]
</li><li><label for="[% form_id %]_password">Password:</label>
<input type="password" maxlength="64" value="[% pa_value.password %]" id="[% form_id %]_password" name="patron_attribute_password" />
[% ELSE %]
[%# To keep the form inputs lined up in the POST %]
<input type="hidden" name="patron_attribute_password" value="" />
[% 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 %]
</li>
[% END %]

View file

@ -16,14 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
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;

View file

@ -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 => Encode::encode( 'UTF-8', $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;