2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 * Displays top part of the form
12 * @uses PMA_generate_common_hidden_inputs()
13 * @uses PMA_getHiddenFields()
14 * @param string $action default: $_SERVER['REQUEST_URI']
15 * @param string $method 'post' or 'get'
16 * @param array $hidden_fields array of form hidden fields (key: field name)
18 function display_form_top($action = null, $method = 'post', $hidden_fields = null)
20 static $has_check_page_refresh = false;
22 if ($action === null) {
23 $action = $_SERVER['REQUEST_URI'];
25 if ($method != 'post') {
29 <form method
="<?php echo $method ?>" action
="<?php echo htmlspecialchars($action) ?>" class="config-form">
30 <input type
="hidden" name
="tab_hash" value
="" />
32 // we do validation on page refresh when browser remembers field values,
33 // add a field with known value which will be used for checks
34 if (!$has_check_page_refresh) {
35 $has_check_page_refresh = true;
36 echo '<input type="hidden" name="check_page_refresh" id="check_page_refresh"'
37 . ' value="" />' . "\n";
39 echo PMA_generate_common_hidden_inputs('', '', 0, 'server') . "\n";
40 echo PMA_getHiddenFields((array)$hidden_fields);
44 * Displays form tabs which are given by an array indexed by fieldset id
45 * ({@link display_fieldset_top}), with values being tab titles.
49 function display_tabs_top($tabs)
53 <?php
foreach ($tabs as $tab_id => $tab_name): ?
>
54 <li
><a href
="#<?php echo $tab_id ?>"><?php
echo $tab_name ?
></a
></li
>
58 <div
class="tabs_contents">
64 * Displays top part of a fieldset
66 * @param string $title
67 * @param string $description
68 * @param array $errors
69 * @param array $attributes
71 function display_fieldset_top($title = '', $description = '', $errors = null, $attributes = array())
73 global $_FormDisplayGroup;
75 $_FormDisplayGroup = 0;
77 $attributes = array_merge(array('class' => 'optbox'), $attributes);
78 foreach ($attributes as $k => &$attr) {
79 $attr = $k . '="' . htmlspecialchars($attr) . '"';
82 echo '<fieldset ' . implode(' ', $attributes) . '>';
83 echo '<legend>' . $title . '</legend>';
84 if (!empty($description)) {
85 echo '<p>' . $description . '</p>';
87 // this must match with displayErrors() in scripts.js
88 if (is_array($errors) && count($errors) > 0) {
89 echo '<dl class="errors">';
90 foreach ($errors as $error) {
91 echo '<dd>' . $error . '</dd>';
96 <table width
="100%" cellspacing
="0">
101 * Displays input field
104 * o doc - (string) documentation link
105 * o errors - error array
106 * o setvalue - (string) shows button allowing to set poredefined value
107 * o show_restore_default - (boolean) whether show "restore default" button
108 * o userprefs_allow - whether user preferences are enabled for this field (null - no support,
109 * true/false - enabled/disabled)
110 * o userprefs_comment - (string) field comment
111 * o values - key - value paris for <select> fields
112 * o values_escaped - (boolean) tells whether values array is already escaped (defaults to false)
113 * o values_disabled - (array)list of disabled values (keys from values)
114 * o comment - (string) tooltip comment
115 * o comment_warning - (bool) whether this comments warns about something
116 * o wiki - (string) wiki link
118 * @uses $GLOBALS['_FormDisplayGroup']
119 * @uses $GLOBALS['cfg']['ThemePath']
120 * @uses $_SESSION['PMA_Theme']
121 * @uses display_group_footer()
122 * @param string $path
123 * @param string $name
124 * @param string $description
125 * @param string $type
126 * @param mixed $value
127 * @param bool $value_is_default
130 function display_input($path, $name, $description = '', $type, $value, $value_is_default = true, $opts = null)
132 global $_FormDisplayGroup;
133 static $base_dir, $img_path;
135 $is_setup_script = defined('PMA_SETUP');
136 if ($base_dir === null) {
137 $base_dir = $is_setup_script ?
'../' : '';
138 $img_path = $is_setup_script
139 ?
'../' . ltrim($GLOBALS['cfg']['ThemePath'], './') . '/original/img/'
140 : $_SESSION['PMA_Theme']->img_path
;
142 $has_errors = isset($opts['errors']) && !empty($opts['errors']);
143 $option_is_disabled = !$is_setup_script && isset($opts['userprefs_allow']) && !$opts['userprefs_allow'];
144 $name_id = 'name="' . htmlspecialchars($path) . '" id="' . htmlspecialchars($path) . '"';
145 $field_class = $type == 'checkbox' ?
'checkbox' : '';
146 if (!$value_is_default) {
147 $field_class .= ($field_class == '' ?
'' : ' ') . ($has_errors ?
'custom field-error' : 'custom');
149 $field_class = $field_class ?
' class="' . $field_class . '"' : '';
150 $tr_class = $_FormDisplayGroup > 0
151 ?
'group-field group-field-' . $_FormDisplayGroup
153 if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
154 unset($opts['setvalue']);
155 $_FormDisplayGroup++
;
156 $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
158 if ($option_is_disabled) {
159 $tr_class .= ($tr_class ?
' ' : '') . 'disabled-field';
161 $tr_class = $tr_class ?
' class="' . $tr_class . '"' : '';
163 <tr
<?php
echo $tr_class ?
>>
165 <label
for="<?php echo htmlspecialchars($path) ?>"><?php
echo $name ?
></label
>
166 <?php
if (!empty($opts['doc']) ||
!empty($opts['wiki'])) { ?
>
168 <?php
if (!empty($opts['doc'])) { ?
><a href
="<?php echo $base_dir . $opts['doc'] ?>" target
="documentation"><img
class="icon" src
="<?php echo $img_path ?>b_help.png" width
="11" height
="11" alt
="Doc" title
="<?php echo __('Documentation') ?>" /></a
><?php
} ?
>
169 <?php
if (!empty($opts['wiki'])){ ?
><a href
="<?php echo $opts['wiki'] ?>" target
="wiki"><img
class="icon" src
="<?php echo $img_path ?>b_info.png" width
="11" height
="11" alt
="Wiki" title
="Wiki" /></a
><?php
} ?
>
172 <?php
if ($option_is_disabled) { ?
>
173 <span
class="disabled-notice" title
="<?php echo __('This setting is disabled, it will not be applied to your configuration') ?>"><?php
echo __('Disabled') ?
></span
>
175 <?php
if (!empty($description)) { ?
><small
><?php
echo $description ?
></small
><?php
} ?
>
181 echo '<input type="text" size="60" ' . $name_id . $field_class
182 . ' value="' . htmlspecialchars($value) . '" />';
185 echo '<input type="text" size="25" ' . $name_id . $field_class
186 . ' value="' . htmlspecialchars($value) . '" />';
189 echo '<input type="text" size="15" ' . $name_id . $field_class
190 . ' value="' . htmlspecialchars($value) . '" />';
193 echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
194 . ($value ?
' checked="checked"' : '') . ' /></span>';
197 echo '<select ' . $name_id . $field_class . '>';
198 $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
199 $values_disabled = isset($opts['values_disabled'])
200 ?
array_flip($opts['values_disabled']) : array();
201 foreach ($opts['values'] as $opt_value_key => $opt_value) {
202 // set names for boolean values
203 if (is_bool($opt_value)) {
204 $opt_value = strtolower($opt_value ?
__('Yes') : __('No'));
206 // escape if necessary
208 $display = htmlspecialchars($opt_value);
209 $display_value = htmlspecialchars($opt_value_key);
211 $display = $opt_value;
212 $display_value = $opt_value_key;
214 // compare with selected value
215 // boolean values are cast to integers when used as array keys
216 $selected = is_bool($value)
217 ?
(int) $value === $opt_value_key
218 : $opt_value_key === $value;
219 echo '<option value="' . $display_value . '"'
220 . ($selected ?
' selected="selected"' : '')
221 . (isset($values_disabled[$opt_value_key]) ?
' disabled="disabled"' : '')
222 . '>' . $display . '</option>';
227 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
228 . htmlspecialchars(implode("\n", $value))
232 if (isset($opts['comment']) && $opts['comment']) {
233 $class = 'field-comment-mark';
234 if (isset($opts['comment_warning']) && $opts['comment_warning']) {
235 $class .= ' field-comment-warning';
238 <span
class="<?php echo $class ?>" title
="<?php echo htmlspecialchars($opts['comment']) ?>">i
</span
>
241 if ($is_setup_script && isset($opts['userprefs_comment']) && $opts['userprefs_comment']) {
243 <a
class="userprefs-comment" title
="<?php echo htmlspecialchars($opts['userprefs_comment']) ?>"><img alt
="comment" src
="<?php echo $img_path ?>b_tblops.png" width
="16" height
="16" /></a
>
246 if (isset($opts['setvalue']) && $opts['setvalue']) {
248 <a
class="set-value" href
="#<?php echo htmlspecialchars("$path={$opts['setvalue']}") ?>" title
="<?php echo sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue'])) ?>" style
="display:none"><img alt
="set-value" src
="<?php echo $img_path ?>b_edit.png" width
="16" height
="16" /></a
>
251 if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
253 <a
class="restore-default" href
="#<?php echo $path ?>" title
="<?php echo __('Restore default value') ?>" style
="display:none"><img alt
="restore-default" src
="<?php echo $img_path ?>s_reload.png" width
="16" height
="16" /></a
>
256 // this must match with displayErrors() in scripts/config.js
258 echo "\n <dl class=\"inline_errors\">";
259 foreach ($opts['errors'] as $error) {
260 echo '<dd>' . htmlspecialchars($error) . '</dd>';
267 if ($is_setup_script && isset($opts['userprefs_allow'])) {
269 <td
class="userprefs-allow" title
="<?php echo __('Allow users to customize this value') ?>">
270 <input type
="checkbox" name
="<?php echo $path ?>-userprefs-allow" <?php
if ($opts['userprefs_allow']) echo 'checked="checked"' ?
> />
273 } else if ($is_setup_script) {
274 echo '<td> </td>';
282 * Display group header
284 * @uses $GLOBALS['_FormDisplayGroup']
285 * @uses display_group_footer()
286 * @param string $header_text
288 function display_group_header($header_text)
290 global $_FormDisplayGroup;
292 $_FormDisplayGroup++
;
296 $colspan = defined('PMA_SETUP')
300 <tr
class="group-header group-header-<?php echo $_FormDisplayGroup ?>">
301 <th colspan
="<?php echo $colspan ?>">
302 <?php
echo $header_text ?
>
309 * Display group footer
311 * @uses $GLOBALS['_FormDisplayGroup']
313 function display_group_footer()
315 global $_FormDisplayGroup;
317 $_FormDisplayGroup--;
321 * Displays bottom part of a fieldset
323 function display_fieldset_bottom()
326 if (defined('PMA_SETUP')) {
331 <td colspan
="<?php echo $colspan ?>" class="lastrow">
332 <input type
="submit" name
="submit_save" value
="<?php echo __('Save') ?>" class="green" />
333 <input type
="button" name
="submit_reset" value
="<?php echo __('Reset') ?>" />
343 * Displays simple bottom part of a fieldset (without submit buttons)
345 function display_fieldset_bottom_simple()
357 function display_tabs_bottom()
363 * Displays bottom part of the form
365 function display_form_bottom()
371 * Appends JS validation code to $js_array
373 * @uses PMA_escapeJsString()
374 * @param string $field_id
375 * @param string|array $validator
376 * @param array $js_array
378 function js_validate($field_id, $validators, &$js_array)
380 foreach ((array)$validators as $validator) {
381 $validator = (array)$validator;
382 $v_name = array_shift($validator);
384 foreach ($validator as $arg) {
385 $v_args[] = PMA_escapeJsString($arg);
387 $v_args = $v_args ?
", ['" . implode("', '", $v_args) . "']" : '';
388 $js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
393 * Displays JavaScript code
395 * @param array $js_array
397 function display_js($js_array)
399 if (empty($js_array)) {
403 <script type
="text/javascript">
404 <?php
echo implode(";\n", $js_array) . ";\n" ?
>
410 * Displays error list
412 * @param string $name
413 * @param array $error_list
415 function display_errors($name, $error_list)
418 echo '<dt>' . htmlspecialchars($name) . '</dt>';
419 foreach ($error_list as $error) {
420 echo '<dd>' . htmlspecialchars($error) . '</dd>';