Sync global-autoresponder current state
This commit is contained in:
+5
-28
@@ -2,38 +2,15 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
return static function (AppContext $ctx): void {
|
||||
$rules = $ctx->rules->all($ctx->daUser->username());
|
||||
$ok = [];
|
||||
$status = $ctx->query('status');
|
||||
if ($status === 'created') { $ok[] = $ctx->t('Rule created.'); }
|
||||
if ($status === 'updated') { $ok[] = $ctx->t('Rule updated.'); }
|
||||
if ($status === 'deleted') { $ok[] = $ctx->t('Rule deleted.'); }
|
||||
if ($status === 'deleted') {
|
||||
$name = $ctx->query('name');
|
||||
$ok[] = $name !== '' ? $ctx->t('Global autoresponder deleted.', ['name' => $name]) : $ctx->t('Rule deleted.');
|
||||
}
|
||||
if ($status === 'toggled') { $ok[] = $ctx->t('Rule status changed.'); }
|
||||
|
||||
if ($rules === []) {
|
||||
$body = '<div class="panel"><div class="empty-state"><div><h3>' . AppContext::e($ctx->t('No global autoresponders')) . '</h3>' .
|
||||
'<p class="muted">' . AppContext::e($ctx->t('All valid POP/IMAP mailboxes in this account')) . '</p></div></div></div>';
|
||||
$ctx->render('Global autoresponders', $body, $ok);
|
||||
return;
|
||||
}
|
||||
|
||||
$rows = '';
|
||||
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($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><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>';
|
||||
$rows .= '<a class="btn danger" href="' . AppContext::e($ctx->url('delete.html', ['id' => $id])) . '">' . AppContext::e($ctx->t('Delete')) . '</a>';
|
||||
$rows .= '</span></td></tr>';
|
||||
}
|
||||
|
||||
$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>' .
|
||||
'</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);
|
||||
render_rules_index($ctx, $ok);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user