FormDisplay.tpl.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Form templates
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. /**
  9. * Displays top part of the form
  10. *
  11. * @param string $action default: $_SERVER['REQUEST_URI']
  12. * @param string $method 'post' or 'get'
  13. * @param array $hidden_fields array of form hidden fields (key: field name)
  14. *
  15. * @return void
  16. */
  17. function PMA_displayFormTop($action = null, $method = 'post', $hidden_fields = null)
  18. {
  19. static $has_check_page_refresh = false;
  20. if ($action === null) {
  21. $action = $_SERVER['REQUEST_URI'];
  22. }
  23. if ($method != 'post') {
  24. $method = 'get';
  25. }
  26. echo '<form method="' . $method . '" action="'
  27. . htmlspecialchars($action) . '" class="config-form disableAjax">';
  28. echo '<input type="hidden" name="tab_hash" value="" />';
  29. // we do validation on page refresh when browser remembers field values,
  30. // add a field with known value which will be used for checks
  31. if (!$has_check_page_refresh) {
  32. $has_check_page_refresh = true;
  33. echo '<input type="hidden" name="check_page_refresh" '
  34. . ' id="check_page_refresh" value="" />' . "\n";
  35. }
  36. echo PMA_generate_common_hidden_inputs('', '', 0, 'server') . "\n";
  37. echo PMA_getHiddenFields((array)$hidden_fields);
  38. }
  39. /**
  40. * Displays form tabs which are given by an array indexed by fieldset id
  41. * ({@link PMA_displayFieldsetTop}), with values being tab titles.
  42. *
  43. * @param array $tabs tab names
  44. *
  45. * @return void
  46. */
  47. function PMA_displayTabsTop($tabs)
  48. {
  49. echo '<ul class="tabs">';
  50. foreach ($tabs as $tab_id => $tab_name) {
  51. echo '<li><a href="#' . $tab_id . '">'
  52. . htmlspecialchars($tab_name) . '</a></li>';
  53. }
  54. echo '</ul>';
  55. echo '<br clear="right" />';
  56. echo '<div class="tabs_contents">';
  57. }
  58. /**
  59. * Displays top part of a fieldset
  60. *
  61. * @param string $title title of fieldset
  62. * @param string $description description shown on top of fieldset
  63. * @param array $errors error messages to display
  64. * @param array $attributes optional extra attributes of fieldset
  65. *
  66. * @return void
  67. */
  68. function PMA_displayFieldsetTop($title = '', $description = '', $errors = null,
  69. $attributes = array()
  70. ) {
  71. global $_FormDisplayGroup;
  72. $_FormDisplayGroup = 0;
  73. $attributes = array_merge(array('class' => 'optbox'), $attributes);
  74. foreach ($attributes as $k => &$attr) {
  75. $attr = $k . '="' . htmlspecialchars($attr) . '"';
  76. }
  77. echo '<fieldset ' . implode(' ', $attributes) . '>';
  78. echo '<legend>' . $title . '</legend>';
  79. if (!empty($description)) {
  80. echo '<p>' . $description . '</p>';
  81. }
  82. // this must match with displayErrors() in scripts.js
  83. if (is_array($errors) && count($errors) > 0) {
  84. echo '<dl class="errors">';
  85. foreach ($errors as $error) {
  86. echo '<dd>' . $error . '</dd>';
  87. }
  88. echo '</dl>';
  89. }
  90. echo '<table width="100%" cellspacing="0">';
  91. }
  92. /**
  93. * Displays input field
  94. *
  95. * $opts keys:
  96. * o doc - (string) documentation link
  97. * o errors - error array
  98. * o setvalue - (string) shows button allowing to set poredefined value
  99. * o show_restore_default - (boolean) whether show "restore default" button
  100. * o userprefs_allow - whether user preferences are enabled for this field
  101. * (null - no support, true/false - enabled/disabled)
  102. * o userprefs_comment - (string) field comment
  103. * o values - key - value paris for <select> fields
  104. * o values_escaped - (boolean) tells whether values array is already escaped
  105. * (defaults to false)
  106. * o values_disabled - (array)list of disabled values (keys from values)
  107. * o comment - (string) tooltip comment
  108. * o comment_warning - (bool) whether this comments warns about something
  109. * o wiki - (string) wiki link
  110. *
  111. * @param string $path config option path
  112. * @param string $name config option name
  113. * @param string $type type of config option
  114. * @param mixed $value current value
  115. * @param string $description verbose description
  116. * @param bool $value_is_default whether value is default
  117. * @param array $opts see above description
  118. *
  119. * @return void
  120. */
  121. function PMA_displayInput($path, $name, $type, $value, $description = '',
  122. $value_is_default = true, $opts = null
  123. ) {
  124. global $_FormDisplayGroup;
  125. static $icons; // An array of IMG tags used further below in the function
  126. $is_setup_script = defined('PMA_SETUP');
  127. if ($icons === null) { // if the static variables have not been initialised
  128. $icons = array();
  129. // Icon definitions:
  130. // The same indexes will be used in the $icons array.
  131. // The first element contains the filename and the second
  132. // element is used for the "alt" and "title" attributes.
  133. $icon_init = array(
  134. 'edit' => array('b_edit.png', ''),
  135. 'help' => array('b_help.png', __('Documentation')),
  136. 'info' => array('b_info.png', __('Wiki')),
  137. 'reload' => array('s_reload.png', ''),
  138. 'tblops' => array('b_tblops.png', '')
  139. );
  140. if ($is_setup_script) {
  141. // When called from the setup script, we don't have access to the
  142. // sprite-aware getImage() function because the PMA_theme class
  143. // has not been loaded, so we generate the img tags manually.
  144. foreach ($icon_init as $k => $v) {
  145. $title = '';
  146. if (! empty($v[1])) {
  147. $title = ' title="' . $v[1] . '"';
  148. }
  149. $icons[$k] = sprintf(
  150. '<img alt="%s" src="%s"%s />',
  151. $v[1],
  152. ".{$GLOBALS['cfg']['ThemePath']}/original/img/{$v[0]}",
  153. $title
  154. );
  155. }
  156. } else {
  157. // In this case we just use getImage() because it's available
  158. foreach ($icon_init as $k => $v) {
  159. $icons[$k] = PMA_Util::getImage(
  160. $v[0], $v[1]
  161. );
  162. }
  163. }
  164. }
  165. $has_errors = isset($opts['errors']) && !empty($opts['errors']);
  166. $option_is_disabled = ! $is_setup_script && isset($opts['userprefs_allow'])
  167. && ! $opts['userprefs_allow'];
  168. $name_id = 'name="' . htmlspecialchars($path) . '" id="'
  169. . htmlspecialchars($path) . '"';
  170. $field_class = $type == 'checkbox' ? 'checkbox' : '';
  171. if (! $value_is_default) {
  172. $field_class .= ($field_class == '' ? '' : ' ')
  173. . ($has_errors ? 'custom field-error' : 'custom');
  174. }
  175. $field_class = $field_class ? ' class="' . $field_class . '"' : '';
  176. $tr_class = $_FormDisplayGroup > 0
  177. ? 'group-field group-field-' . $_FormDisplayGroup
  178. : '';
  179. if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
  180. unset($opts['setvalue']);
  181. $_FormDisplayGroup++;
  182. $tr_class = 'group-header-field group-header-' . $_FormDisplayGroup;
  183. }
  184. if ($option_is_disabled) {
  185. $tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
  186. }
  187. $tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
  188. echo '<tr' . $tr_class . '>';
  189. echo '<th>';
  190. echo '<label for="' . htmlspecialchars($path) . '">' . $name . '</label>';
  191. if (! empty($opts['doc']) || ! empty($opts['wiki'])) {
  192. echo '<span class="doc">';
  193. if (! empty($opts['doc'])) {
  194. echo '<a href="' . $opts['doc']
  195. . '" target="documentation">' . $icons['help'] . '</a>';
  196. echo "\n";
  197. }
  198. if (! empty($opts['wiki'])) {
  199. echo '<a href="' . $opts['wiki']
  200. . '" target="wiki">' . $icons['info'] . '</a>';
  201. echo "\n";
  202. }
  203. echo '</span>';
  204. }
  205. if ($option_is_disabled) {
  206. echo '<span class="disabled-notice" title="';
  207. echo __(
  208. 'This setting is disabled, it will not be applied to your configuration'
  209. );
  210. echo '">' . __('Disabled') . "</span>";
  211. }
  212. if (!empty($description)) {
  213. echo '<small>' . $description . '</small>';
  214. }
  215. echo '</th>';
  216. echo '<td>';
  217. switch ($type) {
  218. case 'text':
  219. echo '<input type="text" size="60" ' . $name_id . $field_class
  220. . ' value="' . htmlspecialchars($value) . '" />';
  221. break;
  222. case 'short_text':
  223. echo '<input type="text" size="25" ' . $name_id . $field_class
  224. . ' value="' . htmlspecialchars($value) . '" />';
  225. break;
  226. case 'number_text':
  227. echo '<input type="text" size="15" ' . $name_id . $field_class
  228. . ' value="' . htmlspecialchars($value) . '" />';
  229. break;
  230. case 'checkbox':
  231. echo '<span' . $field_class . '><input type="checkbox" ' . $name_id
  232. . ($value ? ' checked="checked"' : '') . ' /></span>';
  233. break;
  234. case 'select':
  235. echo '<select ' . $name_id . $field_class . '>';
  236. $escape = !(isset($opts['values_escaped']) && $opts['values_escaped']);
  237. $values_disabled = isset($opts['values_disabled'])
  238. ? array_flip($opts['values_disabled']) : array();
  239. foreach ($opts['values'] as $opt_value_key => $opt_value) {
  240. // set names for boolean values
  241. if (is_bool($opt_value)) {
  242. $opt_value = strtolower($opt_value ? __('Yes') : __('No'));
  243. }
  244. // escape if necessary
  245. if ($escape) {
  246. $display = htmlspecialchars($opt_value);
  247. $display_value = htmlspecialchars($opt_value_key);
  248. } else {
  249. $display = $opt_value;
  250. $display_value = $opt_value_key;
  251. }
  252. // compare with selected value
  253. // boolean values are cast to integers when used as array keys
  254. $selected = is_bool($value)
  255. ? (int) $value === $opt_value_key
  256. : $opt_value_key === $value;
  257. echo '<option value="' . $display_value . '"';
  258. if ($selected) {
  259. echo ' selected="selected"';
  260. }
  261. if (isset($values_disabled[$opt_value_key])) {
  262. echo ' disabled="disabled"';
  263. }
  264. echo '>' . $display . '</option>';
  265. }
  266. echo '</select>';
  267. break;
  268. case 'list':
  269. echo '<textarea cols="40" rows="5" ' . $name_id . $field_class . '>'
  270. . htmlspecialchars(implode("\n", $value))
  271. . '</textarea>';
  272. break;
  273. }
  274. if (isset($opts['comment']) && $opts['comment']) {
  275. $class = 'field-comment-mark';
  276. if (isset($opts['comment_warning']) && $opts['comment_warning']) {
  277. $class .= ' field-comment-warning';
  278. }
  279. echo '<span class="' . $class . '" title="'
  280. . htmlspecialchars($opts['comment']) . '">i</span>';
  281. }
  282. if ($is_setup_script
  283. && isset($opts['userprefs_comment'])
  284. && $opts['userprefs_comment']
  285. ) {
  286. echo '<a class="userprefs-comment" title="'
  287. . htmlspecialchars($opts['userprefs_comment']) . '">'
  288. . $icons['tblops'] . '</a>';
  289. }
  290. if (isset($opts['setvalue']) && $opts['setvalue']) {
  291. echo '<a class="set-value" href="#'
  292. . htmlspecialchars("$path={$opts['setvalue']}") . '" title="'
  293. . sprintf(__('Set value: %s'), htmlspecialchars($opts['setvalue']))
  294. . '" style="display:none">' . $icons['edit'] . '</a>';
  295. }
  296. if (isset($opts['show_restore_default']) && $opts['show_restore_default']) {
  297. echo '<a class="restore-default" href="#' . $path . '" title="'
  298. . __('Restore default value') . '" style="display:none">'
  299. . $icons['reload'] . '</a>';
  300. }
  301. // this must match with displayErrors() in scripts/config.js
  302. if ($has_errors) {
  303. echo "\n <dl class=\"inline_errors\">";
  304. foreach ($opts['errors'] as $error) {
  305. echo '<dd>' . htmlspecialchars($error) . '</dd>';
  306. }
  307. echo '</dl>';
  308. }
  309. echo '</td>';
  310. if ($is_setup_script && isset($opts['userprefs_allow'])) {
  311. echo '<td class="userprefs-allow" title="' .
  312. __('Allow users to customize this value') . '">';
  313. echo '<input type="checkbox" name="' . $path . '-userprefs-allow" ';
  314. if ($opts['userprefs_allow']) {
  315. echo 'checked="checked"';
  316. };
  317. echo '/>';
  318. echo '</td>';
  319. } else if ($is_setup_script) {
  320. echo '<td>&nbsp;</td>';
  321. }
  322. echo '</tr>';
  323. }
  324. /**
  325. * Display group header
  326. *
  327. * @param string $header_text Text of header
  328. *
  329. * @return void
  330. */
  331. function PMA_displayGroupHeader($header_text)
  332. {
  333. global $_FormDisplayGroup;
  334. $_FormDisplayGroup++;
  335. if (!$header_text) {
  336. return;
  337. }
  338. $colspan = defined('PMA_SETUP')
  339. ? 3
  340. : 2;
  341. echo '<tr class="group-header group-header-' . $_FormDisplayGroup . '">';
  342. echo '<th colspan="' . $colspan . '">';
  343. echo $header_text;
  344. echo '</th>';
  345. echo '</tr>';
  346. }
  347. /**
  348. * Display group footer
  349. *
  350. * @return void
  351. */
  352. function PMA_displayGroupFooter()
  353. {
  354. global $_FormDisplayGroup;
  355. $_FormDisplayGroup--;
  356. }
  357. /**
  358. * Displays bottom part of a fieldset
  359. *
  360. * @return void
  361. */
  362. function PMA_displayFieldsetBottom()
  363. {
  364. $colspan = 2;
  365. if (defined('PMA_SETUP')) {
  366. $colspan++;
  367. }
  368. echo '<tr>';
  369. echo '<td colspan="' . $colspan . '" class="lastrow">';
  370. echo '<input type="submit" name="submit_save" value="'
  371. . __('Save') . '" class="green" />';
  372. echo '<input type="button" name="submit_reset" value="'
  373. . __('Reset') . '" />';
  374. echo '</td>';
  375. echo '</tr>';
  376. echo '</table>';
  377. echo '</fieldset>';
  378. }
  379. /**
  380. * Displays simple bottom part of a fieldset (without submit buttons)
  381. *
  382. * @return void
  383. */
  384. function PMA_displayFieldsetBottomSimple()
  385. {
  386. echo '</table>';
  387. echo '</fieldset>';
  388. }
  389. /**
  390. * Closes form tabs
  391. *
  392. * @return void
  393. */
  394. function PMA_displayTabsBottom()
  395. {
  396. echo "</div>\n";
  397. }
  398. /**
  399. * Displays bottom part of the form
  400. *
  401. * @return void
  402. */
  403. function PMA_displayFormBottom()
  404. {
  405. echo "</form>\n";
  406. }
  407. /**
  408. * Appends JS validation code to $js_array
  409. *
  410. * @param string $field_id ID of field to validate
  411. * @param string|array $validators validators callback
  412. * @param array &$js_array will be updated with javascript code
  413. *
  414. * @return void
  415. */
  416. function PMA_addJsValidate($field_id, $validators, &$js_array)
  417. {
  418. foreach ((array)$validators as $validator) {
  419. $validator = (array)$validator;
  420. $v_name = array_shift($validator);
  421. $v_args = array();
  422. foreach ($validator as $arg) {
  423. $v_args[] = PMA_escapeJsString($arg);
  424. }
  425. $v_args = $v_args ? ", ['" . implode("', '", $v_args) . "']" : '';
  426. $js_array[] = "validateField('$field_id', '$v_name', true$v_args)";
  427. }
  428. }
  429. /**
  430. * Displays JavaScript code
  431. *
  432. * @param array $js_array lines of javascript code
  433. *
  434. * @return void
  435. */
  436. function PMA_displayJavascript($js_array)
  437. {
  438. if (empty($js_array)) {
  439. return;
  440. }
  441. echo '<script type="text/javascript">' . "\n";
  442. echo implode(";\n", $js_array) . ";\n";
  443. echo '</script>' . "\n";
  444. }
  445. /**
  446. * Displays error list
  447. *
  448. * @param string $name name of item with errors
  449. * @param array $error_list list of errors to show
  450. *
  451. * @return void
  452. */
  453. function PMA_displayErrors($name, $error_list)
  454. {
  455. echo '<dl>';
  456. echo '<dt>' . htmlspecialchars($name) . '</dt>';
  457. foreach ($error_list as $error) {
  458. echo '<dd>' . htmlspecialchars($error) . '</dd>';
  459. }
  460. echo '</dl>';
  461. }
  462. ?>