Beispiel #1
0
    if ($cf->getServerCount() == 1) {
        $opts['values_disabled'][] = '0';
    }
    $opts['values_disabled'][] = '-';
    foreach ($cf->getServers() as $id => $server) {
        $opts['values'][(string) $id] = $cf->getServerName($id) . " [{$id}]";
    }
} else {
    $opts['values']['1'] = __('- none -');
    $opts['values_escaped'] = true;
}
echo PMA_displayInput('ServerDefault', __('Default server'), 'select', $cf->getValue('ServerDefault'), '', true, $opts);
// Display EOL list
$opts = array('values' => array('unix' => 'UNIX / Linux (\\n)', 'win' => 'Windows (\\r\\n)'), 'values_escaped' => true);
$eol = PMA_ifSetOr($_SESSION['eol'], PMA_IS_WINDOWS ? 'win' : 'unix');
echo PMA_displayInput('eol', __('End of line'), 'select', $eol, '', true, $opts);
echo '<tr>';
echo '<td colspan="2" class="lastrow" style="text-align: left">';
echo '<input type="submit" name="submit_display" value="' . __('Display') . '" />';
echo '<input type="submit" name="submit_download" value="' . __('Download') . '" />';
echo '&nbsp; &nbsp;';
echo '<input type="submit" name="submit_save" value="' . __('Save') . '"';
if (!$config_writable) {
    echo ' disabled="disabled"';
}
echo '/>';
echo '<input type="submit" name="submit_load" value="' . __('Load') . '"';
if (!$config_exists) {
    echo ' disabled="disabled"';
}
echo '/>';
Beispiel #2
0
 /**
  * Prepares data for input field display and outputs HTML code
  *
  * @param Form      $form                 Form object
  * @param string    $field                field name as it appears in $form
  * @param string    $system_path          field path, eg. Servers/1/verbose
  * @param string    $work_path            work path, eg. Servers/4/verbose
  * @param string    $translated_path      work path changed so that it can be
  *                                        used as XHTML id
  * @param bool      $show_restore_default whether show "restore default" button
  *                                        besides the input field
  * @param bool|null $userprefs_allow      whether user preferences are enabled
  *                                        for this field (null - no support,
  *                                        true/false - enabled/disabled)
  * @param array     &$js_default          array which stores JavaScript code
  *                                        to be displayed
  *
  * @return string HTML for input field
  */
 private function _displayFieldInput(Form $form, $field, $system_path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, array &$js_default)
 {
     $name = PMA_langName($system_path);
     $description = PMA_langName($system_path, 'desc', '');
     $value = $this->_configFile->get($work_path);
     $value_default = $this->_configFile->getDefault($system_path);
     $value_is_default = false;
     if ($value === null || $value === $value_default) {
         $value = $value_default;
         $value_is_default = true;
     }
     $opts = array('doc' => $this->getDocLink($system_path), 'show_restore_default' => $show_restore_default, 'userprefs_allow' => $userprefs_allow, 'userprefs_comment' => PMA_langName($system_path, 'cmt', ''));
     if (isset($form->default[$system_path])) {
         $opts['setvalue'] = $form->default[$system_path];
     }
     if (isset($this->_errors[$work_path])) {
         $opts['errors'] = $this->_errors[$work_path];
     }
     $type = '';
     switch ($form->getOptionType($field)) {
         case 'string':
             $type = 'text';
             break;
         case 'short_string':
             $type = 'short_text';
             break;
         case 'double':
         case 'integer':
             $type = 'number_text';
             break;
         case 'boolean':
             $type = 'checkbox';
             break;
         case 'select':
             $type = 'select';
             $opts['values'] = $form->getOptionValueList($form->fields[$field]);
             break;
         case 'array':
             $type = 'list';
             $value = (array) $value;
             $value_default = (array) $value_default;
             break;
         case 'group':
             // :group:end is changed to :group:end:{unique id} in Form class
             $htmlOutput = '';
             if (mb_substr($field, 7, 4) != 'end:') {
                 $htmlOutput .= PMA_displayGroupHeader(mb_substr($field, 7));
             } else {
                 PMA_displayGroupFooter();
             }
             return $htmlOutput;
         case 'NULL':
             trigger_error("Field {$system_path} has no type", E_USER_WARNING);
             return null;
     }
     // detect password fields
     if ($type === 'text' && mb_substr($translated_path, -9) === '-password') {
         $type = 'password';
     }
     // TrustedProxies requires changes before displaying
     if ($system_path == 'TrustedProxies') {
         foreach ($value as $ip => &$v) {
             if (!preg_match('/^-\\d+$/', $ip)) {
                 $v = $ip . ': ' . $v;
             }
         }
     }
     $this->_setComments($system_path, $opts);
     // send default value to form's JS
     $js_line = '\'' . $translated_path . '\': ';
     switch ($type) {
         case 'text':
         case 'short_text':
         case 'number_text':
         case 'password':
             $js_line .= '\'' . Sanitize::escapeJsString($value_default) . '\'';
             break;
         case 'checkbox':
             $js_line .= $value_default ? 'true' : 'false';
             break;
         case 'select':
             $value_default_js = is_bool($value_default) ? (int) $value_default : $value_default;
             $js_line .= '[\'' . Sanitize::escapeJsString($value_default_js) . '\']';
             break;
         case 'list':
             $js_line .= '\'' . Sanitize::escapeJsString(implode("\n", $value_default)) . '\'';
             break;
     }
     $js_default[] = $js_line;
     return PMA_displayInput($translated_path, $name, $type, $value, $description, $value_is_default, $opts);
 }
 /**
  * Test for PMA_displayInput()
  *
  * @return void
  */
 public function testDisplayInput()
 {
     if (!PMA_HAS_RUNKIT) {
         $this->markTestSkipped('Cannot modify constant');
     }
     $GLOBALS['_FormDislayGroup'] = 1;
     $opts = array();
     $opts['errors'] = array('e1');
     $opts['userprefs_allow'] = false;
     $opts['setvalue'] = ':group';
     $opts['doc'] = "http://doclink";
     $opts['comment'] = "testComment";
     $opts['comment_warning'] = true;
     $opts['show_restore_default'] = true;
     $result = PMA_displayInput('test/path', 'testName', 'text', 'val', 'desc', false, $opts);
     $this->assertContains('<tr class="group-header-field group-header-1 disabled-field">', $result);
     $this->assertContains('<label for="test/path">', $result);
     $this->assertContains('<a href="http://doclink" target="documentation"', $result);
     $this->assertContains('<img src="themes/dot.gif" title="Documentation" ' . 'alt="Documentation" class="icon ic_b_help" /', $result);
     $this->assertContains('<span class="disabled-notice"', $result);
     $this->assertContains('<small>', $result);
     $this->assertContains('<input type="text" size="40" name="test/path" id="test/path" ' . 'class="custom field-error" value="val" />', $result);
     $this->assertContains('<span class="field-comment-mark field-comment-warning" ' . 'title="testComment">', $result);
     $this->assertContains('<a class="restore-default" href="#test/path"', $result);
     $this->assertContains('<dl class="inline_errors"><dd>e1</dd></dl>', $result);
     // second case
     define('PMA_SETUP', true);
     $GLOBALS['_FormDislayGroup'] = 0;
     $GLOBALS['cfg']['ThemePath'] = 'themePath';
     $opts = array();
     $opts['errors'] = array();
     $opts['setvalue'] = 'setVal';
     $opts['comment'] = "testComment";
     $opts['show_restore_default'] = true;
     $opts['userprefs_comment'] = 'userprefsComment';
     $opts['userprefs_allow'] = true;
     $result = PMA_displayInput('test/path', 'testName', 'checkbox', 'val', '', false, $opts);
     $this->assertContains('<tr class="group-field group-field-1">', $result);
     $this->assertContains('<input type="checkbox" name="test/path" id="test/path" ' . 'checked="checked" />', $result);
     $this->assertContains('<a class="userprefs-comment" title="userprefsComment">', $result);
     $this->assertContains('<td class="userprefs-allow" title="Allow users to customize ' . 'this value">', $result);
     $this->assertContains('<a class="set-value" href="#test/path=setVal" ' . 'title="Set value: setVal" style="display:none">', $result);
     // short_text
     $GLOBALS['_FormDislayGroup'] = 0;
     $GLOBALS['cfg']['ThemePath'] = 'themePath';
     $opts = array();
     $opts['errors'] = array();
     $result = PMA_displayInput('test/path', 'testName', 'short_text', 'val', '', true, $opts);
     $this->assertContains('<input type="text" size="25" name="test/path" id="test/path" ' . 'value="val" />', $result);
     // number_text
     $result = PMA_displayInput('test/path', 'testName', 'number_text', 'val', '', true, $opts);
     $this->assertContains('<input type="number" name="test/path" ' . 'id="test/path" value="val" />', $result);
     // select case 1
     $opts['values_escaped'] = true;
     $opts['values_disabled'] = array(1, 2);
     $opts['values'] = array(1 => 'test', 'key1' => true, 'key2' => false);
     $result = PMA_displayInput('test/path', 'testName', 'select', true, '', true, $opts);
     $this->assertContains('<select name="test/path" id="test/path">', $result);
     $this->assertContains('<option value="1" selected="selected" disabled="disabled">', $result);
     $this->assertContains('<option value="key1">', $result);
     $this->assertContains('<option value="key2">', $result);
     // select case 2
     $opts['values_escaped'] = false;
     $opts['values_disabled'] = array(1, 2);
     $opts['values'] = array('a<b' => 'c&d', 'key1' => true, 'key2' => false);
     $result = PMA_displayInput('test/path', 'testName', 'select', false, '', true, $opts);
     $this->assertContains('<select name="test/path" id="test/path">', $result);
     // assertContains doesn't seem to work with htmlentities
     $this->assertContains('<option value="a&lt;b">c&amp;d</option>', $result);
     // list
     $result = PMA_displayInput('test/path', 'testName', 'list', array('foo', 'bar'), '', true, $opts);
     $this->assertContains('<textarea cols="40" rows="5" name="test/path" id="test/path">', $result);
     runkit_constant_remove('PMA_SETUP');
 }