From 4265d3a1969796ae18402eebd32042b7dc4fe157 Mon Sep 17 00:00:00 2001 From: Jesse Weaver Date: Mon, 31 Aug 2015 17:45:16 -0600 Subject: [PATCH] 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. --- C4/Members.pm | 4 +- Koha/Template/Plugin/Categories.pm | 15 +++++++ ...lfRegistrationBorrowerUnwantedField_syspref.sql | 2 + .../bootstrap/en/modules/opac-memberentry.tt | 52 ++++++++++++++++++++-- opac/opac-memberentry.pl | 14 +++++- 5 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_14659-add_cardnumber_categorycode_PatronSelfRegistrationBorrowerUnwantedField_syspref.sql diff --git a/C4/Members.pm b/C4/Members.pm index 95fb4e7..b029963 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -2466,14 +2466,14 @@ sub GetBorrowersWithEmail { sub AddMember_Opac { my ( %borrower ) = @_; - $borrower{'categorycode'} = C4::Context->preference('PatronSelfRegistrationDefaultCategory'); + $borrower{'categorycode'} //= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); my $sr = new String::Random; $sr->{'A'} = [ 'A'..'Z', 'a'..'z' ]; my $password = $sr->randpattern("AAAAAAAAAA"); $borrower{'password'} = $password; - $borrower{'cardnumber'} = fixup_cardnumber(); + $borrower{'cardnumber'} = fixup_cardnumber( $borrower{'cardnumber'} ); my $borrowernumber = AddMember(%borrower); diff --git a/Koha/Template/Plugin/Categories.pm b/Koha/Template/Plugin/Categories.pm index 86630ca..fe8b0d7 100644 --- a/Koha/Template/Plugin/Categories.pm +++ b/Koha/Template/Plugin/Categories.pm @@ -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 diff --git a/installer/data/mysql/atomicupdate/bug_14659-add_cardnumber_categorycode_PatronSelfRegistrationBorrowerUnwantedField_syspref.sql b/installer/data/mysql/atomicupdate/bug_14659-add_cardnumber_categorycode_PatronSelfRegistrationBorrowerUnwantedField_syspref.sql new file mode 100644 index 0000000..47f2515 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_14659-add_cardnumber_categorycode_PatronSelfRegistrationBorrowerUnwantedField_syspref.sql @@ -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%'; 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 4eed652..5cc9580 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -1,3 +1,4 @@ +[% USE Categories %] [% USE Koha %] [% USE KohaDates %] [% SET userupdateview = 1 %] @@ -50,7 +51,7 @@
You have not filled out all required fields. Please fill in all missing fields and resubmit.
[% END %] - [% IF invalid_form_fields %] + [% IF invalid_form_fields %]
The following fields contain invalid information:
    [% FOREACH field IN invalid_form_fields %] @@ -63,6 +64,17 @@
[% END %] + [% IF cardnumber_wrong_length || cardnumber_already_exists %] +
+ [% IF cardnumber_wrong_length %] + The entered card number is the wrong length. + [% ELSIF cardnumber_already_exists %] + The entered card number is already in use. + [% END %] + Please correct this and resubmit. +
+ [% END %] + [% IF failed_captcha %]
You typed in the wrong characters in the box before submitting. Please try again.
[% END %] @@ -74,10 +86,21 @@ Library
    - [% UNLESS hidden.defined('cardnumber') %] + [% UNLESS hidden.defined('cardnumber') || Koha.Preference('autoMemberNum') %]
  1. - - [% borrower.cardnumber %] + [% IF mandatory.defined('cardnumber') %] +
  2. [% END %] @@ -108,6 +131,27 @@ [% END %] + + [% UNLESS hidden.defined('categorycode') %] +
  3. + + + [% IF borrower %] + + [% ELSE %] + [% Categories.GetName( borrower.categorycode ) %] + [% END %] +
  4. + [% END %]
[% END # / defined 'branchcode' %] diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index f9f9bc7..504b29c 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -77,8 +77,20 @@ if ( $action eq 'create' ) { my @empty_mandatory_fields = CheckMandatoryFields( \%borrower, $action ); my $invalidformfields = CheckForInvalidFields(\%borrower); + 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, -- 2.5.0