remove todo, after upgrade PHPExcel
[phpmyadmin/arisferyanto.git] / setup / lib / FormDisplay.tpl.php
blob920f8174ad1e24dcaba2d1ddcb25e81a01bfcb8f
1 <?php
2 /**
3 * Form templates
5 * @package phpMyAdmin-setup
6 * @author Piotr Przybylski <piotrprz@gmail.com>
7 * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
8 * @version $Id$
9 */
11 /**
12 * Displays top part of the form
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') {
26 $method = 'get';
29 <form method="<?php echo $method ?>" action="<?php echo htmlspecialchars($action) ?>">
30 <?php
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" id="check_page_refresh"'
36 . ' value="" />' . "\n";
38 echo PMA_generate_common_hidden_inputs() . "\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 display_fieldset_top}), with values being tab titles.
46 * @param array $tabs
48 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 $attributes = array_merge(array('class' => 'optbox'), $attributes);
72 foreach ($attributes as $k => &$attr) {
73 $attr = $k . '="' . htmlspecialchars($attr) . '"';
76 echo '<fieldset ' . implode(' ', $attributes) . '>';
77 echo '<legend>' . $title . '</legend>';
78 if (!empty($description)) {
79 echo '<p>' . $description . '</p>';
81 // this must match with displayErrors() in scripts.js
82 if (is_array($errors) && count($errors) > 0) {
83 echo '<dl class="errors">';
84 foreach ($errors as $error) {
85 echo '<dd>' . $error . '</dd>';
87 echo '</dl>';
90 <table width="100%" cellspacing="0">
91 <?php
94 /**
95 * Displays input field
97 * $opts keys:
98 * o doc - (string) documentation link
99 * o errors - error array
100 * o setvalue - (string) shows button allowing to set poredefined value
101 * o show_restore_default - (boolean) whether show "restore default" button
102 * o values - key - value paris for <select> fields
103 * o values_escaped - (boolean) tells whether values array is already escaped (defaults to false)
104 * o values_disabled - (array)list of disabled values (keys from values)
105 * o wiki - (string) wiki link
107 * @param string $path
108 * @param string $name
109 * @param string $description
110 * @param string $type
111 * @param mixed $value
112 * @param bool $value_is_default
113 * @param array $opts
115 function display_input($path, $name, $description = '', $type, $value, $value_is_default = true, $opts = null)
117 $field_class = $value_is_default ? '' : ' class="custom"';
118 $name_id = 'name="' . $path . '" id="' . $path . '"';
120 <tr>
121 <th>
122 <label for="<?php echo htmlspecialchars($path) ?>"><?php echo $name ?></label>
123 <?php if (!empty($opts['doc']) || !empty($opts['wiki'])): ?>
124 <span class="doc">
125 <?php if (!empty($opts['doc'])) { ?><a href="<?php echo $opts['doc'] ?>" target="documentation"><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath'] ?>/original/img/b_help.png" width="11" height="11" alt="Doc" title="<?php echo $GLOBALS['strDocu'] ?>" /></a><?php } ?>
126 <?php if (!empty($opts['wiki'])){ ?><a href="<?php echo $opts['wiki'] ?>" target="wiki"><img class="icon" src="../<?php echo $GLOBALS['cfg']['ThemePath'] ?>/original/img/b_info.png" width="11" height="11" alt="Wiki" title="Wiki" /></a><?php } ?>
127 </span>
128 <?php endif; ?>
129 <?php if (!empty($description)) { ?><small><?php echo $description ?></small><?php } ?>
131 </th>
132 <td>
133 <?php
134 switch ($type) {
135 case 'text':
136 echo '<input type="text" size="50" ' . $name_id . $field_class
137 . ' value="' . htmlspecialchars($value) . '" />';
138 break;
139 case 'checkbox':
140 echo '<span class="checkbox' . ($value_is_default ? '' : ' custom')
141 . '"><input type="checkbox" ' . $name_id
142 . ($value ? ' checked="checked"' : '') . ' /></span>';
143 break;
144 case 'select':
145 echo '<select ' . $name_id . $field_class . '>';
146 $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
147 $values_disabled = isset($opts['values_disabled'])
148 ? array_flip($opts['values_disabled']) : array();
149 foreach ($opts['values'] as $opt_value => $opt_name) {
150 // set names for boolean values
151 if (is_bool($opt_name)) {
152 $opt_name = $GLOBALS['strSetup' . ($opt_value ? 'True' : 'False')];
154 // cast boolean values to integers
155 $display_value = is_bool($opt_value) ? (int) $opt_value : $opt_value;
156 // escape if necessary
157 if ($escape) {
158 $display = htmlspecialchars($opt_name);
159 $display_value = htmlspecialchars($display_value);
160 } else {
161 $display = $opt_name;
163 // compare with selected value
164 // boolean values are cast to integers when used as array keys
165 $selected = is_bool($value)
166 ? (int) $value === $opt_value
167 : $opt_value === $value;
168 echo '<option value="' . $display_value . '"'
169 . ($selected ? ' selected="selected"' : '')
170 . (isset($values_disabled[$opt_value]) ? ' disabled="disabled"' : '')
171 . '>' . $display . '</option>';
173 echo '</select>';
174 break;
175 case 'list':
176 echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
177 . htmlspecialchars(implode("\n", $value))
178 . '</textarea>';
179 break;
181 if (isset($opts['setvalue']) && $opts['setvalue']) {
183 <a class="set-value" href="#<?php echo "$path={$opts['setvalue']}" ?>" title="<?php echo sprintf($GLOBALS['strSetupSetValue'], htmlspecialchars($opts['setvalue'])) ?>" style="display:none"><img alt="set-value" src="../<?php echo $GLOBALS['cfg']['ThemePath'] ?>/original/img/b_edit.png" width="16" height="16" /></a>
184 <?php
186 if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
188 <a class="restore-default" href="#<?php echo $path ?>" title="<?php echo $GLOBALS['strSetupRestoreDefaultValue'] ?>" style="display:none"><img alt="restore-default" src="../<?php echo $GLOBALS['cfg']['ThemePath'] ?>/original/img/s_reload.png" width="16" height="16" /></a>
189 <?php
191 // this must match with displayErrors() in scripts.js
192 if (isset($opts['errors']) && !empty($opts['errors'])) {
193 echo "\n <dl class=\"inline_errors\">";
194 foreach ($opts['errors'] as $error) {
195 echo '<dd>' . htmlspecialchars($error) . '</dd>';
197 echo '</dl>';
201 </td>
202 </tr>
203 <?php
207 * Displays bottom part of a fieldset
209 * @param array $js_array
211 function display_fieldset_bottom()
214 <tr>
215 <td colspan="2" class="lastrow">
216 <input type="submit" name="submit_save" value="<?php echo $GLOBALS['strSave'] ?>" class="green" />
217 <input type="button" name="submit_reset" value="<?php echo $GLOBALS['strReset'] ?>" />
218 </td>
219 </tr>
220 </table>
221 </fieldset>
223 <?php
227 * Displays simple bottom part of a fieldset (without submit buttons)
229 function display_fieldset_bottom_simple()
232 </table>
233 </fieldset>
235 <?php
239 * Closes form tabs
241 function display_tabs_bottom() {
242 echo "</div>\n";
246 * Displays bottom part of the form
248 function display_form_bottom()
250 echo "</form>\n";
254 * Appends JS validation code to $js_array
256 * @param string $field_id
257 * @param string $validator
258 * @param array $js_array
260 function js_validate($field_id, $validator, &$js_array) {
261 $js_array[] = "validateField('$field_id', '$validator', true)";
265 * Displays JavaScript code
267 * @param array $js_array
269 function display_js($js_array) {
270 if (empty($js_array)) {
271 return;
274 <script type="text/javascript">
275 <?php echo implode(";\n", $js_array) . ";\n" ?>
276 </script>
277 <?php
281 * Displays error list
283 * @param string $name
284 * @param array $error_list
286 function display_errors($name, $error_list) {
287 echo '<dl>';
288 echo '<dt>' . htmlspecialchars($name) . '</dt>';
289 foreach ($error_list as $error) {
290 echo '<dd>' . htmlspecialchars($error) . '</dd>';
292 echo '</dl>';