2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Front controller for config view / download and clear
6 * @package PhpMyAdmin-Setup
8 use PMA\libraries\config\FormDisplay
;
9 use PMA\setup\lib\ConfigGenerator
;
14 require './lib/common.inc.php';
16 require './libraries/config/setup.forms.php';
19 * Loads configuration file path
21 * Do this in a function to avoid messing up with global $cfg
23 * @param string $config_file_path
27 function loadConfig($config_file_path)
30 if (file_exists($config_file_path)) {
31 include $config_file_path;
36 $form_display = new FormDisplay($GLOBALS['ConfigFile']);
37 $form_display->registerForm('_config.php', $forms['_config.php']);
38 $form_display->save('_config.php');
39 $config_file_path = $GLOBALS['ConfigFile']->getFilePath();
41 if (isset($_POST['eol'])) {
42 $_SESSION['eol'] = ($_POST['eol'] == 'unix') ?
'unix' : 'win';
45 if (PMA_ifSetOr($_POST['submit_clear'], '')) {
47 // Clear current config and return to main page
49 $GLOBALS['ConfigFile']->resetConfigData();
51 header('HTTP/1.1 303 See Other');
52 header('Location: index.php' . PMA_URL_getCommon());
54 } elseif (PMA_ifSetOr($_POST['submit_download'], '')) {
56 // Output generated config file
58 PMA_downloadHeader('config.inc.php', 'text/plain');
59 echo ConfigGenerator
::getConfigFile($GLOBALS['ConfigFile']);
61 } elseif (PMA_ifSetOr($_POST['submit_save'], '')) {
63 // Save generated config file on the server
65 $result = @file_put_contents
(
67 ConfigGenerator
::getConfigFile($GLOBALS['ConfigFile'])
69 if ($result === false) {
70 $state = 'config_not_saved';
72 $state = 'config_saved';
74 header('HTTP/1.1 303 See Other');
75 header('Location: index.php' . PMA_URL_getCommon() . '&action_done=' . $state);
77 } elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
79 // Load config file from the server
81 $GLOBALS['ConfigFile']->setConfigData(
82 loadConfig($config_file_path)
84 header('HTTP/1.1 303 See Other');
85 header('Location: index.php' . PMA_URL_getCommon());
87 } elseif (PMA_ifSetOr($_POST['submit_delete'], '')) {
89 // Delete config file on the server
91 @unlink
($config_file_path);
92 header('HTTP/1.1 303 See Other');
93 header('Location: index.php' . PMA_URL_getCommon());
97 // Show generated config file in a <textarea>
99 header('HTTP/1.1 303 See Other');
100 header('Location: index.php' . PMA_URL_getCommon() . '&page=config');