/** * Constructor * * @param string $formGroupName The name of config form group to display * @param string $elemId Id of the div containing settings */ public function __construct($formGroupName, $elemId = null) { global $forms; if (empty($forms[$formGroupName])) { return; } if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { return; } if (!empty($elemId)) { $this->_elemId = $elemId; } $this->_groupName = $formGroupName; $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings); PMA_userprefsPageInit($cf); $form_display = new FormDisplay($cf); foreach ($forms[$formGroupName] as $form_name => $form) { // skip Developer form if no setting is available if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) { continue; } $form_display->registerForm($form_name, $form, 1); } // Process form $error = null; if (isset($_POST['submit_save']) && $_POST['submit_save'] == $formGroupName) { $this->_processPageSettings($form_display, $cf, $error); } // Display forms $this->_HTML = $this->_getPageSettingsDisplay($form_display, $error); }
unlink($file_to_unlink); } } else { // read from POST value (json) $json = isset($_POST['json']) ? $_POST['json'] : null; } // hide header message $_SESSION['userprefs_autoload'] = true; $config = json_decode($json, true); $return_url = isset($_POST['return_url']) ? $_POST['return_url'] : null; if (!is_array($config)) { $error = __('Could not import configuration'); } else { // sanitize input values: treat them as though // they came from HTTP POST request $form_display = new FormDisplay($cf); foreach ($forms as $formset_id => $formset) { foreach ($formset as $form_name => $form) { $form_display->registerForm($formset_id . ': ' . $form_name, $form); } } $new_config = $cf->getFlatDefaultConfig(); if (!empty($_POST['import_merge'])) { $new_config = array_merge($new_config, $cf->getConfigArray()); } $new_config = array_merge($new_config, $config); $_POST_bak = $_POST; foreach ($new_config as $k => $v) { $_POST[str_replace('/', '-', $k)] = $v; } $cf->resetConfigData();
/** * Test for FormDisplay::getDocLink * * @return void */ public function testGetDocLink() { $this->assertEquals("./url.php?url=https%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2F" . "config.html%23cfg_Servers_3_test_2_", $this->object->getDocLink("Servers/3/test/2/")); $this->assertEquals('', $this->object->getDocLink("Import")); $this->assertEquals('', $this->object->getDocLink("Export")); }
} /** * Core libraries. */ require_once './setup/lib/form_processing.lib.php'; require './libraries/config/setup.forms.php'; $mode = isset($_GET['mode']) ? $_GET['mode'] : null; $id = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null; /** @var ConfigFile $cf */ $cf = $GLOBALS['ConfigFile']; $server_exists = !empty($id) && $cf->get("Servers/{$id}") !== null; if ($mode == 'edit' && $server_exists) { $page_title = __('Edit server') . ' ' . $id . ' <small>(' . htmlspecialchars($cf->getServerDSN($id)) . ')</small>'; } elseif ($mode == 'remove' && $server_exists) { $cf->removeServer($id); header('Location: index.php' . PMA_URL_getCommon()); exit; } elseif ($mode == 'revert' && $server_exists) { // handled by process_formset() } else { $page_title = __('Add a new server'); $id = 0; } if (isset($page_title)) { echo '<h2>', $page_title . '</h2>'; } $form_display = new FormDisplay($cf); foreach ($forms['Servers'] as $form_name => $form) { $form_display->registerForm($form_name, $form, $id); } PMA_Process_formset($form_display);
/** * Processes forms registered in $form_display, handles error correction * * @param FormDisplay $form_display Form to display * * @return void */ function PMA_Process_formset(FormDisplay $form_display) { if (isset($_GET['mode']) && $_GET['mode'] == 'revert') { // revert erroneous fields to their default values $form_display->fixErrors(); PMA_generateHeader303(); } if (!$form_display->process(false)) { // handle form view and failed POST echo $form_display->getDisplay(true, true); return; } // check for form errors if (!$form_display->hasErrors()) { PMA_generateHeader303(); return; } // form has errors, show warning $separator = PMA_URL_getArgSeparator('html'); $page = isset($_GET['page']) ? $_GET['page'] : null; $formset = isset($_GET['formset']) ? $_GET['formset'] : null; $formset = $formset ? "{$separator}formset={$formset}" : ''; $formId = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null; if ($formId === null && $page == 'servers') { // we've just added a new server, get its id $formId = $form_display->getConfigFile()->getServerCount(); } $formId = $formId ? "{$separator}id={$formId}" : ''; ?> <div class="error"> <h4><?php echo __('Warning'); ?> </h4> <?php echo __('Submitted form contains errors'); ?> <br /> <a href="<?php echo PMA_URL_getCommon(), $separator; ?> page=<?php echo $page, $formset, $formId, $separator; ?> mode=revert"> <?php echo __('Try to revert erroneous fields to their default values'); ?> </a> </div> <?php echo $form_display->displayErrors(); ?> <a class="btn" href="index.php<?php echo PMA_URL_getCommon(); ?> "> <?php echo __('Ignore errors'); ?> </a> <a class="btn" href="<?php echo PMA_URL_getCommon() . $separator; ?> page=<?php echo $page . $formset . $formId . $separator; ?> mode=edit"> <?php echo __('Show form'); ?> </a> <?php }
* Gets some core libraries and displays a top message if required */ require_once 'libraries/common.inc.php'; require_once 'libraries/user_preferences.lib.php'; require_once 'libraries/config/config_functions.lib.php'; require_once 'libraries/config/messages.inc.php'; require 'libraries/config/user_preferences.forms.php'; $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings); PMA_userprefsPageInit($cf); // handle form processing $form_param = isset($_GET['form']) ? $_GET['form'] : null; if (!isset($forms[$form_param])) { $forms_keys = array_keys($forms); $form_param = array_shift($forms_keys); } $form_display = new FormDisplay($cf); foreach ($forms[$form_param] as $form_name => $form) { // skip Developer form if no setting is available if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) { continue; } $form_display->registerForm($form_name, $form, 1); } if (isset($_POST['revert'])) { // revert erroneous fields to their default values $form_display->fixErrors(); // redirect $url_params = array('form' => $form_param); PMA_sendHeaderLocation('./prefs_forms.php' . URL::getCommonRaw($url_params)); exit; }
} echo '<table width="100%">'; echo '<tr>'; echo '<td class="lastrow" style="text-align: left">'; echo '<input type="submit" name="submit" value="', __('New server'), '" />'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '</div>'; echo PMA_displayFormBottom(); echo '</fieldset>'; echo '<fieldset class="simple"><legend>', __('Configuration file'), '</legend>'; // // Display config file settings and load/save form // $form_display = new FormDisplay($cf); echo PMA_displayFormTop('config.php'); echo '<table width="100%" cellspacing="0">'; // Display language list $opts = array('doc' => $form_display->getDocLink('DefaultLang'), 'values' => array(), 'values_escaped' => true); foreach ($all_languages as $each_lang) { $opts['values'][$each_lang->getCode()] = $each_lang->getName(); } echo PMA_displayInput('DefaultLang', __('Default language'), 'select', $cf->getValue('DefaultLang'), '', true, $opts); // Display server list $opts = array('doc' => $form_display->getDocLink('ServerDefault'), 'values' => array(), 'values_disabled' => array()); if ($cf->getServerCount() > 0) { $opts['values']['0'] = __('let the user choose'); $opts['values']['-'] = '------------------------------'; if ($cf->getServerCount() == 1) { $opts['values_disabled'][] = '0';
* * Do this in a function to avoid messing up with global $cfg * * @param string $config_file_path * * @return array */ function loadConfig($config_file_path) { $cfg = array(); if (file_exists($config_file_path)) { include $config_file_path; } return $cfg; } $form_display = new FormDisplay($GLOBALS['ConfigFile']); $form_display->registerForm('_config.php', $forms['_config.php']); $form_display->save('_config.php'); $config_file_path = $GLOBALS['ConfigFile']->getFilePath(); if (isset($_POST['eol'])) { $_SESSION['eol'] = $_POST['eol'] == 'unix' ? 'unix' : 'win'; } if (PMA_ifSetOr($_POST['submit_clear'], '')) { // // Clear current config and return to main page // $GLOBALS['ConfigFile']->resetConfigData(); // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php' . PMA_URL_getCommon()); exit;