Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / config / FormDisplay.tpl.php
blob677e3f4c3602cca00c49486e0446d6906ee9ed2c
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_generate_common_hidden_inputs('', '', 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
118 * o wiki - (string) wiki link
120 * @param string $path config option path
121 * @param string $name config option name
122 * @param string $type type of config option
123 * @param mixed $value current value
124 * @param string $description verbose description
125 * @param bool $value_is_default whether value is default
126 * @param array $opts see above description
128 * @return void
130 function PMA_displayInput($path, $name, $type, $value, $description = '',
131 $value_is_default = true, $opts = null
133 global $_FormDisplayGroup;
134 static $icons; // An array of IMG tags used further below in the function
136 $is_setup_script = defined('PMA_SETUP');
137 if ($icons === null) { // if the static variables have not been initialised
138 $icons = array();
139 // Icon definitions:
140 // The same indexes will be used in the $icons array.
141 // The first element contains the filename and the second
142 // element is used for the "alt" and "title" attributes.
143 $icon_init = array(
144 'edit' => array('b_edit.png', ''),
145 'help' => array('b_help.png', __('Documentation')),
146 'info' => array('b_info.png', __('Wiki')),
147 'reload' => array('s_reload.png', ''),
148 'tblops' => array('b_tblops.png', '')
150 if ($is_setup_script) {
151 // When called from the setup script, we don't have access to the
152 // sprite-aware getImage() function because the PMA_theme class
153 // has not been loaded, so we generate the img tags manually.
154 foreach ($icon_init as $k => $v) {
155 $title = '';
156 if (! empty($v[1])) {
157 $title = ' title="' . $v[1] . '"';
159 $icons[$k] = sprintf(
160 '<img alt="%s" src="%s"%s />',
161 $v[1],
162 ".{$GLOBALS['cfg']['ThemePath']}/original/img/{$v[0]}",
163 $title
166 } else {
167 // In this case we just use getImage() because it's available
168 foreach ($icon_init as $k => $v) {
169 $icons[$k] = PMA_Util::getImage(
170 $v[0], $v[1]
175 $has_errors = isset($opts['errors']) && !empty($opts['errors']);
176 $option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
177 && ! $opts['userprefs_allow'];
178 $name_id = 'name="' . htmlspecialchars($path) . '" id="'
179 . htmlspecialchars($path) . '"';
180 $field_class = $type == 'checkbox' ? 'checkbox' : '';
181 if (! $value_is_default) {
182 $field_class .= ($field_class == '' ? '' : ' ')
183 . ($has_errors ? 'custom field-error' : 'custom');
185 $field_class = $field_class ? ' class="' . $field_class . '"' : '';
186 $tr_class = $_FormDisplayGroup > 0
187 ? 'group-field group-field-' . $_FormDisplayGroup
188 : '';
189 if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
190 unset($opts['setvalue']);
191 $_FormDisplayGroup++;
192 $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
194 if ($option_is_disabled) {
195 $tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
197 $tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
199 echo '<tr' . $tr_class . '>';
200 echo '<th>';
201 echo '<label for="' . htmlspecialchars($path) . '">' . $name . '</label>';
203 if (! empty($opts['doc']) || ! empty($opts['wiki'])) {
204 echo '<span class="doc">';
205 if (! empty($opts['doc'])) {
206 echo '<a href="' . $opts['doc']
207 . '" target="documentation">' . $icons['help'] . '</a>';
208 echo "\n";
210 if (! empty($opts['wiki'])) {
211 echo '<a href="' . $opts['wiki']
212 . '" target="wiki">' . $icons['info'] . '</a>';
213 echo "\n";
215 echo '</span>';
218 if ($option_is_disabled) {
219 echo '<span class="disabled-notice" title="';
220 echo __(
221 'This setting is disabled, it will not be applied to your configuration'
223 echo '">' . __('Disabled') . "</span>";
226 if (!empty($description)) {
227 echo '<small>' . $description . '</small>';
230 echo '</th>';
231 echo '<td>';
233 switch ($type) {
234 case 'text':
235 echo '<input type="text" size="60" ' . $name_id . $field_class
236 . ' value="' . htmlspecialchars($value) . '" />';
237 break;
238 case 'short_text':
239 echo '<input type="text" size="25" ' . $name_id . $field_class
240 . ' value="' . htmlspecialchars($value) . '" />';
241 break;
242 case 'number_text':
243 echo '<input type="text" size="15" ' . $name_id . $field_class
244 . ' value="' . htmlspecialchars($value) . '" />';
245 break;
246 case 'checkbox':
247 echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
248 . ($value ? ' checked="checked"' : '') . ' /></span>';
249 break;
250 case 'select':
251 echo '<select ' . $name_id . $field_class . '>';
252 $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
253 $values_disabled = isset($opts['values_disabled'])
254 ? array_flip($opts['values_disabled']) : array();
255 foreach ($opts['values'] as $opt_value_key => $opt_value) {
256 // set names for boolean values
257 if (is_bool($opt_value)) {
258 $opt_value = strtolower($opt_value ? __('Yes') : __('No'));
260 // escape if necessary
261 if ($escape) {
262 $display = htmlspecialchars($opt_value);
263 $display_value = htmlspecialchars($opt_value_key);
264 } else {
265 $display = $opt_value;
266 $display_value = $opt_value_key;
268 // compare with selected value
269 // boolean values are cast to integers when used as array keys
270 $selected = is_bool($value)
271 ? (int) $value === $opt_value_key
272 : $opt_value_key === $value;
273 echo '<option value="' . $display_value . '"';
274 if ($selected) {
275 echo ' selected="selected"';
277 if (isset($values_disabled[$opt_value_key])) {
278 echo ' disabled="disabled"';
280 echo '>' . $display . '</option>';
282 echo '</select>';
283 break;
284 case 'list':
285 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
286 . htmlspecialchars(implode("\n", $value))
287 . '</textarea>';
288 break;
290 if (isset($opts['comment']) && $opts['comment']) {
291 $class = 'field-comment-mark';
292 if (isset($opts['comment_warning']) && $opts['comment_warning']) {
293 $class .= ' field-comment-warning';
295 echo '<span class="' . $class . '" title="'
296 . htmlspecialchars($opts['comment']) . '">i</span>';
298 if ($is_setup_script
299 && isset($opts['userprefs_comment'])
300 && $opts['userprefs_comment']
302 echo '<a class="userprefs-comment" title="'
303 . htmlspecialchars($opts['userprefs_comment']) . '">'
304 . $icons['tblops'] . '</a>';
306 if (isset($opts['setvalue']) && $opts['setvalue']) {
307 echo '<a class="set-value" href="#'
308 . htmlspecialchars("$path={$opts['setvalue']}") . '" title="'
309 . sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue']))
310 . '" style="display:none">' . $icons['edit'] . '</a>';
312 if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
313 echo '<a class="restore-default" href="#' . $path . '" title="'
314 . __('Restore default value') . '" style="display:none">'
315 . $icons['reload'] . '</a>';
317 // this must match with displayErrors() in scripts/config.js
318 if ($has_errors) {
319 echo "\n <dl class=\"inline_errors\">";
320 foreach ($opts['errors'] as $error) {
321 echo '<dd>' . htmlspecialchars($error) . '</dd>';
323 echo '</dl>';
325 echo '</td>';
326 if ($is_setup_script && isset($opts['userprefs_allow'])) {
327 echo '<td class="userprefs-allow" title="' .
328 __('Allow users to customize this value') . '">';
329 echo '<input type="checkbox" name="' . $path . '-userprefs-allow" ';
330 if ($opts['userprefs_allow']) {
331 echo 'checked="checked"';
333 echo '/>';
334 echo '</td>';
335 } else if ($is_setup_script) {
336 echo '<td>&nbsp;</td>';
338 echo '</tr>';
342 * Display group header
344 * @param string $header_text Text of header
346 * @return void
348 function PMA_displayGroupHeader($header_text)
350 global $_FormDisplayGroup;
352 $_FormDisplayGroup++;
353 if (!$header_text) {
354 return;
356 $colspan = defined('PMA_SETUP')
358 : 2;
359 echo '<tr class="group-header group-header-' . $_FormDisplayGroup . '">';
360 echo '<th colspan="' . $colspan . '">';
361 echo $header_text;
362 echo '</th>';
363 echo '</tr>';
367 * Display group footer
369 * @return void
371 function PMA_displayGroupFooter()
373 global $_FormDisplayGroup;
375 $_FormDisplayGroup--;
379 * Displays bottom part of a fieldset
381 * @return void
383 function PMA_displayFieldsetBottom()
385 $colspan = 2;
386 if (defined('PMA_SETUP')) {
387 $colspan++;
389 echo '<tr>';
390 echo '<td colspan="' . $colspan . '" class="lastrow">';
391 echo '<input type="submit" name="submit_save" value="'
392 . __('Save') . '" class="green" />';
393 echo '<input type="button" name="submit_reset" value="'
394 . __('Reset') . '" />';
395 echo '</td>';
396 echo '</tr>';
397 echo '</table>';
398 echo '</fieldset>';
402 * Displays simple bottom part of a fieldset (without submit buttons)
404 * @return void
406 function PMA_displayFieldsetBottomSimple()
408 echo '</table>';
409 echo '</fieldset>';
413 * Closes form tabs
415 * @return void
417 function PMA_displayTabsBottom()
419 echo "</div>\n";
423 * Displays bottom part of the form
425 * @return void
427 function PMA_displayFormBottom()
429 echo "</form>\n";
433 * Appends JS validation code to $js_array
435 * @param string $field_id ID of field to validate
436 * @param string|array $validators validators callback
437 * @param array &$js_array will be updated with javascript code
439 * @return void
441 function PMA_addJsValidate($field_id, $validators, &$js_array)
443 foreach ((array)$validators as $validator) {
444 $validator = (array)$validator;
445 $v_name = array_shift($validator);
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>';