Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / config / FormDisplay.tpl.php
blobbe680d3ce862bec65948cb38d020cffcc8cf5fd9
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 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') {
24 $method = 'get';
27 <form method="<?php echo $method ?>" action="<?php echo htmlspecialchars($action) ?>" class="config-form">
28 <input type="hidden" name="tab_hash" value="" />
29 <?php
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);
41 /**
42 * Displays form tabs which are given by an array indexed by fieldset id
43 * ({@link display_fieldset_top}), with values being tab titles.
45 * @param array $tabs
47 function display_tabs_top($tabs)
50 <ul class="tabs">
51 <?php foreach ($tabs as $tab_id => $tab_name): ?>
52 <li><a href="#<?php echo $tab_id ?>"><?php echo $tab_name ?></a></li>
53 <?php endforeach; ?>
54 </ul>
55 <br clear="right" />
56 <div class="tabs_contents">
57 <?php
61 /**
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>';
91 echo '</dl>';
94 <table width="100%" cellspacing="0">
95 <?php
98 /**
99 * Displays input field
101 * $opts keys:
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
122 * @param array $opts
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
146 : '';
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 ?>>
158 <th>
159 <label for="<?php echo htmlspecialchars($path) ?>"><?php echo $name ?></label>
160 <?php if (!empty($opts['doc']) || !empty($opts['wiki'])) { ?>
161 <span class="doc">
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 } ?>
164 </span>
165 <?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>
168 <?php } ?>
169 <?php if (!empty($description)) { ?><small><?php echo $description ?></small><?php } ?>
170 </th>
171 <td>
172 <?php
173 switch ($type) {
174 case 'text':
175 echo '<input type="text" size="60" ' . $name_id . $field_class
176 . ' value="' . htmlspecialchars($value) . '" />';
177 break;
178 case 'short_text':
179 echo '<input type="text" size="25" ' . $name_id . $field_class
180 . ' value="' . htmlspecialchars($value) . '" />';
181 break;
182 case 'number_text':
183 echo '<input type="text" size="15" ' . $name_id . $field_class
184 . ' value="' . htmlspecialchars($value) . '" />';
185 break;
186 case 'checkbox':
187 echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
188 . ($value ? ' checked="checked"' : '') . ' /></span>';
189 break;
190 case 'select':
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
201 if ($escape) {
202 $display = htmlspecialchars($opt_value);
203 $display_value = htmlspecialchars($opt_value_key);
204 } else {
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>';
218 echo '</select>';
219 break;
220 case 'list':
221 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
222 . htmlspecialchars(implode("\n", $value))
223 . '</textarea>';
224 break;
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>
233 <?php
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>
238 <?php
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>
243 <?php
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>
248 <?php
250 // this must match with displayErrors() in scripts/config.js
251 if ($has_errors) {
252 echo "\n <dl class=\"inline_errors\">";
253 foreach ($opts['errors'] as $error) {
254 echo '<dd>' . htmlspecialchars($error) . '</dd>';
256 echo '</dl>';
259 </td>
260 <?php
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"' ?> />
265 </td>
266 <?php
267 } else if ($is_setup_script) {
268 echo '<td>&nbsp;</td>';
271 </tr>
272 <?php
276 * Display group header
278 * @param string $header_text
280 function display_group_header($header_text)
282 global $_FormDisplayGroup;
284 $_FormDisplayGroup++;
285 if (!$header_text) {
286 return;
288 $colspan = defined('PMA_SETUP')
290 : 2;
292 <tr class="group-header group-header-<?php echo $_FormDisplayGroup ?>">
293 <th colspan="<?php echo $colspan ?>">
294 <?php echo $header_text ?>
295 </th>
296 </tr>
297 <?php
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()
316 $colspan = 2;
317 if (defined('PMA_SETUP')) {
318 $colspan++;
321 <tr>
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') ?>" />
325 </td>
326 </tr>
327 </table>
328 </fieldset>
330 <?php
334 * Displays simple bottom part of a fieldset (without submit buttons)
336 function display_fieldset_bottom_simple()
339 </table>
340 </fieldset>
342 <?php
346 * Closes form tabs
348 function display_tabs_bottom()
350 echo "</div>\n";
354 * Displays bottom part of the form
356 function display_form_bottom()
358 echo "</form>\n";
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);
373 $v_args = array();
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)) {
390 return;
393 <script type="text/javascript">
394 <?php echo implode(";\n", $js_array) . ";\n" ?>
395 </script>
396 <?php
400 * Displays error list
402 * @param string $name
403 * @param array $error_list
405 function display_errors($name, $error_list)
407 echo '<dl>';
408 echo '<dt>' . htmlspecialchars($name) . '</dt>';
409 foreach ($error_list as $error) {
410 echo '<dd>' . htmlspecialchars($error) . '</dd>';
412 echo '</dl>';