/** * 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); }
/** * Processes forms registered in $form_display, handles error correction * * @param FormDisplay $form_display */ function process_formset(FormDisplay $form_display) { if (filter_input(INPUT_GET, 'mode') == 'revert') { // revert erroneous fields to their default values $form_display->fixErrors(); // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php'); exit; } if (!$form_display->process(false)) { // handle form view and failed POST $form_display->display(true, true); } else { // check for form errors if ($form_display->hasErrors()) { // form has errors, show warning $separator = PMA_get_arg_separator('html'); $page = filter_input(INPUT_GET, 'page'); $formset = filter_input(INPUT_GET, 'formset'); $formset = $formset ? "{$separator}formset=$formset" : ''; $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); if ($id === null && $page == 'servers') { // we've just added a new server, get it's id $id = ConfigFile::getInstance()->getServerCount(); } $id = $id ? "{$separator}id=$id" : ''; ?> <div class="error"> <h4><?php echo __('Warning') ?></h4> <?php echo __('Submitted form contains errors') ?><br /> <a href="?page=<?php echo $page . $formset . $id . $separator ?>mode=revert"><?php echo __('Try to revert erroneous fields to their default values') ?></a> </div> <?php $form_display->displayErrors() ?> <a class="btn" href="index.php"><?php echo __('Ignore errors') ?></a> <a class="btn" href="?page=<?php echo $page . $formset . $id . $separator ?>mode=edit"><?php echo __('Show form') ?></a> <?php } else { // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php'); exit; } } }
/* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Front controller for config view / download and clear * * @package PhpMyAdmin-Setup */ /** * Core libraries. */ require './lib/common.inc.php'; require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/ConfigGenerator.class.php'; require './libraries/config/setup.forms.php'; $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'); exit;
<td class="lastrow" style="text-align: left"> <input type="submit" name="submit" value="<?php echo __('New server') ?>" /> </td> </tr> </table> </div> <?php display_form_bottom(); ?> <h3><?php echo __('Configuration file') ?></h3> <?php // // Display config file settings and load/save form // $form_display = new FormDisplay(); display_form_top('config.php'); display_fieldset_top('', '', null, array('class' => 'simple')); // Display language list $opts = array( 'doc' => $form_display->getDocLink('DefaultLang'), 'wiki' => $form_display->getWikiLink('DefaultLang'), 'values' => array(), 'values_escaped' => true); foreach ($all_languages as $each_lang_key => $each_lang) { $lang_name = PMA_langName($each_lang); $opts['values'][$each_lang_key] = $lang_name; } display_input('DefaultLang', __('Default language'), '', 'select',
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_once './libraries/config/ConfigFile.class.php'; require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require './libraries/config/user_preferences.forms.php'; PMA_userprefs_pageinit(); // handle form processing $form_param = filter_input(INPUT_GET, 'form'); if (!isset($forms[$form_param])) { $forms_keys = array_keys($forms); $form_param = array_shift($forms_keys); } $form_display = new FormDisplay(); 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($cfg['PmaAbsoluteUri'] . 'prefs_forms.php' . PMA_generate_common_url($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_key => $each_lang) { $lang_name = PMA_languageName($each_lang); $opts['values'][$each_lang_key] = $lang_name; } 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) {
/** * Core libraries. */ require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; require './libraries/config/setup.forms.php'; $mode = filter_input(INPUT_GET, 'mode'); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); $cf = ConfigFile::getInstance(); $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'); 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(); foreach ($forms['Servers'] as $form_name => $form) { $form_display->registerForm($form_name, $form, $id); } process_formset($form_display);
unlink($file_to_unlink); } } else { // read from POST value (json) $json = filter_input(INPUT_POST, 'json'); } // hide header message $_SESSION['userprefs_autoload'] = true; $config = json_decode($json, true); $return_url = filter_input(INPUT_POST, 'return_url'); 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(); foreach ($forms as $formset_id => $formset) { foreach ($formset as $form_name => $form) { $form_display->registerForm($formset_id . ': ' . $form_name, $form); } } $cf = ConfigFile::getInstance(); $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; }
/** * Test for FormDisplay::getDocLink * * @return void */ public function testGetDocLink() { $this->assertEquals("./url.php?url=http%3A%2F%2Fdocs.phpmyadmin.net%2Fen%2Flatest%2F" . "config.html%23cfg_Servers_3_test_2_&server=0&lang=en&" . ";token=token", $this->object->getDocLink("Servers/3/test/2/")); $this->assertEquals('', $this->object->getDocLink("Import")); $this->assertEquals('', $this->object->getDocLink("Export")); }
require_once './setup/lib/Form.class.php'; require_once './setup/lib/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; $mode = filter_input(INPUT_GET, 'mode'); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); $cf = ConfigFile::getInstance(); $server_exists = !empty($id) && $cf->get("Servers/{$id}") !== null; if ($mode == 'edit' && $server_exists) { $page_title = $GLOBALS['strSetupServersEdit'] . ' ' . $id . ' <small>(' . $cf->getServerDSN($id) . ')</small>'; } elseif ($mode == 'remove' && $server_exists) { $cf->removeServer($id); header('Location: index.php'); exit; } elseif ($mode == 'revert' && $server_exists) { // handled by process_formset() } else { $page_title = $GLOBALS['strSetupServersAdd']; $id = 0; } ?> <h2><?php echo $page_title; ?> </h2> <?php $form_display = new FormDisplay(); $form_display->registerForm('Server', $id); $form_display->registerForm('Server_login_options', $id); $form_display->registerForm('Server_config', $id); $form_display->registerForm('Server_pmadb', $id); 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 }
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Form edit view * * @package PhpMyAdmin-Setup */ if (!defined('PHPMYADMIN')) { exit; } /** * Core libraries. */ require_once './libraries/config/Form.class.php'; require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; require './libraries/config/setup.forms.php'; $formset_id = filter_input(INPUT_GET, 'formset'); $mode = filter_input(INPUT_GET, 'mode'); if (!isset($forms[$formset_id])) { PMA_fatalError(__('Incorrect formset, check $formsets array in setup/frames/form.inc.php!')); } if (isset($GLOBALS['strConfigFormset_' . $formset_id])) { echo '<h2>' . $GLOBALS['strConfigFormset_' . $formset_id] . '</h2>'; } $form_display = new FormDisplay($GLOBALS['ConfigFile']); foreach ($forms[$formset_id] as $form_name => $form) { $form_display->registerForm($form_name, $form); } 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 (filter_input(INPUT_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 $form_display->display(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 = filter_input(INPUT_GET, 'page'); $formset = filter_input(INPUT_GET, 'formset'); $formset = $formset ? "{$separator}formset={$formset}" : ''; $formId = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); 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="?page=<?php echo $page . $formset . $formId . $separator; ?> mode=revert"> <?php echo __('Try to revert erroneous fields to their default values'); ?> </a> </div> <?php $form_display->displayErrors(); ?> <a class="btn" href="index.php"><?php echo __('Ignore errors'); ?> </a> <a class="btn" href="?page=<?php echo $page . $formset . $formId . $separator; ?> mode=edit"><?php echo __('Show form'); ?> </a> <?php }
/** * Processes forms registered in $form_display, handles error correction * * @param FormDisplay $form_display * * @return void */ function process_formset(FormDisplay $form_display) { if (isset($_GET['mode']) && $_GET['mode'] == 'revert') { // revert erroneous fields to their default values $form_display->fixErrors(); // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php'); exit; } if (!$form_display->process(false)) { // handle form view and failed POST $form_display->display(true, true); } else { // check for form errors if ($form_display->hasErrors()) { // form has errors, show warning $separator = PMA_get_arg_separator('html'); $page = isset($_GET['page']) ? $_GET['page'] : null; $formset = isset($_GET['formset']) ? $_GET['formset'] : null; $formset = $formset ? "{$separator}formset={$formset}" : ''; $id = PMA_isValid($_GET['id'], 'numeric') ? $_GET['id'] : null; if ($id === null && $page == 'servers') { // we've just added a new server, get it's id $id = ConfigFile::getInstance()->getServerCount(); } $id = $id ? "{$separator}id={$id}" : ''; ?> <div class="error"> <h4><?php echo __('Warning'); ?> </h4> <?php echo __('Submitted form contains errors'); ?> <br /> <a href="?page=<?php echo $page . $formset . $id . $separator . PMA_generate_common_url() . $separator; ?> mode=revert"><?php echo __('Try to revert erroneous fields to their default values'); ?> </a> </div> <?php $form_display->displayErrors(); ?> <a class="btn" href="index.php?<?php echo PMA_generate_common_url(); ?> "><?php echo __('Ignore errors'); ?> </a> <a class="btn" href="?page=<?php echo $page . $formset . $id . $separator . PMA_generate_common_url() . $separator; ?> mode=edit"><?php echo __('Show form'); ?> </a> <?php } else { // drop post data header('HTTP/1.1 303 See Other'); header('Location: index.php'); exit; } } }