Lines 397-405
sub AddMember {
Link Here
|
397 |
} |
397 |
} |
398 |
} |
398 |
} |
399 |
|
399 |
|
|
|
400 |
my $p = Koha::Patron->new( { userid => $data{userid} } ); |
400 |
# generate a proper login if none provided |
401 |
# generate a proper login if none provided |
401 |
$data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} ) |
402 |
$data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} ) |
402 |
if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) ); |
403 |
if ( $data{'userid'} eq '' || ! $p->has_valid_userid ); |
403 |
|
404 |
|
404 |
# add expiration date if it isn't already there |
405 |
# add expiration date if it isn't already there |
405 |
$data{dateexpiry} ||= $category->get_expiry_date; |
406 |
$data{dateexpiry} ||= $category->get_expiry_date; |
Lines 505-511
sub Check_Userid {
Link Here
|
505 |
$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. |
506 |
$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. |
506 |
|
507 |
|
507 |
return : |
508 |
return : |
508 |
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 Check_Userid finds an existing match for the $newuid in the database). |
509 |
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). |
509 |
|
510 |
|
510 |
=cut |
511 |
=cut |
511 |
|
512 |
|
Lines 513-528
sub Generate_Userid {
Link Here
|
513 |
my ($borrowernumber, $firstname, $surname) = @_; |
514 |
my ($borrowernumber, $firstname, $surname) = @_; |
514 |
my $newuid; |
515 |
my $newuid; |
515 |
my $offset = 0; |
516 |
my $offset = 0; |
516 |
#The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique) |
517 |
my $patron = Koha::Patron->new; |
|
|
518 |
#The script will "do" the following code and increment the $offset until the generated userid is unique |
517 |
do { |
519 |
do { |
518 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
520 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
519 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
521 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
520 |
$newuid = lc(($firstname)? "$firstname.$surname" : $surname); |
522 |
$newuid = lc(($firstname)? "$firstname.$surname" : $surname); |
521 |
$newuid = unac_string('utf-8',$newuid); |
523 |
$newuid = unac_string('utf-8',$newuid); |
522 |
$newuid .= $offset unless $offset == 0; |
524 |
$newuid .= $offset unless $offset == 0; |
|
|
525 |
$patron->userid( $newuid ); |
523 |
$offset++; |
526 |
$offset++; |
524 |
|
527 |
} while (! $patron->has_valid_userid ); |
525 |
} while (!Check_Userid($newuid,$borrowernumber)); |
|
|
526 |
|
528 |
|
527 |
return $newuid; |
529 |
return $newuid; |
528 |
} |
530 |
} |