prefs_forms.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * User preferences page
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Config\ConfigFile;
  9. use PhpMyAdmin\Config\Forms\User\UserFormList;
  10. use PhpMyAdmin\Core;
  11. use PhpMyAdmin\Response;
  12. use PhpMyAdmin\Url;
  13. use PhpMyAdmin\UserPreferences;
  14. /**
  15. * Gets some core libraries and displays a top message if required
  16. */
  17. require_once 'libraries/common.inc.php';
  18. $userPreferences = new UserPreferences();
  19. $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
  20. $userPreferences->pageInit($cf);
  21. // handle form processing
  22. $form_param = isset($_GET['form']) ? $_GET['form'] : null;
  23. $form_class = UserFormList::get($form_param);
  24. if (is_null($form_class)) {
  25. Core::fatalError(__('Incorrect form specified!'));
  26. }
  27. $form_display = new $form_class($cf, 1);
  28. if (isset($_POST['revert'])) {
  29. // revert erroneous fields to their default values
  30. $form_display->fixErrors();
  31. // redirect
  32. $url_params = array('form' => $form_param);
  33. Core::sendHeaderLocation(
  34. './prefs_forms.php'
  35. . Url::getCommonRaw($url_params)
  36. );
  37. exit;
  38. }
  39. $error = null;
  40. if ($form_display->process(false) && !$form_display->hasErrors()) {
  41. // save settings
  42. $result = $userPreferences->save($cf->getConfigArray());
  43. if ($result === true) {
  44. // reload config
  45. $GLOBALS['PMA_Config']->loadUserPreferences();
  46. $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
  47. $hash = ltrim($tabHash, '#');
  48. $userPreferences->redirect(
  49. 'prefs_forms.php',
  50. array('form' => $form_param),
  51. $hash
  52. );
  53. exit;
  54. } else {
  55. $error = $result;
  56. }
  57. }
  58. // display forms
  59. $response = Response::getInstance();
  60. $header = $response->getHeader();
  61. $scripts = $header->getScripts();
  62. $scripts->addFile('config.js');
  63. require 'libraries/user_preferences.inc.php';
  64. if ($error) {
  65. $error->display();
  66. }
  67. if ($form_display->hasErrors()) {
  68. // form has errors
  69. ?>
  70. <div class="error config-form">
  71. <b>
  72. <?php echo __('Cannot save settings, submitted form contains errors!') ?>
  73. </b>
  74. <?php echo $form_display->displayErrors(); ?>
  75. </div>
  76. <?php
  77. }
  78. echo $form_display->getDisplay(true, true, true, 'prefs_forms.php?form=' . $form_param, array(
  79. 'server' => $GLOBALS['server']
  80. ));
  81. if ($response->isAjax()) {
  82. $response->addJSON('_disableNaviSettings', true);
  83. } else {
  84. define('PMA_DISABLE_NAVI_SETTINGS', true);
  85. }