diff --git a/public/assets/js/ui-list.js b/public/assets/js/ui-list.js index 6c5bd5f..c1a6529 100755 --- a/public/assets/js/ui-list.js +++ b/public/assets/js/ui-list.js @@ -643,11 +643,6 @@ export async function loadList(section) { toast('Testversand: Ungültige ID', false); return; } - const activeCheck = await apiAction('content.get', { method: 'GET', data: { id, section_id: section.id, active_only: 1 } }).catch(() => ({})); - if (!activeCheck?.active_version_id && !activeCheck?.item?.active_version_id) { - toast('Testversand nur mit aktiver Version möglich.', false); - return; - } if (window.AdminTestSend && typeof window.AdminTestSend.open === 'function') { window.AdminTestSend.open({ id, name: nm, section }); } else { diff --git a/src/ApiKernel.php b/src/ApiKernel.php index 6951965..7b2a276 100755 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -2258,11 +2258,38 @@ class ApiKernel if ($customerId <= 0) $this->fail('Customer context missing', null, 500); $section = $this->ensureEmailtemplateSection($customerId); $itemsTable = $this->contentItemsTable(); - $sql = "SELECT * FROM `$itemsTable` WHERE `customer_id` = :cid AND `section_id` = :sid AND `id` = :id LIMIT 1"; + $itemCols = $this->resolveContentItemColumns($itemsTable); + $versionsTable = $this->contentVersionsTable(); + $versionCols = $this->tableExists($versionsTable) ? $this->resolveContentVersionColumns($versionsTable) : null; + $versionId = (int)$this->val($this->in, ['version_id', 'content_version_id'], 0); + $selectCols = []; + if (!empty($itemCols['html'])) $selectCols[] = "i.`{$itemCols['html']}` AS item_html"; + if (!empty($itemCols['json'])) $selectCols[] = "i.`{$itemCols['json']}` AS item_json"; + if ($versionCols && !empty($versionCols['html'])) $selectCols[] = "v.`{$versionCols['html']}` AS version_html"; + $join = ''; + if ($versionCols) { + if ($versionId > 0) { + $join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`id` = :vid"; + } else { + $join = "LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` AND v.`is_active` = 1"; + } + } + $sql = "SELECT " . implode(',', $selectCols) . " FROM `$itemsTable` i $join WHERE i.`customer_id` = :cid AND i.`section_id` = :sid AND i.`id` = :id LIMIT 1"; $stmt = $this->pdo->prepare($sql); - $stmt->execute([':cid' => $customerId, ':sid' => (int)$section['id'], ':id' => $templateId]); + $params = [':cid' => $customerId, ':sid' => (int)$section['id'], ':id' => $templateId]; + if ($versionId > 0 && $versionCols) { + $params[':vid'] = $versionId; + } + $stmt->execute($params); $row = $stmt->fetch(); - $html = $row ? (string)($row['html'] ?? '') : ''; + $html = $row ? (string)($row['version_html'] ?? $row['item_html'] ?? '') : ''; + if ($html === '' && $versionCols && $versionId <= 0) { + $sql = "SELECT " . implode(',', $selectCols) . " FROM `$itemsTable` i LEFT JOIN `$versionsTable` v ON v.`content_id` = i.`id` ORDER BY v.`created_at` DESC LIMIT 1"; + $stmt = $this->pdo->prepare($sql); + $stmt->execute(); + $row = $stmt->fetch(); + $html = $row ? (string)($row['version_html'] ?? $row['item_html'] ?? '') : $html; + } } else { $t = $this->tableMap['templates']; [$idCol, $allCols] = $this->resolveIdCol('templates'); @@ -2279,7 +2306,13 @@ class ApiKernel if (!$row) { $this->fail('Template not found', ['id' => $templateId], 404); } - if ($html === '' && !empty($row['json_content'])) { + $jsonContent = ''; + if ($row && array_key_exists('json_content', $row)) { + $jsonContent = (string)($row['json_content'] ?? ''); + } elseif ($row && array_key_exists('item_json', $row)) { + $jsonContent = (string)($row['item_json'] ?? ''); + } + if ($html === '' && $jsonContent !== '') { $html = '
(Dieses Template enthält noch keine HTML-Inhalte.)
'; }