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

(-)a/C4/Members.pm (-3 / +27 lines)
Lines 791-802 sub AddMember { Link Here
791
    return $data{'borrowernumber'};
791
    return $data{'borrowernumber'};
792
}
792
}
793
793
794
=head2 Check_Userid
795
796
    my $uniqueness = Check_Userid($userid,$borrowernumber);
797
798
    $borrowernumber is optional (i.e. it can contain a blank value). If $userid is passed with a blank $borrowernumber variable, the database will be checked for all instances of that userid (i.e. userid=? AND borrowernumber != ''). 
799
    
800
    If $borrowernumber is provided, the database will be checked for every instance of that userid coupled with a different borrower(number) than the one provided.
801
802
    return :
803
        0 for not unique (i.e. this $userid already exists)
804
        1 for unique (i.e. this $userid does not exist, or this $userid/$borrowernumber combination already exists)
805
806
=cut
794
807
795
sub Check_Userid {
808
sub Check_Userid {
796
    my ($uid,$member) = @_;
809
    my ($uid,$member) = @_;
797
    my $dbh = C4::Context->dbh;
810
    my $dbh = C4::Context->dbh;
798
    # Make sure the userid chosen is unique and not theirs if non-empty. If it is not,
799
    # Then we need to tell the user and have them create a new one.
800
    my $sth =
811
    my $sth =
801
      $dbh->prepare(
812
      $dbh->prepare(
802
        "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
813
        "SELECT * FROM borrowers WHERE userid=? AND borrowernumber != ?");
Lines 809-818 sub Check_Userid { Link Here
809
    }
820
    }
810
}
821
}
811
822
823
=head2 Generate_Userid
824
825
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
826
    
827
    Generate a userid using the $surname and the $firstname (if there is a value in $firstname).
828
    
829
    $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.
830
831
    return :
832
        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).        
833
834
=cut
835
812
sub Generate_Userid {
836
sub Generate_Userid {
813
  my ($borrowernumber, $firstname, $surname) = @_;
837
  my ($borrowernumber, $firstname, $surname) = @_;
814
  my $newuid;
838
  my $newuid;
815
  my $offset = 0;
839
  my $offset = 0;
840
  #The script will "do" the following code and increment the $offset until Check_Userid = 1 (i.e. until $newuid comes back as unique)
816
  do {
841
  do {
817
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
842
    $firstname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
818
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
843
    $surname =~ s/[[:digit:][:space:][:blank:][:punct:][:cntrl:]]//g;
819
- 

Return to bug 9718