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

(-)a/C4/Members.pm (-34 lines)
Lines 86-92 BEGIN { Link Here
86
    #Check data
86
    #Check data
87
    push @EXPORT, qw(
87
    push @EXPORT, qw(
88
        &checkuserpassword
88
        &checkuserpassword
89
        &Generate_Userid
90
        &fixup_cardnumber
89
        &fixup_cardnumber
91
        &checkcardnumber
90
        &checkcardnumber
92
    );
91
    );
Lines 482-519 sub AddMember { Link Here
482
    return $data{borrowernumber};
481
    return $data{borrowernumber};
483
}
482
}
484
483
485
=head2 Generate_Userid
486
487
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
488
489
    Generate a userid using the $surname and the $firstname (if there is a value in $firstname).
490
491
    $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.
492
493
    return :
494
        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).
495
496
=cut
497
498
sub Generate_Userid {
499
  my ($borrowernumber, $firstname, $surname) = @_;
500
  my $newuid;
501
  my $offset = 0;
502
  my $patron = Koha::Patron->new;
503
  #The script will "do" the following code and increment the $offset until the generated userid is unique
504
  do {
505
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
506
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
507
    $newuid = lc(($firstname)? "$firstname.$surname" : $surname);
508
    $newuid = unac_string('utf-8',$newuid);
509
    $newuid .= $offset unless $offset == 0;
510
    $patron->userid( $newuid );
511
    $offset++;
512
   } while (! $patron->has_valid_userid );
513
514
   return $newuid;
515
}
516
517
=head2 fixup_cardnumber
484
=head2 fixup_cardnumber
518
485
519
Warning: The caller is responsible for locking the members table in write
486
Warning: The caller is responsible for locking the members table in write
520
- 

Return to bug 19936