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