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

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

Return to bug 19936