<?php
namespace Misuzu;

use Misuzu\Config\CfgTools;

if(!$msz->getAuthInfo()->getPerms('global')->check(Perm::G_CONFIG_MANAGE)) {
    echo render_error(403);
    return;
}

$valueName = (string)filter_input(INPUT_GET, 'name');
$valueInfo = $cfg->getValueInfo($valueName);
if($valueInfo === null) {
    echo render_error(404);
    return;
}

if($_SERVER['REQUEST_METHOD'] === 'POST' && CSRF::validateRequest()) {
    $valueName = $valueInfo->getName();
    $msz->createAuditLog('CONFIG_DELETE', [$valueName]);
    $cfg->removeValues($valueName);
    url_redirect('manage-general-settings');
    return;
}

Template::render('manage.general.setting-delete', [
    'config_value' => $valueInfo,
]);
