Lines 415-423
sub AddMember {
Link Here
|
415 |
} |
415 |
} |
416 |
} |
416 |
} |
417 |
|
417 |
|
|
|
418 |
my $p = Koha::Patron->new( { userid => $data{userid} } ); |
418 |
# generate a proper login if none provided |
419 |
# generate a proper login if none provided |
419 |
$data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} ) |
420 |
$data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{'firstname'}, $data{'surname'} ) |
420 |
if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) ); |
421 |
if ( $data{'userid'} eq '' || ! $p->has_valid_userid ); |
421 |
|
422 |
|
422 |
# add expiration date if it isn't already there |
423 |
# add expiration date if it isn't already there |
423 |
$data{dateexpiry} ||= $category->get_expiry_date; |
424 |
$data{dateexpiry} ||= $category->get_expiry_date; |
Lines 523-529
sub Check_Userid {
Link Here
|
523 |
$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. |
524 |
$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. |
524 |
|
525 |
|
525 |
return : |
526 |
return : |
526 |
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). |
527 |
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). |
527 |
|
528 |
|
528 |
=cut |
529 |
=cut |
529 |
|
530 |
|
Lines 531-546
sub Generate_Userid {
Link Here
|
531 |
my ($borrowernumber, $firstname, $surname) = @_; |
532 |
my ($borrowernumber, $firstname, $surname) = @_; |
532 |
my $newuid; |
533 |
my $newuid; |
533 |
my $offset = 0; |
534 |
my $offset = 0; |
534 |
#The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique) |
535 |
my $patron = Koha::Patron->new; |
|
|
536 |
#The script will "do" the following code and increment the $offset until the generated userid is unique |
535 |
do { |
537 |
do { |
536 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
538 |
$firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
537 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
539 |
$surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g; |
538 |
$newuid = lc(($firstname)? "$firstname.$surname" : $surname); |
540 |
$newuid = lc(($firstname)? "$firstname.$surname" : $surname); |
539 |
$newuid = unac_string('utf-8',$newuid); |
541 |
$newuid = unac_string('utf-8',$newuid); |
540 |
$newuid .= $offset unless $offset == 0; |
542 |
$newuid .= $offset unless $offset == 0; |
|
|
543 |
$patron->userid( $newuid ); |
541 |
$offset++; |
544 |
$offset++; |
542 |
|
545 |
} while (! $patron->has_valid_userid ); |
543 |
} while (!Check_Userid($newuid,$borrowernumber)); |
|
|
544 |
|
546 |
|
545 |
return $newuid; |
547 |
return $newuid; |
546 |
} |
548 |
} |