41 lines
3.1 KiB
PHP
41 lines
3.1 KiB
PHP
<?php
|
|
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 === '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>' .
|
|
'<a class="btn amber" href="' . AppContext::e($ctx->url('create.html')) . '">' . AppContext::e($ctx->t('Add autoresponder')) . '</a></div></div></div>';
|
|
$ctx->render('Global autoresponders', $body, $ok);
|
|
return;
|
|
}
|
|
|
|
$rows = '';
|
|
foreach ($rules as $rule) {
|
|
$id = (string)$rule['id'];
|
|
$enabled = !empty($rule['enabled']);
|
|
$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(date('Y-m-d H:i', (int)$rule['start_ts'])) . '<br><span class="muted">do ' . AppContext::e(date('Y-m-d H:i', (int)$rule['end_ts'])) . '</span></td>';
|
|
$rows .= '<td>' . AppContext::e($rule['dynamic_scope'] ? 'Dynamiczny' : '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>';
|
|
$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>' .
|
|
'<a class="btn amber" href="' . AppContext::e($ctx->url('create.html')) . '">' . AppContext::e($ctx->t('Add autoresponder')) . '</a></div>' .
|
|
'<table><thead><tr><th>Status</th><th>' . AppContext::e($ctx->t('Subject')) . '</th><th>Okres wysyłki</th><th>Zakres</th><th>Akcje</th></tr></thead><tbody>' . $rows . '</tbody></table></div>';
|
|
$ctx->render('Global autoresponders', $body, $ok);
|
|
};
|