eMail-Benachrichtigung: Von ASCII Tabelle zu HTML-Tabelle
-
Servus,
i-doit V34
ich habe mir gedacht, baue ich doch heute die eMail-Notification so um, dass ein HTML-eMail samt Tabelle generiert wird, anstatt einem Text-Mail mit der ASCII-Tabelle.
Warum? Verschobener Text in Tabelle.Macht aus dem hier:
das da:
Datei:
/var/www/html/src/classes/notification/isys_notification.class.phpZeile 1036:
Alt:
$l_mailer->set_content_type(isys_library_mail::C__CONTENT_TYPE__PLAIN);
Neu:
$l_mailer->set_content_type(isys_library_mail::C__CONTENT_TYPE__HTML);Alt ab Zeile 1151:
/** * Builds a simple plaintext table with header. Columns are left-aligned. * * @param array $p_entities Entities * * @return string * * @todo This is not the right place. Move it to MVC view or something. */ protected function build_plain_table($p_entities) { assert(is_array($p_entities)); $l_table = ''; $l_headers = []; $l_layouted_headers = []; if (count($p_entities) === 0) { return $l_table; } // Layout: $l_horizontal_line = '-'; $l_horizontal_line_header = '='; $l_vertical_line = '|'; $l_edge = '+'; // Analyze entities: $l_column_widths = []; $l_count = 0; // Iterate through each entity: foreach ($p_entities as $l_entity) { // Also analyze header: if ($l_count === 0) { $l_count++; $l_headers = array_keys($l_entity); foreach ($l_headers as $l_header) { $l_layouted_headers[$l_header] = $this->emphasize(self::_l($l_header)); } foreach ($l_headers as $l_header) { $l_column_widths[$l_header] = strlen($l_layouted_headers[$l_header]); } } // Analyse values: foreach ($l_entity as $l_key => $l_value) { $l_value_length = strlen($l_value); if ($l_value_length > $l_column_widths[$l_key]) { $l_column_widths[$l_key] = $l_value_length; } } } $l_horizonatal_header_line_parts = []; $l_horizonatal_line_parts = []; foreach ($l_column_widths as $l_column_width) { $l_horizonatal_header_line_parts[] = $l_horizontal_line_header . str_pad('', $l_column_width, $l_horizontal_line_header) . $l_horizontal_line_header; $l_horizonatal_line_parts[] = $l_horizontal_line . str_pad('', $l_column_width, $l_horizontal_line) . $l_horizontal_line; } $l_complete_horizontal_header_line = $l_edge . implode($l_edge, $l_horizonatal_header_line_parts) . $l_edge; $l_complete_horizontal_line = $l_edge . implode($l_edge, $l_horizonatal_line_parts) . $l_edge; // Prepend header: $l_padded_headers = array_map([ $this, 'table_header' ], $l_layouted_headers, $l_column_widths); $l_table .= $l_complete_horizontal_header_line . "\n" . $l_vertical_line . ' ' . implode(' ' . $l_vertical_line . ' ', $l_padded_headers) . ' ' . $l_vertical_line . "\n" . $l_complete_horizontal_header_line . "\n"; // Iterate through each entity: foreach ($p_entities as $l_entity) { $l_table .= $l_vertical_line; foreach ($l_entity as $l_key => $l_value) { $l_table .= ' ' . str_pad($l_value, $l_column_widths[$l_key]) . ' ' . $l_vertical_line; } $l_table .= "\n" . $l_complete_horizontal_line . "\n"; } $l_table = "<pre style='font-family: Courier, monospace;'>" . htmlentities($l_table) . "</pre>"; return $l_table; }
Neu ab Zeile 1151:
/** * Builds a simple plaintext table with header. Columns are left-aligned. * * @param array $p_entities Entities * * @return string * * @todo This is not the right place. Move it to MVC view or something. */ protected function build_plain_table($p_entities) { assert(is_array($p_entities)); if (count($p_entities) === 0) { return ''; } // Tabellen-Header bestimmen: $l_headers = array_keys($p_entities[0]); // Tabelle als HTML aufbauen: $l_table = '<table style="border-collapse: collapse; font-family: Courier, monospace; width: 100%;">'; // Tabellenkopf: $l_table .= '<tr>'; foreach ($l_headers as $l_header) { $l_table .= '<th style="border: 1px solid black; padding: 5px; text-align: left; background-color: #f0f0f0;">' . htmlentities(self::_l($l_header)) . '</th>'; } $l_table .= '</tr>'; // Tabellenzeilen: foreach ($p_entities as $l_entity) { $l_table .= '<tr>'; foreach ($l_entity as $l_value) { $l_table .= '<td style="border: 1px solid black; padding: 5px; white-space: nowrap;">' . htmlentities($l_value) . '</td>'; } $l_table .= '</tr>'; } $l_table .= '</table>'; return $l_table; }
Vielleicht kann man das gleich in eine nächste Version einbauen?
PLAIN oder HTML ... wenn das wichtig ist zu entscheiden, dann wäre dies über die Verwaltung / Einstellungen interessant ... frage mich nur wofür?LG Stefan