';
return $htmlOutput;
}
/**
* Displays top part of a fieldset
*
* @param string $title title of fieldset
* @param string $description description shown on top of fieldset
* @param array|null $errors error messages to display
* @param array $attributes optional extra attributes of fieldset
*
* @return string
*/
public static function displayFieldsetTop(
$title = '',
$description = '',
$errors = null,
array $attributes = array()
) {
global $_FormDisplayGroup;
$_FormDisplayGroup = 0;
$attributes = array_merge(array('class' => 'optbox'), $attributes);
return Template::get('config/form_display/fieldset_top')->render([
'attributes' => $attributes,
'title' => $title,
'description' => $description,
'errors' => $errors,
]);
}
/**
* Displays input field
*
* $opts keys:
* o doc - (string) documentation link
* o errors - error array
* o setvalue - (string) shows button allowing to set predefined value
* o show_restore_default - (boolean) whether show "restore default" button
* o userprefs_allow - whether user preferences are enabled for this field
* (null - no support, true/false - enabled/disabled)
* o userprefs_comment - (string) field comment
* o values - key - value pairs for
fields
* o values_escaped - (boolean) tells whether values array is already escaped
* (defaults to false)
* o values_disabled - (array)list of disabled values (keys from values)
* o comment - (string) tooltip comment
* o comment_warning - (bool) whether this comments warns about something
*
* @param string $path config option path
* @param string $name config option name
* @param string $type type of config option
* @param mixed $value current value
* @param string $description verbose description
* @param bool $value_is_default whether value is default
* @param array|null $opts see above description
*
* @return string
*/
public static function displayInput($path, $name, $type, $value, $description = '',
$value_is_default = true, $opts = null
) {
global $_FormDisplayGroup;
static $icons; // An array of IMG tags used further below in the function
if (defined('TESTSUITE')) {
$icons = null;
}
$is_setup_script = $GLOBALS['PMA_Config']->get('is_setup');
if ($icons === null) { // if the static variables have not been initialised
$icons = array();
// Icon definitions:
// The same indexes will be used in the $icons array.
// The first element contains the filename and the second
// element is used for the "alt" and "title" attributes.
$icon_init = array(
'edit' => array('b_edit', ''),
'help' => array('b_help', __('Documentation')),
'reload' => array('s_reload', ''),
'tblops' => array('b_tblops', '')
);
if ($is_setup_script) {
// When called from the setup script, we don't have access to the
// sprite-aware getImage() function because the PMA_theme class
// has not been loaded, so we generate the img tags manually.
foreach ($icon_init as $k => $v) {
$title = '';
if (! empty($v[1])) {
$title = ' title="' . $v[1] . '"';
}
$icons[$k] = sprintf(
' ',
$v[1],
"../themes/pmahomme/img/{$v[0]}.png",
$title
);
}
} else {
// In this case we just use getImage() because it's available
foreach ($icon_init as $k => $v) {
$icons[$k] = Util::getImage(
$v[0], $v[1]
);
}
}
}
$has_errors = isset($opts['errors']) && !empty($opts['errors']);
$option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
&& ! $opts['userprefs_allow'];
$name_id = 'name="' . htmlspecialchars($path) . '" id="'
. htmlspecialchars($path) . '"';
$field_class = $type == 'checkbox' ? 'checkbox' : '';
if (! $value_is_default) {
$field_class .= ($field_class == '' ? '' : ' ')
. ($has_errors ? 'custom field-error' : 'custom');
}
$field_class = $field_class ? ' class="' . $field_class . '"' : '';
$tr_class = $_FormDisplayGroup > 0
? 'group-field group-field-' . $_FormDisplayGroup
: '';
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
unset($opts['setvalue']);
$_FormDisplayGroup++;
$tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
}
if ($option_is_disabled) {
$tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
}
$tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
$htmlOutput = '';
$htmlOutput .= '';
$htmlOutput .= '' . $name
. ' ';
if (! empty($opts['doc'])) {
$htmlOutput .= '';
$htmlOutput .= '' . $icons['help'] . ' ';
$htmlOutput .= "\n";
$htmlOutput .= ' ';
}
if ($option_is_disabled) {
$htmlOutput .= '' . __('Disabled') . " ";
}
if (!empty($description)) {
$htmlOutput .= '' . $description . ' ';
}
$htmlOutput .= ' ';
$htmlOutput .= '';
switch ($type) {
case 'text':
$htmlOutput .= ' ';
break;
case 'password':
$htmlOutput .= ' ';
break;
case 'short_text':
// As seen in the reporting server (#15042) we sometimes receive
// an array here. No clue about its origin nor content, so let's avoid
// a notice on htmlspecialchars().
if (! is_array($value)) {
$htmlOutput .= ' ';
}
break;
case 'number_text':
$htmlOutput .= ' ';
break;
case 'checkbox':
$htmlOutput .= ' ';
break;
case 'select':
$htmlOutput .= '';
$escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
$values_disabled = isset($opts['values_disabled'])
? array_flip($opts['values_disabled']) : array();
foreach ($opts['values'] as $opt_value_key => $opt_value) {
// set names for boolean values
if (is_bool($opt_value)) {
$opt_value = mb_strtolower(
$opt_value ? __('Yes') : __('No')
);
}
// escape if necessary
if ($escape) {
$display = htmlspecialchars($opt_value);
$display_value = htmlspecialchars($opt_value_key);
} else {
$display = $opt_value;
$display_value = $opt_value_key;
}
// compare with selected value
// boolean values are cast to integers when used as array keys
$selected = is_bool($value)
? (int) $value === $opt_value_key
: $opt_value_key === $value;
$htmlOutput .= '';
}
$htmlOutput .= ' ';
break;
case 'list':
$htmlOutput .= '';
break;
}
if (isset($opts['comment']) && $opts['comment']) {
$class = 'field-comment-mark';
if (isset($opts['comment_warning']) && $opts['comment_warning']) {
$class .= ' field-comment-warning';
}
$htmlOutput .= 'i ';
}
if ($is_setup_script
&& isset($opts['userprefs_comment'])
&& $opts['userprefs_comment']
) {
$htmlOutput .= '';
}
if (isset($opts['setvalue']) && $opts['setvalue']) {
$htmlOutput .= '' . $icons['edit'] . ' ';
}
if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
$htmlOutput .= '' . $icons['reload'] . ' ';
}
// this must match with displayErrors() in scripts/config.js
if ($has_errors) {
$htmlOutput .= "\n ";
foreach ($opts['errors'] as $error) {
$htmlOutput .= '' . htmlspecialchars($error) . ' ';
}
$htmlOutput .= ' ';
}
$htmlOutput .= ' ';
if ($is_setup_script && isset($opts['userprefs_allow'])) {
$htmlOutput .= '';
$htmlOutput .= ' get('is_setup') ? 3 : 2;
return Template::get('config/form_display/group_header')->render([
'group' => $_FormDisplayGroup,
'colspan' => $colspan,
'header_text' => $headerText,
]);
}
/**
* Display group footer
*
* @return void
*/
public static function displayGroupFooter()
{
global $_FormDisplayGroup;
$_FormDisplayGroup--;
}
/**
* Displays bottom part of a fieldset
*
* @param bool $showButtons Whether show submit and reset button
*
* @return string
*/
public static function displayFieldsetBottom($showButtons = true)
{
return Template::get('config/form_display/fieldset_bottom')->render([
'show_buttons' => $showButtons,
'is_setup' => $GLOBALS['PMA_Config']->get('is_setup'),
]);
}
/**
* Closes form tabs
*
* @return string
*/
public static function displayTabsBottom()
{
return Template::get('config/form_display/tabs_bottom')->render();
}
/**
* Displays bottom part of the form
*
* @return string
*/
public static function displayFormBottom()
{
return Template::get('config/form_display/form_bottom')->render();
}
/**
* Appends JS validation code to $js_array
*
* @param string $field_id ID of field to validate
* @param string|array $validators validators callback
* @param array &$js_array will be updated with javascript code
*
* @return void
*/
public static function addJsValidate($field_id, $validators, array &$js_array)
{
foreach ((array)$validators as $validator) {
$validator = (array)$validator;
$v_name = array_shift($validator);
$v_name = "PMA_" . $v_name;
$v_args = array();
foreach ($validator as $arg) {
$v_args[] = Sanitize::escapeJsString($arg);
}
$v_args = $v_args ? ", ['" . implode("', '", $v_args) . "']" : '';
$js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
}
}
/**
* Displays JavaScript code
*
* @param array $js_array lines of javascript code
*
* @return string
*/
public static function displayJavascript(array $js_array)
{
if (empty($js_array)) {
return null;
}
return Template::get('javascript/display')->render(
array('js_array' => $js_array,)
);
}
/**
* Displays error list
*
* @param string $name Name of item with errors
* @param array $errorList List of errors to show
*
* @return string HTML for errors
*/
public static function displayErrors($name, array $errorList)
{
return Template::get('config/form_display/errors')->render([
'name' => $name,
'error_list' => $errorList,
]);
}
}