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

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

Return to bug 19936