From b461a041d0625276b782a7d4b15ebe329ca7a0dc Mon Sep 17 00:00:00 2001 From: Mason James Date: Thu, 22 May 2008 21:23:14 +1200 Subject: [PATCH] bug-2149, added new block to C4::Letters::SendAlerts() to email 'account creation' notice, and new block in memberentry.pl to call SendAlerts(). Signed-off-by: Joshua Ferraro --- C4/Letters.pm | 17 +++++++++++++++++ members/memberentry.pl | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 85c7a8518b..4002bbddc4 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -434,6 +434,23 @@ sub SendAlerts { } warn "sending to From $userenv->{emailaddress} subj $innerletter->{title} Mess $innerletter->{content}"; + } + # send an "account details" notice to a newly created user + elsif ( $type eq 'members' ) { + $letter->{content} =~ s/<>/$externalid->{'title'}/g; + $letter->{content} =~ s/<>/$externalid->{'firstname'}/g; + $letter->{content} =~ s/<>/$externalid->{'surname'}/g; + $letter->{content} =~ s/<>/$externalid->{'cardnumber'}/g; + $letter->{content} =~ s/<>/$externalid->{'password'}/g; + + my %mail = ( + To => $externalid->{'emailaddr'}, + From => C4::Context->preference("KohaAdminEmailAddress"), + Subject => $letter->{'title'}, + Message => $letter->{'content'}, + 'Content-Type' => 'text/plain; charset="utf8"', + ); + sendmail(%mail); } } diff --git a/members/memberentry.pl b/members/memberentry.pl index 3ee30c6d5f..9d282cd7fc 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -35,10 +35,9 @@ use C4::Koha; use C4::Dates qw/format_date format_date_in_iso/; use C4::Input; use C4::Log; +use C4::Letters; use C4::Branch; # GetBranches -#use Smart::Comments; - use vars qw($debug); BEGIN { @@ -240,7 +239,35 @@ if ((!$nok) and ($op eq 'insert' or $op eq 'save')){ $debug and warn "$op dates: " . join "\t", map {"$_: $newdata{$_}"} qw(dateofbirth dateenrolled dateexpiry); if ($op eq 'insert'){ # we know it's not a duplicate borrowernumber or there would already be an error - $borrowernumber = &AddMember(%newdata); + $borrowernumber = &AddMember(%newdata); + + # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' that matches the user's branchcode. + if ( C4::Context->preference("AutoEmailOpacUser") == 1 && $newdata{'userid'} && $newdata{'password'}) { + #look for defined primary email address, if blank - attempt to use borr.email and borr.emailpro instead + my $emailaddr; + if (C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' && + $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} =~ /\w\@\w/ ) { + $emailaddr = $newdata{C4::Context->preference("AutoEmailPrimaryAddress")} + } + elsif ($newdata{email} =~ /\w\@\w/) { + $emailaddr = $newdata{email} + } + elsif ($newdata{emailpro} =~ /\w\@\w/) { + $emailaddr = $newdata{emailpro} + } + elsif ($newdata{B_email} =~ /\w\@\w/) { + $emailaddr = $newdata{B_email} + } + # if we manage to find a valid email address, send notice + if ($emailaddr) { + $newdata{emailaddr} = $emailaddr; + my $letter = getletter ('members', "ACCTDETAILS:$newdata{'branchcode'}") ; + # if $branch notice fails, then email a default notice instead. + $letter = getletter ('members', "ACCTDETAILS") if !$letter; + SendAlerts ( 'members' , \%newdata , $letter ) if $letter + } + } + if ($data{'organisations'}){ # need to add the members organisations my @orgs=split(/\|/,$data{'organisations'}); -- 2.39.5