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

(-)a/C4/Members.pm (-34 lines)
Lines 86-92 BEGIN { Link Here
86
    #Check data
86
    #Check data
87
    push @EXPORT, qw(
87
    push @EXPORT, qw(
88
        &checkuserpassword
88
        &checkuserpassword
89
        &Check_Userid
90
        &Generate_Userid
89
        &Generate_Userid
91
        &fixup_cardnumber
90
        &fixup_cardnumber
92
        &checkcardnumber
91
        &checkcardnumber
Lines 483-520 sub AddMember { Link Here
483
    return $data{borrowernumber};
482
    return $data{borrowernumber};
484
}
483
}
485
484
486
=head2 Check_Userid
487
488
    my $uniqueness = Check_Userid($userid,$borrowernumber);
489
490
    $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 != '').
491
492
    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.
493
494
    return :
495
        0 for not unique (i.e. this $userid already exists)
496
        1 for unique (i.e. this $userid does not exist, or this $userid/$borrowernumber combination already exists)
497
498
=cut
499
500
sub Check_Userid {
501
    my ( $uid, $borrowernumber ) = @_;
502
503
    return 0 unless ($uid); # userid is a unique column, we should assume NULL is not unique
504
505
    return 0 if ( $uid eq C4::Context->config('user') );
506
507
    my $rs = Koha::Database->new()->schema()->resultset('Borrower');
508
509
    my $params;
510
    $params->{userid} = $uid;
511
    $params->{borrowernumber} = { '!=' => $borrowernumber } if ($borrowernumber);
512
513
    my $count = $rs->count( $params );
514
515
    return $count ? 0 : 1;
516
}
517
518
=head2 Generate_Userid
485
=head2 Generate_Userid
519
486
520
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
487
    my $newuid = Generate_Userid($borrowernumber, $firstname, $surname);
521
- 

Return to bug 19936