OpenNIT

Quelltext des aktuellen Standes

Fassung 1.1.1

edit-email.php

4 KB
<?php $this->layout('layouts/admin', [
    'page_title'         => $page_title,
    'current_admin_page' => $current_admin_page ?? 'loans-settings',
    'breadcrumbs'        => [
        ['label' => 'Leihgeräte', 'url' => '/admin/loans'],
        ['label' => $tpl_label],
    ],
]); ?>

<?php
$flash = $this->flash();
$placeholders = $placeholders ?? [];
$key = $tpl_key;
?>

<?php if (!empty($flash['success'])): ?>
<div class="alert alert-success"><?= $this->e($flash['success']) ?></div>
<?php endif; ?>
<?php if (!empty($flash['error'])): ?>
<div class="alert alert-danger"><?= $this->e($flash['error']) ?></div>
<?php endif; ?>

<?php if (!empty($placeholders)): ?>
<div class="card card-outline card-primary mb-3">
    <div class="card-header"><h3 class="card-title"><i class="fas fa-code"></i> <?= $this->te('Verf&uuml;gbare Platzhalter') ?></h3></div>
    <div class="card-body">
        <div class="var-chips">
            <?php foreach ($placeholders as $p): ?>
            <button type="button" class="var-chip" onclick="insertPlaceholder('{{<?= $p ?>}}')"><code>{{<?= $p ?>}}</code></button>
            <?php endforeach; ?>
        </div>
    </div>
</div>
<?php endif; ?>

<form action="/admin/loans/email/<?= urlencode($key) ?>" method="POST">
    <input type="hidden" name="_csrf" value="<?= $this->csrf() ?>">
    <div class="card card-outline card-primary mb-3">
        <div class="card-header"><h3 class="card-title"><i class="fas fa-envelope-open-text"></i> <?= $this->te('E-Mail-Inhalt') ?></h3></div>
        <div class="card-body">
            <div class="form-group">
                <label for="subject" style="font-weight:600;"><?= $this->te('Betreff') ?></label>
                <input type="text" id="subject" name="subject" class="form-control" value="<?= $this->e($subject ?? '') ?>" required>
            </div>
            <div class="form-group mb-0">
                <label for="body_html" style="font-weight:600;"><?= $this->te('Nachricht (HTML)') ?></label>
                <textarea id="body_html" name="body_html" rows="16" class="form-control"><?= $this->e($body ?? '') ?></textarea>
            </div>
        </div>
    </div>
    <div class="form-actions">
        <button type="submit" class="btn btn-primary"><i class="fas fa-save"></i> <?= $this->te('Speichern') ?></button>
        <a href="/admin/loans" class="btn btn-default"><?= $this->te('Abbrechen') ?></a>
    </div>
</form>

<style>
.var-chips { display:flex; flex-wrap:wrap; gap:.4rem; }
.var-chip { padding:.3rem .6rem; background:var(--gray-50); border:1px solid var(--gray-200); border-radius:.375rem; cursor:pointer; font-size:.78rem; }
.var-chip:hover { background:var(--blue-50); border-color:var(--blue-300); }
.var-chip code { color:var(--blue-600); font-size:.72rem; }
.tox-tinymce { border-radius:.375rem !important; }
</style>

<script>
function insertPlaceholder(v){
    if (typeof tinymce !== 'undefined' && tinymce.activeEditor) { tinymce.activeEditor.insertContent(v); }
    else if (window._fallbackEditor) { window._fallbackEditor.focus(); document.execCommand('insertHTML', false, v); }
    else { var ta=document.getElementById('body_html'); ta.value += v; }
}
</script>

<?php if (TINYMCE_INSTALLED): ?>
<script src="<?= $this->asset('/assets/tinymce/tinymce.min.js') ?>"></script>
<script>
tinymce.init({
    selector: '#body_html', language: 'de', language_url: '/assets/tinymce/langs/de.js',
    height: 420, menubar: false, plugins: 'link lists code table fullscreen',
    toolbar: 'undo redo | blocks | bold italic underline | forecolor backcolor | bullist numlist | table | link | code fullscreen',
    content_style: 'body { font-family: Arial, sans-serif; font-size: 13px; color: #1f2937; line-height: 1.5; }',
    promotion: false, branding: false, license_key: 'gpl'
});
</script>
<?php else: ?>
<link rel="stylesheet" href="<?= $this->asset('/assets/css/wysiwyg.css') ?>">
<script src="<?= $this->asset('/assets/js/wysiwyg.js') ?>"></script>
<script>
(function() {
    var ta = document.getElementById('body_html');
    var wrap = document.createElement('div'); wrap.className = 'wysiwyg-editor-container';
    ta.parentNode.insertBefore(wrap, ta); wrap.appendChild(ta);
    window._fallbackEditor = new OpenNIT.WysiwygEditor(wrap, {
        uploadUrl: '/upload/image',
        csrfToken: document.querySelector('input[name="_csrf"]')?.value || ''
    });
}());
</script>
<?php endif; ?>