Files
itflow/admin/modals/email_template/email_template_edit.php

100 lines
5.4 KiB
PHP

<?php
/*
* Edit Wording - your own subject, heading, opening and closing text for one of the emails about a ticket to clients
* (functions/email_template.php), from Admin > Settings > Mail > Previews. Each field starts with the wording it sends
* now - yours, or ITFlow's own - and the words in square brackets are filled in as it goes. Saved by
* save_email_template (admin/post/email_template.php); Use ITFlow's Wording puts all of it back.
*/
require_once '../../includes/modal_header.php';
$key = (string) ($_GET['key'] ?? '');
if (!isset(EMAIL_TEMPLATES[$key]) || !emailTemplateReady()) {
echo json_encode(['error' => !emailTemplateReady() ? 'Your own wording arrives with the 4.3.4 database update.' : "That email's wording can't be changed."]);
exit;
}
$label = (string) (emailPreviewCatalog()[$key]['label'] ?? $key);
$saved = emailTemplatesSaved()[$key] ?? [];
$value = function ($part) use ($key, $saved) {
return escapeHtml($saved[$part] ?? emailTemplateDefault($key, $part));
};
$edited = emailTemplateEdited($key);
$reference = escapeHtml(($config_ticket_prefix ?? 'TCK-') . '123');
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-pen me-2"></i>Edit Wording <small class="ms-1 opacity-75"><?= escapeHtml($label) ?></small></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="post.php" method="post" autocomplete="off" data-email-template-form>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="email_template_key" value="<?= escapeHtml($key) ?>">
<div class="modal-body">
<?php if (!empty(EMAIL_TEMPLATES[$key]['note'])) { ?>
<div class="alert alert-info small py-2"><i class="fas fa-fw fa-info-circle me-1"></i><?= escapeHtml(EMAIL_TEMPLATES[$key]['note']) ?></div>
<?php } ?>
<div class="mb-3">
<label class="form-label" for="emailTemplateSubject">Subject</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
<span class="input-group-text text-body-secondary" title="Every email about a ticket starts with its number, so a reply finds it">[<?= $reference ?>]</span>
<input type="text" class="form-control" id="emailTemplateSubject" name="email_template_subject" maxlength="255" value="<?= $value('subject') ?>">
</div>
<div class="form-text">Keep [Subject] as it is, so the client's mail program keeps the ticket's emails together.</div>
</div>
<div class="mb-3">
<label class="form-label" for="emailTemplateTitle">Heading</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-heading"></i></span>
<input type="text" class="form-control" id="emailTemplateTitle" name="email_template_title" maxlength="255" value="<?= $value('title') ?>">
</div>
</div>
<div class="mb-3">
<label class="form-label" for="emailTemplateIntro">Opening text</label>
<div class="input-group">
<span class="input-group-text align-items-start pt-2"><i class="fas fa-fw fa-align-left"></i></span>
<textarea class="form-control" id="emailTemplateIntro" name="email_template_intro" rows="4" maxlength="5000"><?= $value('intro') ?></textarea>
</div>
<div class="form-text">After "Hello Name,". A blank line starts a new paragraph. Empty, there is none.</div>
</div>
<div class="mb-3">
<label class="form-label" for="emailTemplateAfter">Closing text</label>
<div class="input-group">
<span class="input-group-text align-items-start pt-2"><i class="fas fa-fw fa-align-left"></i></span>
<textarea class="form-control" id="emailTemplateAfter" name="email_template_after" rows="2" maxlength="5000"><?= $value('after') ?></textarea>
</div>
<div class="form-text">Under the button, in smaller print.</div>
</div>
<div class="small" data-email-template-placeholders>
<div class="fw-semibold mb-1">Filled in as it goes</div>
<div class="d-flex flex-wrap gap-1">
<?php foreach (emailTemplatePlaceholders($key) as $name => $what) { ?>
<code class="border rounded px-1" title="<?= escapeHtml($what) ?>">[<?= escapeHtml($name) ?>]</code>
<?php } ?>
</div>
<div class="text-body-secondary mt-2">The message, the details, the button and the earlier messages are always there.</div>
</div>
</div>
<div class="modal-footer">
<?php if ($edited) { ?>
<button type="submit" name="reset_email_template" class="btn btn-outline-secondary me-auto" title="Its subject, heading and text go back to ITFlow's own"><i class="fas fa-undo-alt me-2"></i>Use ITFlow's Wording</button>
<?php } ?>
<button type="submit" name="save_email_template" class="btn btn-primary fw-bold"><i class="fas fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';