<?php
namespace Misuzu;

use Misuzu\Config\CfgTools;

if(!$msz->getAuthInfo()->getPerms('global')->check(Perm::G_CONFIG_MANAGE))
    Template::throwError(403);

$valueName = (string)filter_input(INPUT_GET, 'name');
$valueInfo = $cfg->getValueInfo($valueName);
if($valueInfo === null)
    Template::throwError(404);

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

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