registerForm() public method

Registers form in form manager
public registerForm ( string $form_name, array $form, integer $server_id = null ) : void
$form_name string Form name
$form array Form data
$server_id integer 0 if new server, validation; >= 1 if editing a server
return void
Ejemplo n.º 1
0
 /**
  * Test for FormDisplay::registerForm
  *
  * @return void
  * @group medium
  */
 public function testRegisterForm()
 {
     $reflection = new \ReflectionClass('PMA\\libraries\\config\\FormDisplay');
     $attrForms = $reflection->getProperty('_forms');
     $attrForms->setAccessible(true);
     $array = array("Servers" => array("1" => array('test' => 1, 1 => ':group:end')));
     $this->object->registerForm('pma_testform', $array, 2);
     $_forms = $attrForms->getValue($this->object);
     $this->assertInstanceOf('PMA\\libraries\\config\\Form', $_forms['pma_testform']);
     $this->assertEquals(array("Servers/2/test" => "Servers/1/test", "Servers/2/:group:end:0" => "Servers/1/:group:end:0"), $this->readAttribute($this->object, '_systemPaths'));
     $this->assertEquals(array("Servers/2/test" => "Servers-2-test", "Servers/2/:group:end:0" => "Servers-2-:group:end:0"), $this->readAttribute($this->object, '_translatedPaths'));
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }
Ejemplo n.º 3
0
     // 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();
     $all_ok = $form_display->process(true, false);
     $all_ok = $all_ok && !$form_display->hasErrors();
     $_POST = $_POST_bak;
Ejemplo n.º 4
0
}
/**
 * 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);
Ejemplo n.º 5
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;
} elseif (PMA_ifSetOr($_POST['submit_download'], '')) {