97 lines
4.3 KiB
PHP
97 lines
4.3 KiB
PHP
<?php
|
|
$pageTitle = $title ?? 'Edit Campaign';
|
|
$campaign = $campaign ?? [];
|
|
$error = $error ?? '';
|
|
ob_start();
|
|
?>
|
|
<section class="admin-card">
|
|
<div class="badge">Newsletter</div>
|
|
<div style="display:flex; align-items:center; justify-content:space-between; gap:16px; margin-top:16px;">
|
|
<div>
|
|
<h1 style="font-size:28px; margin:0;"><?= htmlspecialchars($pageTitle, ENT_QUOTES, 'UTF-8') ?></h1>
|
|
<p style="color: var(--muted); margin-top:6px;">Write a full HTML campaign.</p>
|
|
</div>
|
|
<a href="/admin/newsletter" class="btn outline">Back</a>
|
|
</div>
|
|
|
|
<?php if ($error): ?>
|
|
<div style="margin-top:16px; color:#f3b0b0; font-size:13px;"><?= htmlspecialchars($error, ENT_QUOTES, 'UTF-8') ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post" action="/admin/newsletter/campaigns/save" style="margin-top:18px; display:grid; gap:16px;">
|
|
<input type="hidden" name="id" value="<?= (int)($campaign['id'] ?? 0) ?>">
|
|
<div class="admin-card" style="padding:16px;">
|
|
<div style="display:grid; gap:12px;">
|
|
<label class="label">Title</label>
|
|
<input class="input" name="title" value="<?= htmlspecialchars((string)($campaign['title'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="Monthly Update">
|
|
<label class="label">Subject</label>
|
|
<input class="input" name="subject" value="<?= htmlspecialchars((string)($campaign['subject'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="AudioCore Newsletter">
|
|
<div style="display:flex; align-items:center; justify-content:space-between; gap:12px;">
|
|
<label class="label" style="margin:0;">Content (HTML)</label>
|
|
<button type="button" class="btn outline small" data-media-picker="newsletter_content_html">Insert Media</button>
|
|
</div>
|
|
<textarea class="input" id="newsletter_content_html" name="content_html" rows="18" style="resize:vertical; font-family:'IBM Plex Mono', monospace; font-size:13px; line-height:1.6;"><?= htmlspecialchars((string)($campaign['content_html'] ?? ''), ENT_QUOTES, 'UTF-8') ?></textarea>
|
|
<label class="label">Schedule Send (optional)</label>
|
|
<input class="input" name="scheduled_at" value="<?= htmlspecialchars((string)($campaign['scheduled_at'] ?? ''), ENT_QUOTES, 'UTF-8') ?>" placeholder="2026-01-25 18:30:00">
|
|
</div>
|
|
</div>
|
|
|
|
<div style="display:flex; justify-content:flex-end; gap:12px; align-items:center;">
|
|
<button type="button" id="previewNewsletter" class="btn outline">Preview</button>
|
|
<button type="submit" class="btn">Save campaign</button>
|
|
</div>
|
|
</form>
|
|
|
|
<?php if (!empty($campaign['id'])): ?>
|
|
<form method="post" action="/admin/newsletter/campaigns/test" style="margin-top:12px; display:flex; gap:10px; align-items:center;">
|
|
<input type="hidden" name="id" value="<?= (int)($campaign['id'] ?? 0) ?>">
|
|
<input class="input" name="test_email" placeholder="test@example.com" style="max-width:280px;">
|
|
<button type="submit" class="btn outline small">Send Test</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</section>
|
|
<script>
|
|
(function () {
|
|
const previewBtn = document.getElementById('previewNewsletter');
|
|
const contentEl = document.querySelector('textarea[name="content_html"]');
|
|
if (!previewBtn || !contentEl) {
|
|
return;
|
|
}
|
|
|
|
previewBtn.addEventListener('click', function () {
|
|
const previewWindow = window.open('', 'newsletterPreview', 'width=1000,height=800');
|
|
if (!previewWindow) {
|
|
return;
|
|
}
|
|
const html = contentEl.value || '';
|
|
const doc = previewWindow.document;
|
|
doc.open();
|
|
doc.write(`<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Newsletter Preview</title>
|
|
<style>
|
|
body { margin: 0; background: #f0f2f5; font-family: Arial, sans-serif; }
|
|
.wrap { padding: 24px; display: flex; justify-content: center; }
|
|
.frame { max-width: 680px; width: 100%; background: #ffffff; border-radius: 12px; padding: 24px; box-shadow: 0 12px 30px rgba(0,0,0,0.15); }
|
|
img { max-width: 100%; height: auto; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="wrap">
|
|
<div class="frame">
|
|
${html}
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>`);
|
|
doc.close();
|
|
});
|
|
})();
|
|
</script>
|
|
<?php
|
|
$content = ob_get_clean();
|
|
require __DIR__ . '/../../../admin/views/layout.php';
|