feat: use vacation subject prefix
This commit is contained in:
@@ -5,7 +5,8 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
|
||||
{
|
||||
$isUpdate = $mode === 'update';
|
||||
$id = $isUpdate ? (string)$rule['id'] : '';
|
||||
$subject = $rule['subject'] ?? '';
|
||||
$subjectPrefix = $rule['subject_prefix'] ?? $rule['subject'] ?? '';
|
||||
$replyFrequency = selected_reply_frequency($rule);
|
||||
$body = $rule['body'] ?? '';
|
||||
$enabled = $rule === null || !empty($rule['enabled']);
|
||||
$startValue = (string)($rule['start_value'] ?? '2026-06-10T09:00');
|
||||
@@ -16,7 +17,8 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
|
||||
$hiddenId = $isUpdate ? '<input type="hidden" name="id" value="' . AppContext::e($id) . '">' : '';
|
||||
|
||||
return '<form method="post" action="' . AppContext::e($action) . '">' . $csrf . $hiddenId .
|
||||
'<div class="panel"><h3>' . AppContext::e($ctx->t('Response content')) . '</h3><div class="row"><div><label>' . AppContext::e($ctx->t('Subject')) . '</label><input type="text" name="subject" value="' . AppContext::e((string)$subject) . '"></div>' .
|
||||
'<div class="panel"><h3>' . AppContext::e($ctx->t('Response content')) . '</h3><div class="row"><div><label>' . AppContext::e($ctx->t('Subject prefix')) . '</label><div class="subject-prefix-control"><input type="text" name="subject_prefix" value="' . AppContext::e((string)$subjectPrefix) . '"><span>' . AppContext::e($ctx->t('Original subject suffix')) . '</span></div></div>' .
|
||||
'<div><label>' . AppContext::e($ctx->t('Response frequency')) . '</label>' . render_reply_frequency_select($ctx, $replyFrequency) . '</div>' .
|
||||
'<div><label>' . AppContext::e($ctx->t('Status')) . '</label><label class="br-time-item"><input type="checkbox" name="enabled" value="1" ' . ($enabled ? 'checked' : '') . '> ' . AppContext::e($ctx->t('Enabled')) . '</label></div></div>' .
|
||||
'<label>' . AppContext::e($ctx->t('Message body')) . '</label><textarea name="body">' . AppContext::e((string)$body) . '</textarea></div>' .
|
||||
render_calendar_picker($ctx, 'start_value', $ctx->t('Start date'), $startValue) .
|
||||
@@ -25,6 +27,40 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
|
||||
'</form>';
|
||||
}
|
||||
|
||||
/** @param array<string,mixed>|null $rule */
|
||||
function selected_reply_frequency(?array $rule): string
|
||||
{
|
||||
if ($rule === null) {
|
||||
return '1440';
|
||||
}
|
||||
if (!empty($rule['reply_every_message'])) {
|
||||
return 'every';
|
||||
}
|
||||
$minutes = (string)(int)($rule['repeat_minutes'] ?? 1440);
|
||||
return in_array($minutes, ['30', '60', '120', '360', '720', '1440', '2880', '10080'], true) ? $minutes : '1440';
|
||||
}
|
||||
|
||||
function render_reply_frequency_select(AppContext $ctx, string $selected): string
|
||||
{
|
||||
$options = [
|
||||
'every' => 'Send automatic reply for every message',
|
||||
'30' => '30 minutes',
|
||||
'60' => '1 hour',
|
||||
'120' => '2 hours',
|
||||
'360' => '6 hours',
|
||||
'720' => '12 hours',
|
||||
'1440' => '1 day',
|
||||
'2880' => '2 days',
|
||||
'10080' => '7 days',
|
||||
];
|
||||
$html = '<select name="reply_frequency">';
|
||||
foreach ($options as $value => $label) {
|
||||
$value = (string)$value;
|
||||
$html .= '<option value="' . AppContext::e($value) . '"' . ($selected === $value ? ' selected' : '') . '>' . AppContext::e($ctx->t($label)) . '</option>';
|
||||
}
|
||||
return $html . '</select>';
|
||||
}
|
||||
|
||||
/** @param array<string,mixed> $post @return array<string,mixed> */
|
||||
function normalize_rule_post(array $post): array
|
||||
{
|
||||
@@ -104,7 +140,8 @@ function render_calendar_picker(AppContext $ctx, string $name, string $title, st
|
||||
|
||||
function render_preview_box(AppContext $ctx, array $rule): string
|
||||
{
|
||||
return '<div class="preview-box"><div><strong>' . AppContext::e($ctx->t('Subject')) . ':</strong> ' . AppContext::e((string)$rule['subject']) . '</div><br><div>' . nl2br(AppContext::e((string)$rule['body'])) . '</div></div>';
|
||||
$subjectPrefix = (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '');
|
||||
return '<div class="preview-box"><div><strong>' . AppContext::e($ctx->t('Subject prefix')) . ':</strong> ' . AppContext::e($subjectPrefix) . '</div><br><div>' . nl2br(AppContext::e((string)$rule['body'])) . '</div></div>';
|
||||
}
|
||||
|
||||
function render_weekday_headers(AppContext $ctx): string
|
||||
|
||||
Reference in New Issue
Block a user