fix: match directadmin vacation controls

This commit is contained in:
Marek Miklewicz
2026-06-03 09:21:51 +02:00
parent 0617798821
commit 9174d62706
12 changed files with 176 additions and 53 deletions
+35 -16
View File
@@ -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> */