From 824735fcfa7c7bb9a5e76ceb2214c6a7cb42e60a Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 12 Jan 2022 12:22:51 +0100 Subject: [PATCH] E-Mails als HTML verschicken: Versand in Einkaufs-/Verkaufsbelegen --- SL/Common.pm | 3 ++- SL/Controller/Order.pm | 3 ++- SL/Form.pm | 20 ++++++------------- js/kivi.SalesPurchase.js | 10 ++++++++++ .../webpages/common/_send_email_dialog.html | 2 +- 5 files changed, 21 insertions(+), 17 deletions(-) diff --git a/SL/Common.pm b/SL/Common.pm index 15f8f7b93..36635fdbc 100644 --- a/SL/Common.pm +++ b/SL/Common.pm @@ -25,6 +25,7 @@ use Encode qw(decode); use SL::DBUtils; use SL::DB; +use SL::HTML::Util; sub unique_id { my ($a, $b) = gettimeofday(); @@ -423,7 +424,7 @@ sub save_email_status { . $main::locale->text('To (email)') . ": $form->{email}\n" . "${cc}${bcc}" . $main::locale->text('Subject') . ": $form->{subject}\n\n" - . $main::locale->text('Message') . ": $form->{message}"; + . $main::locale->text('Message') . ": " . SL::HTML::Util->strip($form->{message}); $intnotes =~ s|\r||g; diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 24ad4a565..e709336ab 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -4,6 +4,7 @@ use strict; use parent qw(SL::Controller::Base); use SL::Helper::Flash qw(flash_later); +use SL::HTML::Util; use SL::Presenter::Tag qw(select_tag hidden_tag div_tag); use SL::Locale::String qw(t8); use SL::SessionFile::Random; @@ -522,7 +523,7 @@ sub action_send_email { $intnotes .= t8('Cc') . ": " . $::form->{cc} . "\n" if $::form->{cc}; $intnotes .= t8('Bcc') . ": " . $::form->{bcc} . "\n" if $::form->{bcc}; $intnotes .= t8('Subject') . ": " . $::form->{subject} . "\n\n"; - $intnotes .= t8('Message') . ": " . $::form->{message}; + $intnotes .= t8('Message') . ": " . SL::HTML::Util->strip($::form->{message}); $self->order->update_attributes(intnotes => $intnotes); diff --git a/SL/Form.pm b/SL/Form.pm index 229ad2c4d..9c05c3353 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -952,17 +952,15 @@ sub send_email { $mail->{to} = $self->{EMAIL_RECIPIENT} ? $self->{EMAIL_RECIPIENT} : $self->{email}; $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; $mail->{fileid} = time() . '.' . $$ . '.'; + $mail->{content_type} = "text/html"; my $full_signature = $self->create_email_signature(); - $full_signature =~ s/\r//g; $mail->{attachments} = []; my @attfiles; # if we send html or plain text inline if (($self->{format} eq 'html') && ($self->{sendmode} eq 'inline')) { - $mail->{content_type} = "text/html"; $mail->{message} =~ s/\r//g; $mail->{message} =~ s{\n}{
\n}g; - $full_signature =~ s{\n}{
\n}g; $mail->{message} .= $full_signature; open(IN, "<", $self->{tmpfile}) @@ -1234,10 +1232,12 @@ sub generate_email_body { return undef unless $body; + $body .= GenericTranslations->get(translation_type => "salutation_punctuation_mark", language_id => $self->{language_id}); + $body = '

' . $::locale->quote_special_chars('HTML', $body) . '

'; + my $translation_type = $params{translation_type} // "preset_text_$self->{formname}"; my $main_body = GenericTranslations->get(translation_type => $translation_type, language_id => $self->{language_id}); $main_body = GenericTranslations->get(translation_type => $params{fallback_translation_type}, language_id => $self->{language_id}) if !$main_body && $params{fallback_translation_type}; - $body .= GenericTranslations->get(translation_type => "salutation_punctuation_mark", language_id => $self->{language_id}) . "\n\n"; $body .= $main_body; $body = $main::locale->unquote_special_chars('HTML', $body); @@ -3440,19 +3440,11 @@ sub reformat_numbers { } sub create_email_signature { - my $client_signature = $::instance_conf->get_signature; my $user_signature = $::myconfig{signature}; - my $signature = ''; - if ( $client_signature or $user_signature ) { - $signature = "\n\n-- \n"; - $signature .= $user_signature . "\n" if $user_signature; - $signature .= $client_signature . "\n" if $client_signature; - }; - return $signature; - -}; + return join '', grep { $_ } ($user_signature, $client_signature); +} sub calculate_tax { # this function calculates the net amount and tax for the lines in ar, ap and diff --git a/js/kivi.SalesPurchase.js b/js/kivi.SalesPurchase.js index e8a1ba241..771351cf5 100644 --- a/js/kivi.SalesPurchase.js +++ b/js/kivi.SalesPurchase.js @@ -241,9 +241,17 @@ namespace('kivi.SalesPurchase', function(ns) { if (!kivi.SalesPurchase.check_required_email_fields()) return false; + // ckeditor gets de-initialized when removing the children from + // the DOM. Therefore we have to manually preserve its content + // over the children's relocation. + + var message = $('#email_form_message').val(); + $('#send_email_dialog').children().remove().appendTo('#email_inputs'); $('#send_email_dialog').dialog('close'); + $('#email_form_message').val(message); + kivi.submit_form_with_action('#form', $('#form').data('send-email-action')); return true; @@ -255,6 +263,8 @@ namespace('kivi.SalesPurchase', function(ns) { $('#print_options').children().remove().appendTo('#email_form_print_options'); + kivi.reinit_widgets(); + var to_focus = $('#email_form_to').val() === '' ? 'to' : 'subject'; $('#email_form_' + to_focus).focus(); }; diff --git a/templates/webpages/common/_send_email_dialog.html b/templates/webpages/common/_send_email_dialog.html index b039b253f..23cc1a9f7 100644 --- a/templates/webpages/common/_send_email_dialog.html +++ b/templates/webpages/common/_send_email_dialog.html @@ -68,7 +68,7 @@ [% LxERP.t8("Message") %] [% L.link("generictranslations.pl?action=edit_email_strings", "1)", title=LxERP.t8('Tired of copying always nice phrases for this message? Click here to use the new preset message option!'), target="_blank") %] - [% L.textarea_tag("email_form.message", email_form.message, rows="15" cols="80" wrap="soft") %] + [% L.textarea_tag("email_form.message", email_form.message, rows="15", cols="80", class="texteditor") %] [% IF INSTANCE_CONF.get_doc_storage %] -- 2.20.1