added japanese language
[openemr.git] / phpmyadmin / libraries / config / FormDisplay.tpl.php
blobb355511f1c98de9b57c6329cf424065ebf7cf65a
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Form templates
6 * @package PhpMyAdmin
7 */
9 /**
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 * @return void
18 function PMA_displayFormTop($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') {
26 $method = 'get';
28 echo '<form method="' . $method . '" action="'
29 . htmlspecialchars($action) . '" class="config-form disableAjax">';
30 echo '<input type="hidden" name="tab_hash" value="" />';
31 // we do validation on page refresh when browser remembers field values,
32 // add a field with known value which will be used for checks
33 if (! $has_check_page_refresh) {
34 $has_check_page_refresh = true;
35 echo '<input type="hidden" name="check_page_refresh" '
36 . ' id="check_page_refresh" value="" />' . "\n";
38 echo PMA_URL_getHiddenInputs('', '', 0, 'server') . "\n";
39 echo PMA_getHiddenFields((array)$hidden_fields);
42 /**
43 * Displays form tabs which are given by an array indexed by fieldset id
44 * ({@link PMA_displayFieldsetTop}), with values being tab titles.
46 * @param array $tabs tab names
48 * @return void
50 function PMA_displayTabsTop($tabs)
52 echo '<ul class="tabs">';
53 foreach ($tabs as $tab_id => $tab_name) {
54 echo '<li><a href="#' . $tab_id . '">'
55 . htmlspecialchars($tab_name) . '</a></li>';
57 echo '</ul>';
58 echo '<br clear="right" />';
59 echo '<div class="tabs_contents">';
63 /**
64 * Displays top part of a fieldset
66 * @param string $title title of fieldset
67 * @param string $description description shown on top of fieldset
68 * @param array $errors error messages to display
69 * @param array $attributes optional extra attributes of fieldset
71 * @return void
73 function PMA_displayFieldsetTop($title = '', $description = '', $errors = null,
74 $attributes = array()
75 ) {
76 global $_FormDisplayGroup;
78 $_FormDisplayGroup = 0;
80 $attributes = array_merge(array('class' => 'optbox'), $attributes);
81 foreach ($attributes as $k => &$attr) {
82 $attr = $k . '="' . htmlspecialchars($attr) . '"';
85 echo '<fieldset ' . implode(' ', $attributes) . '>';
86 echo '<legend>' . $title . '</legend>';
87 if (!empty($description)) {
88 echo '<p>' . $description . '</p>';
90 // this must match with displayErrors() in scripts.js
91 if (is_array($errors) && count($errors) > 0) {
92 echo '<dl class="errors">';
93 foreach ($errors as $error) {
94 echo '<dd>' . $error . '</dd>';
96 echo '</dl>';
98 echo '<table width="100%" cellspacing="0">';
102 * Displays input field
104 * $opts keys:
105 * o doc - (string) documentation link
106 * o errors - error array
107 * o setvalue - (string) shows button allowing to set poredefined value
108 * o show_restore_default - (boolean) whether show "restore default" button
109 * o userprefs_allow - whether user preferences are enabled for this field
110 * (null - no support, true/false - enabled/disabled)
111 * o userprefs_comment - (string) field comment
112 * o values - key - value paris for <select> fields
113 * o values_escaped - (boolean) tells whether values array is already escaped
114 * (defaults to false)
115 * o values_disabled - (array)list of disabled values (keys from values)
116 * o comment - (string) tooltip comment
117 * o comment_warning - (bool) whether this comments warns about something
119 * @param string $path config option path
120 * @param string $name config option name
121 * @param string $type type of config option
122 * @param mixed $value current value
123 * @param string $description verbose description
124 * @param bool $value_is_default whether value is default
125 * @param array $opts see above description
127 * @return void
129 function PMA_displayInput($path, $name, $type, $value, $description = '',
130 $value_is_default = true, $opts = null
132 global $_FormDisplayGroup;
133 static $icons; // An array of IMG tags used further below in the function
135 if (defined('TESTSUITE')) {
136 $icons = null;
139 $is_setup_script = defined('PMA_SETUP');
140 if ($icons === null) { // if the static variables have not been initialised
141 $icons = array();
142 // Icon definitions:
143 // The same indexes will be used in the $icons array.
144 // The first element contains the filename and the second
145 // element is used for the "alt" and "title" attributes.
146 $icon_init = array(
147 'edit' => array('b_edit.png', ''),
148 'help' => array('b_help.png', __('Documentation')),
149 'reload' => array('s_reload.png', ''),
150 'tblops' => array('b_tblops.png', '')
152 if ($is_setup_script) {
153 // When called from the setup script, we don't have access to the
154 // sprite-aware getImage() function because the PMA_theme class
155 // has not been loaded, so we generate the img tags manually.
156 foreach ($icon_init as $k => $v) {
157 $title = '';
158 if (! empty($v[1])) {
159 $title = ' title="' . $v[1] . '"';
161 $icons[$k] = sprintf(
162 '<img alt="%s" src="%s"%s />',
163 $v[1],
164 ".{$GLOBALS['cfg']['ThemePath']}/original/img/{$v[0]}",
165 $title
168 } else {
169 // In this case we just use getImage() because it's available
170 foreach ($icon_init as $k => $v) {
171 $icons[$k] = PMA_Util::getImage(
172 $v[0], $v[1]
177 $has_errors = isset($opts['errors']) && !empty($opts['errors']);
178 $option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
179 && ! $opts['userprefs_allow'];
180 $name_id = 'name="' . htmlspecialchars($path) . '" id="'
181 . htmlspecialchars($path) . '"';
182 $field_class = $type == 'checkbox' ? 'checkbox' : '';
183 if (! $value_is_default) {
184 $field_class .= ($field_class == '' ? '' : ' ')
185 . ($has_errors ? 'custom field-error' : 'custom');
187 $field_class = $field_class ? ' class="' . $field_class . '"' : '';
188 $tr_class = $_FormDisplayGroup > 0
189 ? 'group-field group-field-' . $_FormDisplayGroup
190 : '';
191 if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
192 unset($opts['setvalue']);
193 $_FormDisplayGroup++;
194 $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
196 if ($option_is_disabled) {
197 $tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
199 $tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
201 echo '<tr' . $tr_class . '>';
202 echo '<th>';
203 echo '<label for="' . htmlspecialchars($path) . '">' . $name . '</label>';
205 if (! empty($opts['doc'])) {
206 echo '<span class="doc">';
207 echo '<a href="' . $opts['doc']
208 . '" target="documentation">' . $icons['help'] . '</a>';
209 echo "\n";
210 echo '</span>';
213 if ($option_is_disabled) {
214 echo '<span class="disabled-notice" title="';
215 echo __(
216 'This setting is disabled, it will not be applied to your configuration.'
218 echo '">' . __('Disabled') . "</span>";
221 if (!empty($description)) {
222 echo '<small>' . $description . '</small>';
225 echo '</th>';
226 echo '<td>';
228 switch ($type) {
229 case 'text':
230 echo '<input type="text" size="60" ' . $name_id . $field_class
231 . ' value="' . htmlspecialchars($value) . '" />';
232 break;
233 case 'password':
234 echo '<input type="password" size="60" ' . $name_id . $field_class
235 . ' value="' . htmlspecialchars($value) . '" />';
236 break;
237 case 'short_text':
238 echo '<input type="text" size="25" ' . $name_id . $field_class
239 . ' value="' . htmlspecialchars($value) . '" />';
240 break;
241 case 'number_text':
242 echo '<input type="number" ' . $name_id . $field_class
243 . ' value="' . htmlspecialchars($value) . '" />';
244 break;
245 case 'checkbox':
246 echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
247 . ($value ? ' checked="checked"' : '') . ' /></span>';
248 break;
249 case 'select':
250 echo '<select ' . $name_id . $field_class . '>';
251 $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
252 $values_disabled = isset($opts['values_disabled'])
253 ? array_flip($opts['values_disabled']) : array();
254 foreach ($opts['values'] as $opt_value_key => $opt_value) {
255 // set names for boolean values
256 if (is_bool($opt_value)) {
257 $opt_value = strtolower($opt_value ? __('Yes') : __('No'));
259 // escape if necessary
260 if ($escape) {
261 $display = htmlspecialchars($opt_value);
262 $display_value = htmlspecialchars($opt_value_key);
263 } else {
264 $display = $opt_value;
265 $display_value = $opt_value_key;
267 // compare with selected value
268 // boolean values are cast to integers when used as array keys
269 $selected = is_bool($value)
270 ? (int) $value === $opt_value_key
271 : $opt_value_key === $value;
272 echo '<option value="' . $display_value . '"';
273 if ($selected) {
274 echo ' selected="selected"';
276 if (isset($values_disabled[$opt_value_key])) {
277 echo ' disabled="disabled"';
279 echo '>' . $display . '</option>';
281 echo '</select>';
282 break;
283 case 'list':
284 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
285 . htmlspecialchars(implode("\n", $value))
286 . '</textarea>';
287 break;
289 if (isset($opts['comment']) && $opts['comment']) {
290 $class = 'field-comment-mark';
291 if (isset($opts['comment_warning']) && $opts['comment_warning']) {
292 $class .= ' field-comment-warning';
294 echo '<span class="' . $class . '" title="'
295 . htmlspecialchars($opts['comment']) . '">i</span>';
297 if ($is_setup_script
298 && isset($opts['userprefs_comment'])
299 && $opts['userprefs_comment']
301 echo '<a class="userprefs-comment" title="'
302 . htmlspecialchars($opts['userprefs_comment']) . '">'
303 . $icons['tblops'] . '</a>';
305 if (isset($opts['setvalue']) && $opts['setvalue']) {
306 echo '<a class="set-value" href="#'
307 . htmlspecialchars("$path={$opts['setvalue']}") . '" title="'
308 . sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue']))
309 . '" style="display:none">' . $icons['edit'] . '</a>';
311 if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
312 echo '<a class="restore-default" href="#' . $path . '" title="'
313 . __('Restore default value') . '" style="display:none">'
314 . $icons['reload'] . '</a>';
316 // this must match with displayErrors() in scripts/config.js
317 if ($has_errors) {
318 echo "\n <dl class=\"inline_errors\">";
319 foreach ($opts['errors'] as $error) {
320 echo '<dd>' . htmlspecialchars($error) . '</dd>';
322 echo '</dl>';
324 echo '</td>';
325 if ($is_setup_script && isset($opts['userprefs_allow'])) {
326 echo '<td class="userprefs-allow" title="' .
327 __('Allow users to customize this value') . '">';
328 echo '<input type="checkbox" name="' . $path . '-userprefs-allow" ';
329 if ($opts['userprefs_allow']) {
330 echo 'checked="checked"';
332 echo '/>';
333 echo '</td>';
334 } else if ($is_setup_script) {
335 echo '<td>&nbsp;</td>';
337 echo '</tr>';
341 * Display group header
343 * @param string $header_text Text of header
345 * @return void
347 function PMA_displayGroupHeader($header_text)
349 global $_FormDisplayGroup;
351 $_FormDisplayGroup++;
352 if (! $header_text) {
353 return;
355 $colspan = defined('PMA_SETUP')
357 : 2;
358 echo '<tr class="group-header group-header-' . $_FormDisplayGroup . '">';
359 echo '<th colspan="' . $colspan . '">';
360 echo $header_text;
361 echo '</th>';
362 echo '</tr>';
366 * Display group footer
368 * @return void
370 function PMA_displayGroupFooter()
372 global $_FormDisplayGroup;
374 $_FormDisplayGroup--;
378 * Displays bottom part of a fieldset
380 * @return void
382 function PMA_displayFieldsetBottom()
384 $colspan = 2;
385 if (defined('PMA_SETUP')) {
386 $colspan++;
388 echo '<tr>';
389 echo '<td colspan="' . $colspan . '" class="lastrow">';
390 echo '<input type="submit" name="submit_save" value="'
391 . __('Apply') . '" class="green" />';
392 echo '<input type="button" name="submit_reset" value="'
393 . __('Reset') . '" />';
394 echo '</td>';
395 echo '</tr>';
396 echo '</table>';
397 echo '</fieldset>';
401 * Displays simple bottom part of a fieldset (without submit buttons)
403 * @return void
405 function PMA_displayFieldsetBottomSimple()
407 echo '</table>';
408 echo '</fieldset>';
412 * Closes form tabs
414 * @return void
416 function PMA_displayTabsBottom()
418 echo "</div>\n";
422 * Displays bottom part of the form
424 * @return void
426 function PMA_displayFormBottom()
428 echo "</form>\n";
432 * Appends JS validation code to $js_array
434 * @param string $field_id ID of field to validate
435 * @param string|array $validators validators callback
436 * @param array &$js_array will be updated with javascript code
438 * @return void
440 function PMA_addJsValidate($field_id, $validators, &$js_array)
442 foreach ((array)$validators as $validator) {
443 $validator = (array)$validator;
444 $v_name = array_shift($validator);
445 $v_name = "PMA_" . $v_name;
446 $v_args = array();
447 foreach ($validator as $arg) {
448 $v_args[] = PMA_escapeJsString($arg);
450 $v_args = $v_args ? ", ['" . implode("', '", $v_args) . "']" : '';
451 $js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
456 * Displays JavaScript code
458 * @param array $js_array lines of javascript code
460 * @return void
462 function PMA_displayJavascript($js_array)
464 if (empty($js_array)) {
465 return;
467 echo '<script type="text/javascript">' . "\n";
468 echo implode(";\n", $js_array) . ";\n";
469 echo '</script>' . "\n";
473 * Displays error list
475 * @param string $name name of item with errors
476 * @param array $error_list list of errors to show
478 * @return void
480 function PMA_displayErrors($name, $error_list)
482 echo '<dl>';
483 echo '<dt>' . htmlspecialchars($name) . '</dt>';
484 foreach ($error_list as $error) {
485 echo '<dd>' . htmlspecialchars($error) . '</dd>';
487 echo '</dl>';