Settings > Mail > Previews, Edit Wording (admin/modals/email_template/email_template_edit.php): * save_email_template keeps your own subject, heading, opening and closing text for one of the emails about a ticket * to clients (functions/email_template.php) - each part sent back as ITFlow's own words, or a subject or heading left * empty, is kept as none, so it follows ITFlow's own; an opening or closing text left empty leaves it out. * reset_email_template puts all of it back to ITFlow's own. Both go back to the email's preview. */ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); if (isset($_POST['save_email_template']) || isset($_POST['reset_email_template'])) { validateCSRFToken(); $key = (string) ($_POST['email_template_key'] ?? ''); if (!isset(EMAIL_TEMPLATES[$key]) || !emailTemplateReady()) { flashAlert("That email's wording can't be changed", 'error'); redirect('settings_mail.php?tab=previews'); } $label = (string) (emailPreviewCatalog()[$key]['label'] ?? $key); $back = 'settings_mail.php?tab=previews&email=' . rawurlencode($key); $key_sql = escapeSql($key); if (isset($_POST['reset_email_template'])) { mysqli_query($mysqli, "DELETE FROM email_templates WHERE email_template_key = '$key_sql'"); logAudit("Settings", "Edit", "$session_name put the wording of the email " . escapeSql($label) . " back to ITFlow's own"); flashAlert("" . escapeHtml($label) . " uses ITFlow's own wording again"); redirect($back); } $set = []; foreach (EMAIL_TEMPLATE_PARTS as $part => $length) { $text = str_replace("\r", '', (string) ($_POST["email_template_$part"] ?? '')); // One line for the subject and heading; trailing spaces off every line $text = in_array($part, ['subject', 'title'], true) ? trim(preg_replace('/\s+/u', ' ', $text)) : trim(preg_replace('/[ \t]+$/m', '', $text)); $text = mb_substr($text, 0, $length); $own = $text === emailTemplateDefault($key, $part) || ($text === '' && in_array($part, ['subject', 'title'], true)); $set[$part] = $own ? null : $text; } if (count(array_filter($set, function ($text) { return $text !== null; })) === 0) { mysqli_query($mysqli, "DELETE FROM email_templates WHERE email_template_key = '$key_sql'"); } else { // Kept as typed - it is plain text, escaped as each email is made (emailHtml()) $sql = function ($text) use ($mysqli) { return $text === null ? 'NULL' : "'" . mysqli_real_escape_string($mysqli, $text) . "'"; }; $columns = "email_template_subject = {$sql($set['subject'])}, email_template_title = {$sql($set['title'])}, email_template_intro = {$sql($set['intro'])}, email_template_after = {$sql($set['after'])}, email_template_updated_by = " . intval($session_user_id) . ", email_template_updated_at = NOW()"; mysqli_query($mysqli, "INSERT INTO email_templates SET email_template_key = '$key_sql', $columns ON DUPLICATE KEY UPDATE $columns"); } logAudit("Settings", "Edit", "$session_name changed the wording of the email " . escapeSql($label)); flashAlert("Wording saved for " . escapeHtml($label) . " - the preview shows it"); redirect($back); }