<?php
namespace Misuzu;

use Misuzu\Config;
use Misuzu\Config\CfgTools;
use Misuzu\Config\IConfig;
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;
}

$hidden = $cfg->getValue('settings.hidden', IConfig::T_ARR, []);

$vars = [];
foreach($cfg->getNames() as $key) {
    $var = $cfg->getValue($key);
    $vars[] = [
        'key' => $key,
        'type' => CfgTools::type($var),
        'value' => in_array($key, $hidden) ? '*** hidden ***' : json_encode($var),
    ];
}

Template::render('manage.general.settings', [
    'conf_vars' => $vars,
]);
