This patch change the method used to generate a new login for a user when his 
informations are modified(memberentry.pl).

Before the login are generated with the first letter of lastname and the 9 
first letter of the surname, and do not verify the
login already exist).
Now the login will be lastname.surnameX, where X is an incremented digit if the 
login already exists.
---
 C4/Members.pm          |  167 ++++++++++++++++++++++++++---------------------
 members/memberentry.pl |    6 +--
 2 files changed, 93 insertions(+), 80 deletions(-)

diff --git a/C4/Members.pm b/C4/Members.pm
index 7df9424..735dc5a 100644
--- a/C4/Members.pm
+++ b/C4/Members.pm
@@ -32,80 +32,81 @@ use C4::Biblio;
 our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug);
 
 BEGIN {
-       $VERSION = 3.02;
-       $debug = $ENV{DEBUG} || 0;
-       require Exporter;
-       @ISA = qw(Exporter);
-       #Get data
-       push @EXPORT, qw(
-               &SearchMember 
-               &GetMemberDetails
-               &GetMember
-
-               &GetGuarantees 
-
-               &GetMemberIssuesAndFines
-               &GetPendingIssues
-               &GetAllIssues
-
-               &get_institutions 
-               &getzipnamecity 
-               &getidcity
-
-               &GetAge 
-               &GetCities 
-               &GetRoadTypes 
-               &GetRoadTypeDetails 
-               &GetSortDetails
-               &GetTitles
-
-    &GetPatronImage
-    &PutPatronImage
-    &RmPatronImage
-
-               &GetMemberAccountRecords
-               &GetBorNotifyAcctRecord
-
-               &GetborCatFromCatType 
-               &GetBorrowercategory
-    &GetBorrowercategoryList
-
-               &GetBorrowersWhoHaveNotBorrowedSince
-               &GetBorrowersWhoHaveNeverBorrowed
-               &GetBorrowersWithIssuesHistoryOlderThan
-
-               &GetExpiryDate
-       );
-
-       #Modify data
-       push @EXPORT, qw(
-               &ModMember
-               &changepassword
-       );
-
-       #Delete data
-       push @EXPORT, qw(
-               &DelMember
-       );
-
-       #Insert data
-       push @EXPORT, qw(
-               &AddMember
-               &add_member_orgs
-               &MoveMemberToDeleted
-               &ExtendMemberSubscriptionTo 
-       );
-
-       #Check data
-       push @EXPORT, qw(
-               &checkuniquemember 
-               &checkuserpassword
-               &Check_Userid
-               &fixEthnicity
-               &ethnicitycategories 
-               &fixup_cardnumber
-               &checkcardnumber
-       );
+    $VERSION = 3.02;
+    $debug = $ENV{DEBUG} || 0;
+    require Exporter;
+    @ISA = qw(Exporter);
+    #Get data
+    push @EXPORT, qw(
+        &SearchMember
+        &GetMemberDetails
+        &GetMember
+
+        &GetGuarantees
+
+        &GetMemberIssuesAndFines
+        &GetPendingIssues
+        &GetAllIssues
+
+        &get_institutions
+        &getzipnamecity
+        &getidcity
+
+        &GetAge
+        &GetCities
+        &GetRoadTypes
+        &GetRoadTypeDetails
+        &GetSortDetails
+        &GetTitles
+
+        &GetPatronImage
+        &PutPatronImage
+        &RmPatronImage
+
+        &GetMemberAccountRecords
+        &GetBorNotifyAcctRecord
+
+        &GetborCatFromCatType
+        &GetBorrowercategory
+        &GetBorrowercategoryList
+
+        &GetBorrowersWhoHaveNotBorrowedSince
+        &GetBorrowersWhoHaveNeverBorrowed
+        &GetBorrowersWithIssuesHistoryOlderThan
+
+        &GetExpiryDate
+    );
+
+    #Modify data
+    push @EXPORT, qw(
+        &ModMember
+        &changepassword
+    );
+
+    #Delete data
+    push @EXPORT, qw(
+        &DelMember
+    );
+
+    #Insert data
+    push @EXPORT, qw(
+        &AddMember
+        &add_member_orgs
+        &MoveMemberToDeleted
+        &ExtendMemberSubscriptionTo
+    );
+
+    #Check data
+    push @EXPORT, qw(
+        &checkuniquemember
+        &checkuserpassword
+        &Check_Userid
+        &Generate_Userid
+        &fixEthnicity
+        &ethnicitycategories
+        &fixup_cardnumber
+        &checkcardnumber
+    );
 }
 
 =head1 NAME
@@ -164,7 +165,7 @@ sub SearchMember {
     my $count;
     my @data;
     my @bind = ();
-    
+
     # this is used by circulation everytime a new borrowers cardnumber is 
scanned
     # so we can check an exact match first, if that works return, otherwise do 
the rest
     $query = "SELECT * FROM borrowers
@@ -801,6 +802,22 @@ sub Check_Userid {
     }
 }
 
+sub Generate_Userid {
+  my ($borrowernumber, $firstname, $surname) = @_;
+  my $newuid;
+  my $offset = 0;
+  do {
+    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
+    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
+    $newuid = lc("$firstname.$surname");
+    $newuid .= $offset unless $offset == 0;
+    $offset++;
+
+   } while (!Check_Userid($newuid,$borrowernumber));
+
+   return $newuid;
+}
+
 
 sub changepassword {
     my ( $uid, $member, $digest ) = @_;
diff --git a/members/memberentry.pl b/members/memberentry.pl
index 5dcb648..e845e56 100755
--- a/members/memberentry.pl
+++ b/members/memberentry.pl
@@ -177,13 +177,10 @@ if ($guarantorid eq '') {
 
 #builds default userid
 if ( (defined $newdata{'userid'}) && ($newdata{'userid'} eq '')){
-  my $onefirstnameletter = substr($data{'firstname'},0,1);
-  my  $fivesurnameletter = substr($data{'surname'},0,9);
-  $newdata{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
+  $newdata{'userid'} = Generate_Userid($borrowernumber, $newdata{'firstname'}, 
$newdata{'surname'});
 }
   
 $debug and warn join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth 
dateenrolled dateexpiry);
-my $loginexist=0;
 my $extended_patron_attributes = ();
 if ($op eq 'save' || $op eq 'insert'){
   if (checkcardnumber($newdata{cardnumber},$newdata{borrowernumber})){ 
@@ -210,7 +207,6 @@ if ($op eq 'save' || $op eq 'insert'){
   # Check if the userid is unique
   unless (Check_Userid($newdata{'userid'},$borrowernumber)) {
     push @errors, "ERROR_login_exist";
-    $loginexist=1; 
   }
 
   if (C4::Context->preference('ExtendedPatronAttributes')) {
-- 
1.5.6.3

_______________________________________________
Koha-patches mailing list
[email protected]
http://lists.koha.org/mailman/listinfo/koha-patches

Reply via email to