View | Details | Raw Unified | Return to bug 19936
Collapse All | Expand All

(-)a/C4/Members.pm (-34 lines)
Lines 88-94 BEGIN { Link Here
88
    #Check data
88
    #Check data
89
    push @EXPORT, qw(
89
    push @EXPORT, qw(
90
        &checkuserpassword
90
        &checkuserpassword
91
        &Generate_Userid
92
        &fixup_cardnumber
91
        &fixup_cardnumber
93
        &checkcardnumber
92
        &checkcardnumber
94
    );
93
    );
Lines 464-501 sub AddMember { Link Here
464
    return $data{borrowernumber};
463
    return $data{borrowernumber};
465
}
464
}
466
465
467
=head2 Generate_Userid
468
469
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
470
471
    Generate a userid using the $surname and the $firstname (if there is a value in $firstname).
472
473
    $borrowernumber is optional (i.e. it can contain a blank value). A value is passed when generating a new userid for an existing borrower. When a new userid is created for a new borrower, a blank value is passed to this sub.
474
475
    return :
476
        new userid ($firstname.$surname if there is a $firstname, or $surname if there is no value in $firstname) plus offset (0 if the $newuid is unique, or a higher numeric value if not unique).
477
478
=cut
479
480
sub Generate_Userid {
481
  my ($borrowernumber, $firstname, $surname) = @_;
482
  my $newuid;
483
  my $offset = 0;
484
  my $patron = Koha::Patron->new;
485
  #The script will "do" the following code and increment the $offset until the generated userid is unique
486
  do {
487
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
488
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
489
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
490
    $newuid = unac_string('utf-8',$newuid);
491
    $newuid .= $offset unless $offset == 0;
492
    $patron->userid( $newuid );
493
    $offset++;
494
   } while (! $patron->has_valid_userid );
495
496
   return $newuid;
497
}
498
499
=head2 fixup_cardnumber
466
=head2 fixup_cardnumber
500
467
501
Warning: The caller is responsible for locking the members table in write
468
Warning: The caller is responsible for locking the members table in write
502
- 

Return to bug 19936