sub AddMember {
my (%data) = @_;
my $dbh = C4::Context->dbh;
# generate a proper login if none provided
$data{'userid'} = Generate_Userid( $data{'borrowernumber'}, $data{
+'firstname'}, $data{'surname'} )
if ( $data{'userid'} eq '' || !Check_Userid( $data{'userid'} ) )
+;
# add expiration date if it isn't already there
unless ( $data{'dateexpiry'} ) {
$data{'dateexpiry'} = GetExpiryDate( $data{'categorycode'}, C4
+::Dates->new()->output("iso") );
}
# add enrollment date if it isn't already there
unless ( $data{'dateenrolled'} ) {
$data{'dateenrolled'} = C4::Dates->new()->output("iso");
}
my $patron_category =
Koha::Database->new()->schema()->resultset('Category')
->find( $data{'categorycode'} );
$data{'privacy'} =
$patron_category->default_privacy() eq 'default' ? 1
: $patron_category->default_privacy() eq 'never' ? 2
: $patron_category->default_privacy() eq 'forever' ? 0
: undef;
# Make a copy of the plain text password for later use
my $plain_text_password = $data{'password'};
# create a disabled account if no password provided
$data{'password'} = ($data{'password'})? hash_password($data{'pass
+word'}) : '!';
$data{'borrowernumber'}=InsertInTable("borrowers",\%data);
# If NorwegianPatronDBEnable is enabled, we set syncstatus to some
+thing that a
# cronjob will use for syncing with NL
if ( exists $data{'borrowernumber'} && C4::Context->preference('No
+rwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDB
+Enable') == 1 ) {
Koha::Database->new->schema->resultset('BorrowerSync')->create
+({
'borrowernumber' => $data{'borrowernumber'},
'synctype' => 'norwegianpatrondb',
'sync' => 1,
'syncstatus' => 'new',
'hashed_pin' => NLEncryptPIN( $plain_text_password ),
});
}
# mysql_insertid is probably bad. not necessarily accurate and my
+sql-specific at best.
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4:
+:Context->preference("BorrowersLog");
AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber
+} );
return $data{'borrowernumber'};
}
=head2 Check_Userid
my $uniqueness = Check_Userid($userid,$borrowernumber);
$borrowernumber is optional (i.e. it can contain a blank value). I
+f $userid is passed with a blank $borrowernumber variable, the databa
+se will be checked for all instances of that userid (i.e. userid=? AN
+D borrowernumber != '').
If $borrowernumber is provided, the database will be checked for e
+very instance of that userid coupled with a different borrower(number
+) than the one provided.
return :
0 for not unique (i.e. this $userid already exists)
1 for unique (i.e. this $userid does not exist, or this $useri
+d/$borrowernumber combination already exists)
=cut
|