Mahnungen: E-Mail-Text als HTML
authorMoritz Bunkus <m.bunkus@linet.de>
Tue, 22 Feb 2022 09:12:06 +0000 (10:12 +0100)
committerMoritz Bunkus <m.bunkus@linet.de>
Tue, 22 Feb 2022 09:55:30 +0000 (10:55 +0100)
SL/DN.pm
SL/Form.pm
bin/mozilla/dn.pl
sql/Pg-upgrade2/convert_columns_to_html_for_sending_html_emails2.pl [new file with mode: 0644]
templates/webpages/dunning/set_email.html

index b3c4d89..d9d02a6 100644 (file)
--- 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('&lt;%', '%&gt;');
+
   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();
index e0bff1b..a0e7856 100644 (file)
@@ -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};
 
index c4640ef..419b4f4 100644 (file)
@@ -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 (file)
index 0000000..9c79104
--- /dev/null
@@ -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 = <<SQL;
+    SELECT ${id_column}, ${column_to_convert}
+    FROM ${table}
+    ${condition}
+SQL
+
+  my $q_update = <<SQL;
+    UPDATE ${table}
+    SET ${column_to_convert} = ?
+    WHERE ${id_column} = ?
+SQL
+
+  my $h_fetch = $self->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;
index 1a40a45..b740f58 100644 (file)
@@ -1,13 +1,14 @@
 [%- USE T8 %]
-[%- USE HTML %]
+[%- USE HTML %][%- USE L -%]
 <h1>[% title %]</h1>
 
  <script type="text/javascript">
   <!--
       function email_updated() {
         window.opener.document.getElementsByName(document.Form.input_subject.value)[0].value = document.getElementsByName("email_subject")[0].value;
-        window.opener.document.getElementsByName(document.Form.input_body.value)[0].value = document.getElementsByName("email_body")[0].value;
-        window.opener.document.getElementsByName(document.Form.input_attachment.value)[0].value = document.getElementsByName("email_attachment")[0].value;        self.close();
+        window.opener.document.getElementsByName(document.Form.input_body.value)[0].value = $("#email_body").val();
+        window.opener.document.getElementsByName(document.Form.input_attachment.value)[0].value = document.getElementsByName("email_attachment")[0].value;
+        self.close();
       }
     -->
  </script>
@@ -26,7 +27,7 @@
 
    <tr>
     <td valign="top">[% 'Body:' | $T8 %]</td>
-    <td valign="top"><textarea id="email_body" name="email_body" rows="20" cols="70" wrap="soft">[% HTML.escape(email_body) %]</textarea></td>
+    <td valign="top">[% L.textarea_tag('email_body', email_body, rows=20, cols=70, class='texteditor') %]</td>
    </tr>
 
    <tr>