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
|
||||
|
||||
@@ -13,7 +13,7 @@ return static function (AppContext $ctx): void {
|
||||
$ctx->requireCsrf('delete:' . $id);
|
||||
$ctx->rules->delete($ctx->daUser->username(), $id);
|
||||
$ctx->syncActiveBackend();
|
||||
$ctx->audit->record('delete', $ctx->daUser->username(), ['rule_id' => $id, 'subject' => (string)$rule['subject']]);
|
||||
$ctx->audit->record('delete', $ctx->daUser->username(), ['rule_id' => $id, 'subject_prefix' => (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '')]);
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'deleted']));
|
||||
} catch (Throwable $e) {
|
||||
$ctx->render('Confirm deletion', '<div class="alert alert-err">' . AppContext::e($e->getMessage()) . '</div>');
|
||||
|
||||
@@ -22,8 +22,9 @@ return static function (AppContext $ctx): void {
|
||||
foreach ($rules as $rule) {
|
||||
$id = (string)$rule['id'];
|
||||
$enabled = !empty($rule['enabled']);
|
||||
$subjectPrefix = (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '');
|
||||
$rows .= '<tr><td><span class="badge ' . ($enabled ? 'ok' : 'off') . '">' . AppContext::e($ctx->t($enabled ? 'Enabled' : 'Disabled')) . '</span></td>';
|
||||
$rows .= '<td>' . AppContext::e((string)$rule['subject']) . '<br><span class="muted">' . date('Y-m-d H:i', (int)($rule['updated_at'] ?? time())) . '</span></td>';
|
||||
$rows .= '<td>' . AppContext::e($subjectPrefix) . '<br><span class="muted">' . date('Y-m-d H:i', (int)($rule['updated_at'] ?? time())) . '</span></td>';
|
||||
$rows .= '<td>' . AppContext::e(date('Y-m-d H:i', (int)$rule['start_ts'])) . '<br><span class="muted">' . AppContext::e($ctx->t('To')) . ' ' . AppContext::e(date('Y-m-d H:i', (int)$rule['end_ts'])) . '</span></td>';
|
||||
$rows .= '<td>' . AppContext::e($ctx->t($rule['dynamic_scope'] ? 'Dynamic' : 'Snapshot')) . '</td><td><span class="table-actions">';
|
||||
$rows .= '<a class="btn" href="' . AppContext::e($ctx->url('update.html', ['id' => $id])) . '">' . AppContext::e($ctx->t('Edit')) . '</a>';
|
||||
@@ -35,6 +36,6 @@ return static function (AppContext $ctx): void {
|
||||
|
||||
$body = '<div class="panel"><div class="panel-head"><div><h3>' . AppContext::e($ctx->t('Global autoresponders')) . '</h3><p class="muted">' . AppContext::e($ctx->t('All valid POP/IMAP mailboxes in this account')) . '</p></div>' .
|
||||
'<a class="btn amber" href="' . AppContext::e($ctx->url('create.html')) . '">' . AppContext::e($ctx->t('Add autoresponder')) . '</a></div>' .
|
||||
'<table><thead><tr><th>' . AppContext::e($ctx->t('Status')) . '</th><th>' . AppContext::e($ctx->t('Subject')) . '</th><th>' . AppContext::e($ctx->t('Sending period')) . '</th><th>' . AppContext::e($ctx->t('Scope')) . '</th><th>' . AppContext::e($ctx->t('Actions')) . '</th></tr></thead><tbody>' . $rows . '</tbody></table></div>';
|
||||
'<table><thead><tr><th>' . AppContext::e($ctx->t('Status')) . '</th><th>' . AppContext::e($ctx->t('Subject prefix')) . '</th><th>' . AppContext::e($ctx->t('Sending period')) . '</th><th>' . AppContext::e($ctx->t('Scope')) . '</th><th>' . AppContext::e($ctx->t('Actions')) . '</th></tr></thead><tbody>' . $rows . '</tbody></table></div>';
|
||||
$ctx->render('Global autoresponders', $body, $ok);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user