<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[eMail-Benachrichtigung: Von ASCII Tabelle zu HTML-Tabelle]]></title><description><![CDATA[<p dir="auto">Servus,</p>
<p dir="auto">i-doit V34</p>
<p dir="auto">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.<br />
Warum? Verschobener Text in Tabelle.</p>
<p dir="auto">Macht aus dem hier:<br />
<img src="/assets/uploads/files/1743075920631-jo1.png" alt="jo1.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">das da:<br />
<img src="/assets/uploads/files/1743075926869-jo2.png" alt="jo2.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto"><strong>Datei:</strong><br />
/var/www/html/src/classes/notification/isys_notification.class.php</p>
<p dir="auto"><strong>Zeile 1036:</strong><br />
Alt:<br />
$l_mailer-&gt;set_content_type(isys_library_mail::C__CONTENT_TYPE__PLAIN);<br />
Neu:<br />
$l_mailer-&gt;set_content_type(isys_library_mail::C__CONTENT_TYPE__HTML);</p>
<p dir="auto"><strong>Alt ab Zeile 1151:</strong></p>
<pre><code>     /**
     * 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-&gt;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 =&gt; $l_value) {
                $l_value_length = strlen($l_value);
                if ($l_value_length &gt; $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 =&gt; $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 = "&lt;pre style='font-family: Courier, monospace;'&gt;" . htmlentities($l_table) . "&lt;/pre&gt;";
		
		return $l_table;
    }
</code></pre>
<p dir="auto"><strong>Neu ab Zeile 1151:</strong></p>
<pre><code>    /**
     * 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 = '&lt;table style="border-collapse: collapse; font-family: Courier, monospace; width: 100%;"&gt;';

		// Tabellenkopf:
		$l_table .= '&lt;tr&gt;';
		foreach ($l_headers as $l_header) {
			$l_table .= '&lt;th style="border: 1px solid black; padding: 5px; text-align: left; background-color: #f0f0f0;"&gt;' 
					 . htmlentities(self::_l($l_header)) 
					 . '&lt;/th&gt;';
		}
		$l_table .= '&lt;/tr&gt;';

		// Tabellenzeilen:
		foreach ($p_entities as $l_entity) {
			$l_table .= '&lt;tr&gt;';
			foreach ($l_entity as $l_value) {
				$l_table .= '&lt;td style="border: 1px solid black; padding: 5px; white-space: nowrap;"&gt;' 
						 . htmlentities($l_value) 
						 . '&lt;/td&gt;';
			}
			$l_table .= '&lt;/tr&gt;';
		}

		$l_table .= '&lt;/table&gt;';

		return $l_table;
	}
</code></pre>
<p dir="auto">Vielleicht kann man das gleich in eine nächste Version einbauen?<br />
PLAIN oder HTML ... wenn das wichtig ist zu entscheiden, dann wäre dies über die Verwaltung / Einstellungen interessant ... frage mich nur wofür?</p>
<p dir="auto">LG Stefan</p>
]]></description><link>https://community.i-doit.com/topic/5293/email-benachrichtigung-von-ascii-tabelle-zu-html-tabelle</link><generator>RSS for Node</generator><lastBuildDate>Fri, 17 Apr 2026 19:00:36 GMT</lastBuildDate><atom:link href="https://community.i-doit.com/topic/5293.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 27 Mar 2025 11:51:55 GMT</pubDate><ttl>60</ttl></channel></rss>