misuzu/public/manage/general/setting-delete.php

38 lines
990 B
PHP
Raw Normal View History

2022-09-13 13:14:49 +00:00
<?php
namespace Misuzu;
use Misuzu\AuditLog;
use Misuzu\Config;
use Misuzu\Users\User;
require_once '../../../misuzu.php';
if(!User::hasCurrent()
|| !perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_GENERAL_MANAGE_CONFIG)) {
echo render_error(403);
return;
}
$sName = (string)filter_input(INPUT_GET, 'name');
if(!Config::validateName($sName) || !Config::has($sName))
throw new \Exception("Config value does not exist.");
if($_SERVER['REQUEST_METHOD'] === 'POST') {
if(!CSRF::validateRequest())
throw new \Exception("Request verification failed.");
AuditLog::create(AuditLog::CONFIG_DELETE, [$sName]);
Config::remove($sName);
url_redirect('manage-general-settings');
} else {
$sValue = Config::get($sName);
Template::render('manage.general.setting-delete', [
'conf_var' => [
'name' => $sName,
'type' => Config::type($sValue),
'value' => $sValue,
],
]);
}