From 6092ef39d7da3d61b6df25c9dc3ff23b1a7b8acb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 22 Feb 2022 10:12:06 +0100 Subject: [PATCH] Mahnungen: E-Mail-Text als HTML --- SL/DN.pm | 6 ++- SL/Form.pm | 2 + bin/mozilla/dn.pl | 5 +- ...olumns_to_html_for_sending_html_emails2.pl | 53 +++++++++++++++++++ templates/webpages/dunning/set_email.html | 9 ++-- 5 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 sql/Pg-upgrade2/convert_columns_to_html_for_sending_html_emails2.pl diff --git a/SL/DN.pm b/SL/DN.pm index b3c4d897a..d9d02a626 100644 --- a/SL/DN.pm +++ b/SL/DN.pm @@ -487,13 +487,17 @@ sub send_email { } or die $main::locale->text('No email for user with login #1 defined.', $ref->{invoice_employee_login}); } + my $html_template = SL::Template::create(type => 'HTML', form => $form, myconfig => $myconfig); + $html_template->set_tag_style('<%', '%>'); + my $template = SL::Template::create(type => 'PlainText', form => $form, myconfig => $myconfig); my $mail = Mailer->new(); $mail->{bcc} = $form->get_bcc_defaults($myconfig, $form->{bcc}); $mail->{from} = $from; $mail->{to} = $ref->{recipient}; $mail->{subject} = $template->parse_block($ref->{email_subject}); - $mail->{message} = $template->parse_block($ref->{email_body}); + $mail->{message} = $html_template->parse_block($ref->{email_body}); + $mail->{content_type} = 'text/html'; my $sign_backup = $::myconfig{signature}; $::myconfig{signature} = $sign if $sign; $mail->{message} .= $form->create_email_signature(); diff --git a/SL/Form.pm b/SL/Form.pm index e0bff1b40..a0e7856ae 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -436,6 +436,8 @@ sub header { common part_selection ), "jquery/ui/i18n/jquery.ui.datepicker-$::myconfig{countrycode}"); + $layout->use_javascript("$_.js") for @{ $params{use_javascripts} // [] }; + $self->{favicon} ||= "favicon.ico"; $self->{titlebar} = join ' - ', grep $_, $self->{title}, $self->{login}, $::myconfig{dbname}, $self->read_version if $self->{title} || !$self->{titlebar}; diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index c4640efee..419b4f4bd 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -317,7 +317,10 @@ sub set_email { $main::auth->assert('dunning_edit'); $form->{"title"} = $locale->text("Set eMail text"); - $form->header(no_layout => 1); + $form->header( + no_layout => 1, + use_javascripts => [ qw(ckeditor/ckeditor ckeditor/adapters/jquery) ], + ); print($form->parse_html_template("dunning/set_email")); $main::lxdebug->leave_sub(); diff --git a/sql/Pg-upgrade2/convert_columns_to_html_for_sending_html_emails2.pl b/sql/Pg-upgrade2/convert_columns_to_html_for_sending_html_emails2.pl new file mode 100644 index 000000000..9c79104f8 --- /dev/null +++ b/sql/Pg-upgrade2/convert_columns_to_html_for_sending_html_emails2.pl @@ -0,0 +1,53 @@ +# @tag: convert_columns_to_html_for_sending_html_emails2 +# @description: Versand von E-Mails in HTML: weitere Text-Spalten nach HTML umwandeln +# @depends: convert_columns_to_html_for_sending_html_emails +package SL::DBUpgrade2::convert_columns_to_html_for_sending_html_emails2; + +use strict; +use utf8; + +use parent qw(SL::DBUpgrade2::Base); + +use SL::HTML::Util; + +sub convert_column { + my ($self, $table, $id_column, $column_to_convert, $condition) = @_; + + $condition = $condition ? "WHERE $condition" : ""; + + my $q_fetch = <dbh->prepare($q_fetch); + $h_fetch->execute || $::form->dberror($q_fetch); + + my $h_update = $self->dbh->prepare($q_update); + + while (my $entry = $h_fetch->fetchrow_hashref) { + $entry->{$column_to_convert} //= ''; + my $new_value = SL::HTML::Util->plain_text_to_html($entry->{$column_to_convert}); + + next if $entry->{$column_to_convert} eq $new_value; + + $h_update->execute($new_value, $entry->{id}) || $::form->dberror($q_update); + } +} + +sub run { + my ($self) = @_; + + $self->convert_column('dunning_config', 'id', 'email_body'); + + return 1; +} + +1; diff --git a/templates/webpages/dunning/set_email.html b/templates/webpages/dunning/set_email.html index 1a40a45cf..b740f589d 100644 --- a/templates/webpages/dunning/set_email.html +++ b/templates/webpages/dunning/set_email.html @@ -1,13 +1,14 @@ [%- USE T8 %] -[%- USE HTML %] +[%- USE HTML %][%- USE L -%]

[% title %]

@@ -26,7 +27,7 @@ [% 'Body:' | $T8 %] - + [% L.textarea_tag('email_body', email_body, rows=20, cols=70, class='texteditor') %] -- 2.20.1