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

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

Return to bug 19936