26 lines
1015 B
PHP
26 lines
1015 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
return static function (AppContext $ctx): void {
|
|
$id = Http::isPost() ? $ctx->post('id') : $ctx->query('id');
|
|
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
|
|
if ($rule === null) {
|
|
$ctx->render('Edit autoresponder', '<div class="alert alert-err">' . AppContext::e($ctx->t('Rule not found')) . '</div>');
|
|
return;
|
|
}
|
|
$errors = [];
|
|
if (Http::isPost()) {
|
|
try {
|
|
$ctx->requireCsrf('update:' . $id);
|
|
$input = normalize_rule_post($_POST);
|
|
$patch = attach_rule_scope($ctx, RuleValidator::validate($input, $ctx->settings));
|
|
$ctx->rules->update($ctx->daUser->username(), $id, $patch);
|
|
$ctx->syncActiveBackend();
|
|
Http::redirect($ctx->url('index.html', ['status' => 'updated']));
|
|
} catch (Throwable $e) {
|
|
$errors[] = $e->getMessage();
|
|
}
|
|
}
|
|
$ctx->render('Edit autoresponder', render_rule_form($ctx, 'update', $rule), [], $errors);
|
|
};
|