27 lines
1.2 KiB
PHP
27 lines
1.2 KiB
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('Confirm deletion', '<div class="alert alert-err">' . AppContext::e($ctx->t('Rule not found')) . '</div>');
|
|
return;
|
|
}
|
|
if (Http::isPost()) {
|
|
try {
|
|
$ctx->requireCsrf('delete:' . $id);
|
|
$deletedName = display_rule_name($ctx, $rule);
|
|
$ctx->rules->delete($ctx->daUser->username(), $id);
|
|
$ctx->syncDirectAdminVacations();
|
|
$ctx->audit->record('delete', $ctx->daUser->username(), ['rule_id' => $id, 'subject_prefix' => (string)($rule['subject_prefix'] ?? $rule['subject'] ?? '')]);
|
|
Http::redirect($ctx->url('index.html', ['status' => 'deleted', 'name' => $deletedName]));
|
|
} catch (Throwable $e) {
|
|
PluginLogger::exception($e, 'DELETE');
|
|
$ctx->render('Confirm deletion', '<div class="alert alert-err">' . AppContext::e($e->getMessage()) . '</div>');
|
|
return;
|
|
}
|
|
}
|
|
$ctx->render('Confirm deletion', render_delete_confirmation_body($ctx, $rule));
|
|
};
|