@@ -, +, @@ code changes --- .../prog/en/modules/admin/preferences/patrons.pref | 2 +- members/memberentry.pl | 79 +++++++++++-------- 2 files changed, 47 insertions(+), 34 deletions(-) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ a/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 --- a/members/memberentry.pl +++ a/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: --