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