fix: match directadmin vacation controls
This commit is contained in:
@@ -6,7 +6,7 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
|
||||
$isUpdate = $mode === 'update';
|
||||
$id = $isUpdate ? (string)$rule['id'] : '';
|
||||
$subjectPrefix = $rule['subject_prefix'] ?? $rule['subject'] ?? '';
|
||||
$replyFrequency = selected_reply_frequency($rule);
|
||||
$replyFrequency = selected_reply_frequency($ctx, $rule);
|
||||
$body = $rule['body'] ?? '';
|
||||
$enabled = $rule === null || !empty($rule['enabled']);
|
||||
$startValue = (string)($rule['start_value'] ?? default_schedule_value($ctx, true));
|
||||
@@ -30,29 +30,43 @@ function render_rule_form(AppContext $ctx, string $mode, ?array $rule): string
|
||||
function default_schedule_value(AppContext $ctx, bool $start): string
|
||||
{
|
||||
$today = new DateTimeImmutable('today', new DateTimeZone($ctx->settings->timezone()));
|
||||
if ($ctx->settings->scheduleMode() === 'directadmin_period') {
|
||||
return $today->format('Y-m-d') . '|' . ($start ? 'morning' : 'evening');
|
||||
}
|
||||
return $today->format('Y-m-d') . 'T' . ($start ? '09:00' : '17:00');
|
||||
return $today->format('Y-m-d') . 'T' . ($start ? '00:00' : '23:59');
|
||||
}
|
||||
|
||||
/** @param array<string,mixed>|null $rule */
|
||||
function selected_reply_frequency(?array $rule): string
|
||||
function selected_reply_frequency(AppContext $ctx, ?array $rule): string
|
||||
{
|
||||
if ($rule === null) {
|
||||
return '1440';
|
||||
}
|
||||
if (!empty($rule['reply_every_message'])) {
|
||||
return 'every';
|
||||
return $ctx->settings->backendMode() === 'da' ? '1' : 'every';
|
||||
}
|
||||
$minutes = (string)(int)($rule['repeat_minutes'] ?? 1440);
|
||||
return in_array($minutes, ['30', '60', '120', '360', '720', '1440', '2880', '10080'], true) ? $minutes : '1440';
|
||||
return array_key_exists($minutes, reply_frequency_options($ctx)) ? $minutes : '1440';
|
||||
}
|
||||
|
||||
function render_reply_frequency_select(AppContext $ctx, string $selected): string
|
||||
{
|
||||
$options = [
|
||||
'every' => 'Send automatic reply for every message',
|
||||
$options = reply_frequency_options($ctx);
|
||||
$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>';
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
function reply_frequency_options(AppContext $ctx): array
|
||||
{
|
||||
$options = [];
|
||||
if ($ctx->settings->backendMode() !== 'da') {
|
||||
$options['every'] = 'Send automatic reply for every message';
|
||||
}
|
||||
return $options + [
|
||||
'1' => '1 minute',
|
||||
'10' => '10 minutes',
|
||||
'30' => '30 minutes',
|
||||
'60' => '1 hour',
|
||||
'120' => '2 hours',
|
||||
@@ -60,14 +74,19 @@ function render_reply_frequency_select(AppContext $ctx, string $selected): strin
|
||||
'720' => '12 hours',
|
||||
'1440' => '1 day',
|
||||
'2880' => '2 days',
|
||||
'4320' => '3 days',
|
||||
'5760' => '4 days',
|
||||
'7200' => '5 days',
|
||||
'8640' => '6 days',
|
||||
'10080' => '7 days',
|
||||
'11520' => '8 days',
|
||||
'12960' => '9 days',
|
||||
'14400' => '10 days',
|
||||
'15840' => '11 days',
|
||||
'17280' => '12 days',
|
||||
'18720' => '13 days',
|
||||
'20160' => '14 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> */
|
||||
|
||||
@@ -26,7 +26,7 @@ return static function (AppContext $ctx): void {
|
||||
$rows .= '<tr><td><span class="badge ' . ($enabled ? 'ok' : 'off') . '">' . AppContext::e($ctx->t($enabled ? 'Enabled' : 'Disabled')) . '</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 .= '<td><span class="table-actions">';
|
||||
$rows .= '<a class="btn" href="' . AppContext::e($ctx->url('update.html', ['id' => $id])) . '">' . AppContext::e($ctx->t('Edit')) . '</a>';
|
||||
$rows .= '<a class="btn" href="' . AppContext::e($ctx->url('preview.html', ['id' => $id])) . '">' . AppContext::e($ctx->t('Preview')) . '</a>';
|
||||
$rows .= '<form method="post" action="' . AppContext::e($ctx->url('toggle.html')) . '">' . $ctx->csrfField('toggle:' . $id) . '<input type="hidden" name="id" value="' . AppContext::e($id) . '"><button>' . AppContext::e($ctx->t($enabled ? 'Disable' : 'Enable')) . '</button></form>';
|
||||
@@ -36,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 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>';
|
||||
'<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('Actions')) . '</th></tr></thead><tbody>' . $rows . '</tbody></table></div>';
|
||||
$ctx->render('Global autoresponders', $body, $ok);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user