getId(), MSZ_PERM_GENERAL_MANAGE_CONFIG)) { echo render_error(403); return; } $sVar = [ 'name' => '', 'type' => '', 'value' => null, 'new' => true, ]; $sName = (string)filter_input(INPUT_GET, 'name'); if(!empty($sName)) { if(!Config::validateName($sName)) throw new \Exception("Config key name has invalid format."); $sVar['name'] = $sName; } $sType = (string)filter_input(INPUT_GET, 'type'); if(!empty($sType)) { if(!Config::isValidType($sType)) throw new \Exception("Specified type is invalid."); $sVar['type'] = $sType; $sVar['value'] = Config::default($sType); } if($_SERVER['REQUEST_METHOD'] === 'POST') { if(!CSRF::validateRequest()) throw new \Exception("Request verification failed."); if(empty($sName)) { $sName = (string)filter_input(INPUT_POST, 'conf_name'); if(empty($sName) || !Config::validateName($sName)) throw new \Exception("Config key name has invalid format."); $sVar['name'] = $sName; } $sLogAction = AuditLog::CONFIG_CREATE; if(Config::has($sName)) { $sType = Config::type(Config::get($sName)); $sVar['new'] = false; $sLogAction = AuditLog::CONFIG_UPDATE; } elseif(empty($sType)) { $sType = (string)filter_input(INPUT_POST, 'conf_type'); if(empty($sType) || !Config::isValidType($sType)) throw new \Exception("Specified type is invalid."); } $sVar['type'] = $sType; $sValue = Config::default($sType); if($sType === 'array') { if(!empty($_POST['conf_value']) && is_array($_POST['conf_value'])) { foreach($_POST['conf_value'] as $fv) { $fv = strval($fv); if(str_starts_with($fv, 's:')) { $fv = substr($fv, 2); } elseif(str_starts_with($fv, 'i:')) { $fv = intval(substr($fv, 2)); } elseif(str_starts_with($fv, 'b:')) { $fv = strtolower(substr($fv, 2)); $fv = $fv !== 'false' && $fv !== '0' && $fv !== ''; } $sValue[] = $fv; } } } elseif($sType === 'boolean') { $sValue = !empty($_POST['conf_value']); } else { $sValue = (string)filter_input(INPUT_POST, 'conf_value'); if($sType === 'integer') $sValue = intval($sValue); } $sVar['value'] = $sValue; AuditLog::create($sLogAction, [$sName]); Config::set($sName, $sValue); url_redirect('manage-general-settings'); return; } if(Config::has($sName)) { $sVar['new'] = false; $sValue = Config::get($sName); $sVar['type'] = $sType = Config::type($sValue); if($sType === Config::TYPE_ARR) foreach($sValue as $fk => $fv) $sValue[$fk] = ['integer' => 'i', 'string' => 's', 'boolean' => 'b'][gettype($fv)] . ':' . $fv; $sVar['value'] = $sValue; } Template::render('manage.general.setting', [ 'conf_var' => $sVar, ]);