From aeb5d5ba65579f7529d2b2b04d46e52d808e2af2 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 17 Oct 2014 12:00:25 +0200 Subject: [PATCH] Bug 13096: Send an ACCTDETAILS notice: Rewording pref and code changes Content-Type: text/plain; charset=utf-8 This patch adds a line to the AutoEmailOpacUser pref description. It also makes some code changes to memberentry.pl. The code for selecting an email address and sending the alert is moved to a subroutine. An additional call is made for the op=save situation; if in that case param mailacctdetails is true, a mail will be sent too. Note that the script refers to op=duplicate several times. Inspecting the template shows that the duplicate operation also goes via op=insert however. Test plan: [1] Check the pref rewording in Systempreferences. [2] Disable AutoEmailOpacUser. Add, duplicate, modify patron. No mails? [3] Enable AutoEmailOpacUser. Add, duplicate patron. Check mail. [4] Modify patron. Check the email checkbox. Did you receive it? [5] Modify patron. Uncheck the email checkbox. No mail? --- .../prog/en/modules/admin/preferences/patrons.pref | 2 +- members/memberentry.pl | 79 +++++++++++-------- 2 files changed, 47 insertions(+), 34 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 2469431..717c67d 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -11,7 +11,7 @@ Patrons: choices: yes: Send no: "Don't send" - - an email to newly created patrons with their account details. + - an email to newly created patrons with their account details. When enabled, this pref also allows staff to resend account details when modifying a patron. - - "Use" - pref: AutoEmailPrimaryAddress diff --git a/members/memberentry.pl b/members/memberentry.pl index 3c7f648..36372eb 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -76,6 +76,8 @@ my $cardnumber = $input->param('cardnumber'); my $check_member = $input->param('check_member'); my $nodouble = $input->param('nodouble'); my $duplicate = $input->param('duplicate'); +my $mailacctdetails= $input->param('mailacctdetails') // 0; + $nodouble = 1 if ($op eq 'modify' or $op eq 'duplicate'); # FIXME hack to represent fact that if we're # modifying an existing patron, it ipso facto # isn't a duplicate. Marking FIXME because this @@ -376,39 +378,7 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ $borrowernumber = &AddMember(%newdata); $newdata{'borrowernumber'} = $borrowernumber; - # 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 $err; - eval { - $err = SendAlerts ( 'members', \%newdata, "ACCTDETAILS" ); - }; - if ( $@ ) { - $template->param(error_alert => $@); - } elsif ( ref($err) eq "HASH" && defined $err->{error} and $err->{error} eq "no_email" ) { - $template->{VARS}->{'error_alert'} = "no_email"; - } else { - $template->{VARS}->{'info_alert'} = 1; - } - } - } + SendAutoEmail( \%newdata, $template ); # optionally send acct details if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); @@ -425,6 +395,8 @@ if ((!$nok) and $nodouble and ($op eq 'insert' or $op eq 'save')){ # updating any columns in the borrowers table, # which can happen if we're only editing the # patron attributes or messaging preferences sections + + SendAutoEmail( \%newdata, $template ) if $mailacctdetails; # optionally send acct details, if the checkbox was checked if (C4::Context->preference('ExtendedPatronAttributes') and $input->param('setting_extended_patron_attributes')) { C4::Members::Attributes::SetBorrowerAttributes($borrowernumber, $extended_patron_attributes); } @@ -812,6 +784,47 @@ sub patron_attributes_form { } +sub SendAutoEmail { #optionally send account detail notice + my ( $dataref, $template ) = @_; + my %newdata = %$dataref; + + # check AutoEmailOpacUser syspref first + return if !C4::Context->preference("AutoEmailOpacUser"); + # no mail too if no userid or password + return if !$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 $err; + eval { + $err = SendAlerts ( 'members', \%newdata, "ACCTDETAILS" ); + }; + if ( $@ ) { + $template->param(error_alert => $@); + } elsif ( ref($err) eq "HASH" && defined $err->{error} and $err->{error} eq "no_email" ) { + $template->{VARS}->{'error_alert'} = "no_email"; + } else { + $template->{VARS}->{'info_alert'} = 1; + } + } +} + # Local Variables: # tab-width: 8 # End: -- 1.7.7.6