/** * Test for PMA_displayFormTop() * * @return void */ public function testDisplayFormTop() { $_SERVER['REQUEST_URI'] = 'http://www.phpmyadmin.net'; $GLOBALS['cfg']['ServerDefault'] = ''; $result = PMA_displayFormTop(null, 'posted', array(1)); $this->assertContains('<form method="get" action="http://www.phpmyadmin.net" ' . 'class="config-form disableAjax">', $result); $this->assertContains('<input type="hidden" name="tab_hash" value="" />', $result); $this->assertContains('<input type="hidden" name="lang" value="en" />', $result); $this->assertContains('<input type="hidden" name="token" value="token" />', $result); $this->assertContains('<input type="hidden" name="0" value="1" />', $result); }
/** * Test for PMA_displayFormTop() * * @return void */ public function testDisplayFormTop() { $_SERVER['REQUEST_URI'] = 'http://www.phpmyadmin.net'; $GLOBALS['cfg']['ServerDefault'] = ''; ob_start(); PMA_displayFormTop(null, 'posted', array(1)); $result = ob_get_clean(); $this->assertTag( PMA_getTagArray( '<form method="get" action="http://www.phpmyadmin.net" ' . 'class="config-form disableAjax">' ), $result ); $this->assertTag( PMA_getTagArray( '<input type="hidden" name="tab_hash" value="" />' ), $result ); $this->assertTag( PMA_getTagArray( '<input type="hidden" name="check_page_refresh" ' . 'id="check_page_refresh" value="" />' ), $result ); $this->assertTag( PMA_getTagArray( '<input type="hidden" name="lang" value="en" />' ), $result ); $this->assertTag( PMA_getTagArray( '<input type="hidden" name="token" value="token" />' ), $result ); $this->assertTag( PMA_getTagArray( '<input type="hidden" name="0" value="1" />' ), $result ); }
/** * Outputs HTML for forms * * @param bool $tabbed_form if true, use a form with tabs * @param bool $show_restore_default whether show "restore default" button * besides the input field * @param bool $show_buttons whether show submit and reset button * @param string $form_action action attribute for the form * @param array $hidden_fields array of form hidden fields (key: field * name) * * @return string HTML for forms */ public function getDisplay($tabbed_form = false, $show_restore_default = false, $show_buttons = true, $form_action = null, $hidden_fields = null) { static $js_lang_sent = false; $htmlOutput = ''; $js = array(); $js_default = array(); $htmlOutput .= PMA_displayFormTop($form_action, 'post', $hidden_fields); if ($tabbed_form) { $tabs = array(); foreach ($this->_forms as $form) { $tabs[$form->name] = PMA_lang("Form_{$form->name}"); } $htmlOutput .= PMA_displayTabsTop($tabs); } // validate only when we aren't displaying a "new server" form $is_new_server = false; foreach ($this->_forms as $form) { /* @var $form Form */ if ($form->index === 0) { $is_new_server = true; break; } } if (!$is_new_server) { $this->_validate(); } // user preferences $this->_loadUserprefsInfo(); // display forms $htmlOutput .= $this->_displayForms($show_restore_default, $js_default, $js, $show_buttons); if ($tabbed_form) { $htmlOutput .= PMA_displayTabsBottom(); } $htmlOutput .= PMA_displayFormBottom(); // if not already done, send strings used for validation to JavaScript if (!$js_lang_sent) { $js_lang_sent = true; $js_lang = array(); foreach ($this->_jsLangStrings as $strName => $strValue) { $js_lang[] = "'{$strName}': '" . Sanitize::jsFormat($strValue, false) . '\''; } $js[] = "\$.extend(PMA_messages, {\n\t" . implode(",\n\t", $js_lang) . '})'; } $js[] = "\$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})'; $htmlOutput .= PMA_displayJavascript($js); return $htmlOutput; }
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) { $opts['values_disabled'][] = '0';
/** * Outputs HTML for forms * * @param bool $tabbed_form * @param bool $show_restore_default whether show "restore default" button * besides the input field * * @return void */ public function display($tabbed_form = false, $show_restore_default = false) { static $js_lang_sent = false; $js = array(); $js_default = array(); $tabbed_form = $tabbed_form && count($this->_forms) > 1; $validators = PMA_config_get_validators(); PMA_displayFormTop(); if ($tabbed_form) { $tabs = array(); foreach ($this->_forms as $form) { $tabs[$form->name] = PMA_lang("Form_{$form->name}"); } PMA_displayTabsTop($tabs); } // valdiate only when we aren't displaying a "new server" form $is_new_server = false; foreach ($this->_forms as $form) { /* @var $form Form */ if ($form->index === 0) { $is_new_server = true; break; } } if (!$is_new_server) { $this->_validate(); } // user preferences $this->_loadUserprefsInfo(); // display forms foreach ($this->_forms as $form) { /* @var $form Form */ $form_desc = isset($GLOBALS["strConfigForm_{$form->name}_desc"]) ? PMA_lang("Form_{$form->name}_desc") : ''; $form_errors = isset($this->_errors[$form->name]) ? $this->_errors[$form->name] : null; PMA_displayFieldsetTop(PMA_lang("Form_{$form->name}"), $form_desc, $form_errors, array('id' => $form->name)); foreach ($form->fields as $field => $path) { $work_path = array_search($path, $this->_systemPaths); $translated_path = $this->_translatedPaths[$work_path]; // always true/false for user preferences display // otherwise null $userprefs_allow = isset($this->_userprefsKeys[$path]) ? !isset($this->_userprefsDisallow[$path]) : null; // display input $this->_displayFieldInput($form, $field, $path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, $js_default); // register JS validators for this field if (isset($validators[$path])) { PMA_addJsValidate($translated_path, $validators[$path], $js); } } PMA_displayFieldsetBottom(); } if ($tabbed_form) { PMA_displayTabsBottom(); } PMA_displayFormBottom(); // if not already done, send strings used for valdiation to JavaScript if (!$js_lang_sent) { $js_lang_sent = true; $js_lang = array(); foreach ($this->_jsLangStrings as $strName => $strValue) { $js_lang[] = "'{$strName}': '" . PMA_jsFormat($strValue, false) . '\''; } $js[] = "\$.extend(PMA_messages, {\n\t" . implode(",\n\t", $js_lang) . '})'; } $js[] = "\$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})'; PMA_displayJavascript($js); }