2 /* vim: set expandtab sw=4 ts=4 sts=4: */
10 * Displays top part of the form
12 * @param string $action default: $_SERVER['REQUEST_URI']
13 * @param string $method 'post' or 'get'
14 * @param array $hidden_fields array of form hidden fields (key: field name)
16 function display_form_top($action = null, $method = 'post', $hidden_fields = null)
18 static $has_check_page_refresh = false;
20 if ($action === null) {
21 $action = $_SERVER['REQUEST_URI'];
23 if ($method != 'post') {
27 <form method
="<?php echo $method ?>" action
="<?php echo htmlspecialchars($action) ?>" class="config-form">
28 <input type
="hidden" name
="tab_hash" value
="" />
30 // we do validation on page refresh when browser remembers field values,
31 // add a field with known value which will be used for checks
32 if (!$has_check_page_refresh) {
33 $has_check_page_refresh = true;
34 echo '<input type="hidden" name="check_page_refresh" id="check_page_refresh"'
35 . ' value="" />' . "\n";
37 echo PMA_generate_common_hidden_inputs('', '', 0, 'server') . "\n";
38 echo PMA_getHiddenFields((array)$hidden_fields);
42 * Displays form tabs which are given by an array indexed by fieldset id
43 * ({@link display_fieldset_top}), with values being tab titles.
47 function display_tabs_top($tabs)
51 <?php
foreach ($tabs as $tab_id => $tab_name): ?
>
52 <li
><a href
="#<?php echo $tab_id ?>"><?php
echo $tab_name ?
></a
></li
>
56 <div
class="tabs_contents">
62 * Displays top part of a fieldset
64 * @param string $title
65 * @param string $description
66 * @param array $errors
67 * @param array $attributes
69 function display_fieldset_top($title = '', $description = '', $errors = null, $attributes = array())
71 global $_FormDisplayGroup;
73 $_FormDisplayGroup = 0;
75 $attributes = array_merge(array('class' => 'optbox'), $attributes);
76 foreach ($attributes as $k => &$attr) {
77 $attr = $k . '="' . htmlspecialchars($attr) . '"';
80 echo '<fieldset ' . implode(' ', $attributes) . '>';
81 echo '<legend>' . $title . '</legend>';
82 if (!empty($description)) {
83 echo '<p>' . $description . '</p>';
85 // this must match with displayErrors() in scripts.js
86 if (is_array($errors) && count($errors) > 0) {
87 echo '<dl class="errors">';
88 foreach ($errors as $error) {
89 echo '<dd>' . $error . '</dd>';
94 <table width
="100%" cellspacing
="0">
99 * Displays input field
102 * o doc - (string) documentation link
103 * o errors - error array
104 * o setvalue - (string) shows button allowing to set poredefined value
105 * o show_restore_default - (boolean) whether show "restore default" button
106 * o userprefs_allow - whether user preferences are enabled for this field (null - no support,
107 * true/false - enabled/disabled)
108 * o userprefs_comment - (string) field comment
109 * o values - key - value paris for <select> fields
110 * o values_escaped - (boolean) tells whether values array is already escaped (defaults to false)
111 * o values_disabled - (array)list of disabled values (keys from values)
112 * o comment - (string) tooltip comment
113 * o comment_warning - (bool) whether this comments warns about something
114 * o wiki - (string) wiki link
116 * @param string $path
117 * @param string $name
118 * @param string $description
119 * @param string $type
120 * @param mixed $value
121 * @param bool $value_is_default
124 function display_input($path, $name, $description = '', $type, $value, $value_is_default = true, $opts = null)
126 global $_FormDisplayGroup;
127 static $base_dir, $img_path;
129 $is_setup_script = defined('PMA_SETUP');
130 if ($base_dir === null) {
131 $base_dir = $is_setup_script ?
'../' : '';
132 $img_path = $is_setup_script
133 ?
'../' . ltrim($GLOBALS['cfg']['ThemePath'], './') . '/original/img/'
134 : $_SESSION['PMA_Theme']->img_path
;
136 $has_errors = isset($opts['errors']) && !empty($opts['errors']);
137 $option_is_disabled = !$is_setup_script && isset($opts['userprefs_allow']) && !$opts['userprefs_allow'];
138 $name_id = 'name="' . htmlspecialchars($path) . '" id="' . htmlspecialchars($path) . '"';
139 $field_class = $type == 'checkbox' ?
'checkbox' : '';
140 if (!$value_is_default) {
141 $field_class .= ($field_class == '' ?
'' : ' ') . ($has_errors ?
'custom field-error' : 'custom');
143 $field_class = $field_class ?
' class="' . $field_class . '"' : '';
144 $tr_class = $_FormDisplayGroup > 0
145 ?
'group-field group-field-' . $_FormDisplayGroup
147 if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
148 unset($opts['setvalue']);
149 $_FormDisplayGroup++
;
150 $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
152 if ($option_is_disabled) {
153 $tr_class .= ($tr_class ?
' ' : '') . 'disabled-field';
155 $tr_class = $tr_class ?
' class="' . $tr_class . '"' : '';
157 <tr
<?php
echo $tr_class ?
>>
159 <label
for="<?php echo htmlspecialchars($path) ?>"><?php
echo $name ?
></label
>
160 <?php
if (!empty($opts['doc']) ||
!empty($opts['wiki'])) { ?
>
162 <?php
if (!empty($opts['doc'])) { ?
><a href
="<?php echo $base_dir . $opts['doc'] ?>" target
="documentation"><img
class="icon ic_b_help_s" src
="<?php echo $base_dir; ?>themes/dot.gif" alt
="Doc" title
="<?php echo __('Documentation') ?>" /></a
><?php
} ?
>
163 <?php
if (!empty($opts['wiki'])){ ?
><a href
="<?php echo $opts['wiki'] ?>" target
="wiki"><img
class="icon ic_b_info" src
="<?php echo $base_dir; ?>themes/dot.gif" alt
="Wiki" title
="Wiki" /></a
><?php
} ?
>
166 <?php
if ($option_is_disabled) { ?
>
167 <span
class="disabled-notice" title
="<?php echo __('This setting is disabled, it will not be applied to your configuration') ?>"><?php
echo __('Disabled') ?
></span
>
169 <?php
if (!empty($description)) { ?
><small
><?php
echo $description ?
></small
><?php
} ?
>
175 echo '<input type="text" size="60" ' . $name_id . $field_class
176 . ' value="' . htmlspecialchars($value) . '" />';
179 echo '<input type="text" size="25" ' . $name_id . $field_class
180 . ' value="' . htmlspecialchars($value) . '" />';
183 echo '<input type="text" size="15" ' . $name_id . $field_class
184 . ' value="' . htmlspecialchars($value) . '" />';
187 echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
188 . ($value ?
' checked="checked"' : '') . ' /></span>';
191 echo '<select ' . $name_id . $field_class . '>';
192 $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
193 $values_disabled = isset($opts['values_disabled'])
194 ?
array_flip($opts['values_disabled']) : array();
195 foreach ($opts['values'] as $opt_value_key => $opt_value) {
196 // set names for boolean values
197 if (is_bool($opt_value)) {
198 $opt_value = strtolower($opt_value ?
__('Yes') : __('No'));
200 // escape if necessary
202 $display = htmlspecialchars($opt_value);
203 $display_value = htmlspecialchars($opt_value_key);
205 $display = $opt_value;
206 $display_value = $opt_value_key;
208 // compare with selected value
209 // boolean values are cast to integers when used as array keys
210 $selected = is_bool($value)
211 ?
(int) $value === $opt_value_key
212 : $opt_value_key === $value;
213 echo '<option value="' . $display_value . '"'
214 . ($selected ?
' selected="selected"' : '')
215 . (isset($values_disabled[$opt_value_key]) ?
' disabled="disabled"' : '')
216 . '>' . $display . '</option>';
221 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
222 . htmlspecialchars(implode("\n", $value))
226 if (isset($opts['comment']) && $opts['comment']) {
227 $class = 'field-comment-mark';
228 if (isset($opts['comment_warning']) && $opts['comment_warning']) {
229 $class .= ' field-comment-warning';
232 <span
class="<?php echo $class ?>" title
="<?php echo htmlspecialchars($opts['comment']) ?>">i
</span
>
235 if ($is_setup_script && isset($opts['userprefs_comment']) && $opts['userprefs_comment']) {
237 <a
class="userprefs-comment" title
="<?php echo htmlspecialchars($opts['userprefs_comment']) ?>"><img alt
="comment" class="icon ic_b_tblops" src
="<?php echo $base_dir; ?>themes/dot.gif" /></a
>
240 if (isset($opts['setvalue']) && $opts['setvalue']) {
242 <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" class="icon ic_b_edit" src
="<?php echo $base_dir; ?>themes/dot.gif" /></a
>
245 if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
247 <a
class="restore-default" href
="#<?php echo $path ?>" title
="<?php echo __('Restore default value') ?>" style
="display:none"><img alt
="restore-default" class="icon ic_s_reload" src
="<?php echo $base_dir; ?>themes/dot.gif" /></a
>
250 // this must match with displayErrors() in scripts/config.js
252 echo "\n <dl class=\"inline_errors\">";
253 foreach ($opts['errors'] as $error) {
254 echo '<dd>' . htmlspecialchars($error) . '</dd>';
261 if ($is_setup_script && isset($opts['userprefs_allow'])) {
263 <td
class="userprefs-allow" title
="<?php echo __('Allow users to customize this value') ?>">
264 <input type
="checkbox" name
="<?php echo $path ?>-userprefs-allow" <?php
if ($opts['userprefs_allow']) echo 'checked="checked"' ?
> />
267 } else if ($is_setup_script) {
268 echo '<td> </td>';
276 * Display group header
278 * @param string $header_text
280 function display_group_header($header_text)
282 global $_FormDisplayGroup;
284 $_FormDisplayGroup++
;
288 $colspan = defined('PMA_SETUP')
292 <tr
class="group-header group-header-<?php echo $_FormDisplayGroup ?>">
293 <th colspan
="<?php echo $colspan ?>">
294 <?php
echo $header_text ?
>
301 * Display group footer
304 function display_group_footer()
306 global $_FormDisplayGroup;
308 $_FormDisplayGroup--;
312 * Displays bottom part of a fieldset
314 function display_fieldset_bottom()
317 if (defined('PMA_SETUP')) {
322 <td colspan
="<?php echo $colspan ?>" class="lastrow">
323 <input type
="submit" name
="submit_save" value
="<?php echo __('Save') ?>" class="green" />
324 <input type
="button" name
="submit_reset" value
="<?php echo __('Reset') ?>" />
334 * Displays simple bottom part of a fieldset (without submit buttons)
336 function display_fieldset_bottom_simple()
348 function display_tabs_bottom()
354 * Displays bottom part of the form
356 function display_form_bottom()
362 * Appends JS validation code to $js_array
364 * @param string $field_id
365 * @param string|array $validator
366 * @param array $js_array
368 function js_validate($field_id, $validators, &$js_array)
370 foreach ((array)$validators as $validator) {
371 $validator = (array)$validator;
372 $v_name = array_shift($validator);
374 foreach ($validator as $arg) {
375 $v_args[] = PMA_escapeJsString($arg);
377 $v_args = $v_args ?
", ['" . implode("', '", $v_args) . "']" : '';
378 $js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
383 * Displays JavaScript code
385 * @param array $js_array
387 function display_js($js_array)
389 if (empty($js_array)) {
393 <script type
="text/javascript">
394 <?php
echo implode(";\n", $js_array) . ";\n" ?
>
400 * Displays error list
402 * @param string $name
403 * @param array $error_list
405 function display_errors($name, $error_list)
408 echo '<dt>' . htmlspecialchars($name) . '</dt>';
409 foreach ($error_list as $error) {
410 echo '<dd>' . htmlspecialchars($error) . '</dd>';