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

(-)a/C4/Members.pm (-34 lines)
Lines 89-95 BEGIN { Link Here
89
    #Check data
89
    #Check data
90
    push @EXPORT, qw(
90
    push @EXPORT, qw(
91
        &checkuserpassword
91
        &checkuserpassword
92
        &Check_Userid
93
        &Generate_Userid
92
        &Generate_Userid
94
        &fixup_cardnumber
93
        &fixup_cardnumber
95
        &checkcardnumber
94
        &checkcardnumber
Lines 466-503 sub AddMember { Link Here
466
    return $data{borrowernumber};
465
    return $data{borrowernumber};
467
}
466
}
468
467
469
=head2 Check_Userid
470
471
    my $uniqueness = Check_Userid($userid,$borrowernumber);
472
473
    $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 != '').
474
475
    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.
476
477
    return :
478
        0 for not unique (i.e. this $userid already exists)
479
        1 for unique (i.e. this $userid does not exist, or this $userid/$borrowernumber combination already exists)
480
481
=cut
482
483
sub Check_Userid {
484
    my ( $uid, $borrowernumber ) = @_;
485
486
    return 0 unless ($uid); # userid is a unique column, we should assume NULL is not unique
487
488
    return 0 if ( $uid eq C4::Context->config('user') );
489
490
    my $rs = Koha::Database->new()->schema()->resultset('Borrower');
491
492
    my $params;
493
    $params->{userid} = $uid;
494
    $params->{borrowernumber} = { '!=' => $borrowernumber } if ($borrowernumber);
495
496
    my $count = $rs->count( $params );
497
498
    return $count ? 0 : 1;
499
}
500
501
=head2 Generate_Userid
468
=head2 Generate_Userid
502
469
503
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
470
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
504
- 

Return to bug 19936