Bug 14659: Allow patrons to enter card number and patron category on OPAC registration page

Test plan:
  1. Open OPAC self-registration page while logged out.
  2. Note that cardnumber and categorycode are not shown.
  3. Remove cardnumber and categorycode from
     PatronSelfRegistrationBorrowerUnwantedField.
  4. Enable autoMemberNum.
  5. Reload self-registration page, note that categorycode now shows.
  6. Disable autoMemberNum.
  7. Reload self-registration page, note that cardnumber now shows.
  8. Try saving a patron with an existing cardnumber; this should fail
     and explain why.
  9. Set CardnumberLength, and verify that those length restrictions are
     enforced.
 10. Verify that patron can be created with custom categorycode and
     cardnumber.

Signed-off-by: Michael Sauers <msauers@dospace.org>

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

Signed-off-by: Brendan Gallagher brendan@bywatersolutions.com
This commit is contained in:
Jesse Weaver 2015-08-31 17:45:16 -06:00 committed by Brendan Gallagher
parent ef2decc489
commit cdbb63f856
5 changed files with 80 additions and 7 deletions

View File

@ -2414,7 +2414,7 @@ sub GetBorrowersWithEmail {
sub AddMember_Opac {
my ( %borrower ) = @_;
$borrower{'categorycode'} = C4::Context->preference('PatronSelfRegistrationDefaultCategory');
$borrower{'categorycode'} //= C4::Context->preference('PatronSelfRegistrationDefaultCategory');
if (not defined $borrower{'password'}){
my $sr = new String::Random;
$sr->{'A'} = [ 'A'..'Z', 'a'..'z' ];
@ -2422,7 +2422,7 @@ sub AddMember_Opac {
$borrower{'password'} = $password;
}
$borrower{'cardnumber'} = fixup_cardnumber();
$borrower{'cardnumber'} = fixup_cardnumber( $borrower{'cardnumber'} );
my $borrowernumber = AddMember(%borrower);

View File

@ -21,6 +21,16 @@ use Template::Plugin;
use base qw( Template::Plugin );
use C4::Category;
use Koha::Database;
sub GetName {
my ( $self, $categorycode ) = @_;
my $schema = Koha::Database->new->schema;
return $schema->resultset( 'Category' )->search( {
categorycode => $categorycode,
} )->get_column( 'description' )->next // '';
}
sub all {
my ( $self, $params ) = @_;
@ -56,6 +66,11 @@ Koha::Template::Plugin::Categories - TT Plugin for categories
In a template, you can get the all categories with
the following TT code: [% Categories.all() %]
=head2 GetName
In a template, you can get the name of a patron category using
[% Categories.GetName( categorycode ) %].
=head1 AUTHOR
Jonathan Druart <jonathan.druart@biblibre.com>

View File

@ -0,0 +1,2 @@
UPDATE systempreferences SET value = CONCAT_WS('|', IF(value = '', NULL, value), 'cardnumber') WHERE variable = 'PatronSelfRegistrationBorrowerUnwantedField' AND value NOT LIKE '%cardnumber%';
UPDATE systempreferences SET value = CONCAT_WS('|', IF(value = '', NULL, value), 'categorycode') WHERE variable = 'PatronSelfRegistrationBorrowerUnwantedField' AND value NOT LIKE '%categorycode%';

View File

@ -1,3 +1,4 @@
[% USE Categories %]
[% USE Koha %]
[% USE KohaDates %]
[% SET userupdateview = 1 %]
@ -53,7 +54,7 @@
<div class="alert">You have not filled out all required fields. Please fill in all missing fields and resubmit.</div>
[% END %]
[% IF invalid_form_fields %]
[% IF invalid_form_fields %]
<div class="alert alert-error"><strong>The following fields contain invalid information:</strong>
<ul>
[% FOREACH field IN invalid_form_fields %]
@ -69,6 +70,17 @@
</div>
[% END %]
[% IF cardnumber_wrong_length || cardnumber_already_exists %]
<div class="alert alert-error">
[% IF cardnumber_wrong_length %]
<strong>The entered <a href="#borrower_cardnumber">card number</a> is the wrong length.</strong>
[% ELSIF cardnumber_already_exists %]
<strong>The entered <a href="#borrower_cardnumber">card number</a> is already in use.</strong>
[% END %]
Please correct this and resubmit.
</div>
[% END %]
[% IF failed_captcha %]
<div class="alert">You typed in the wrong characters in the box before submitting. Please try again.</div>
[% END %]
@ -106,10 +118,21 @@
<legend id="library_legend">Library</legend>
<ol>
[% UNLESS hidden.defined('cardnumber') %]
[% UNLESS hidden.defined('cardnumber') || Koha.Preference('autoMemberNum') %]
<li>
<label>Card number:</label>
[% borrower.cardnumber %]
[% IF mandatory.defined('cardnumber') %]
<label for="borrower_cardnumber" class="required">
[% ELSE %]
<label for="borrower_cardnumber">
[% END %]
Library card number:
</label>
[% IF borrower %]
<input type="text" id="borrower_cardnumber" name="borrower_cardnumber" value="[% borrower.cardnumber %]" />
[% IF mandatory.defined('cardnumber') %]<span class="required">Required</span>[% END %]
[% ELSE %]
[% borrower.cardnumber %]
[% END %]
</li>
[% END %]
@ -140,6 +163,27 @@
</select>
</li>
[% END %]
[% UNLESS hidden.defined('categorycode') %]
<li>
<label for="borrower_categorycode">
Category:</label>
[% IF borrower %]
<select id="borrower_categorycode" name="borrower_categorycode">
[% FOREACH c IN Categories.all() %]
[% IF c.categorycode == Koha.Preference('PatronSelfRegistrationDefaultCategory') %]
<option value="[% c.categorycode %]" selected="selected">[% c.description %]</option>
[% ELSE %]
<option value="[% c.categorycode %]">[% c.description %]</option>
[% END %]
[% END %]
</select>
[% ELSE %]
[% Categories.GetName( borrower.categorycode ) %]
[% END %]
</li>
[% END %]
</ol>
</fieldset>
[% END # / defined 'branchcode' %]

View File

@ -80,8 +80,20 @@ if ( $action eq 'create' ) {
my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action );
my $invalidformfields = CheckForInvalidFields(\%borrower);
delete $borrower{'password2'};
my $cardnumber_error_code;
if ( !grep { $_ eq 'cardnumber' } @empty_mandatory_fields ) {
# No point in checking the cardnumber if it's missing and mandatory, it'll just generate a
# spurious length warning.
$cardnumber_error_code = checkcardnumber( $borrower{cardnumber}, $borrower{borrowernumber} );
}
if ( @empty_mandatory_fields || @$invalidformfields || $cardnumber_error_code ) {
if ( $cardnumber_error_code == 1 ) {
$template->param( cardnumber_already_exists => 1 );
} elsif ( $cardnumber_error_code == 2 ) {
$template->param( cardnumber_wrong_length => 1 );
}
if (@empty_mandatory_fields || @$invalidformfields) {
$template->param(
empty_mandatory_fields => \@empty_mandatory_fields,
invalid_form_fields => $invalidformfields,