$params[$k] = mb_substr($q, $pos + 1); } } else { $return_url = 'prefs_manage.php'; } // reload config $GLOBALS['PMA_Config']->loadUserPreferences(); PMA_userprefsRedirect($return_url, $params); exit; } else { $error = $result; } } } else { if (isset($_POST['submit_clear'])) { $result = PMA_saveUserprefs(array()); if ($result === true) { $params = array(); if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') { $GLOBALS['PMA_Config']->removeCookie('pma_fontsize'); } $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection'); $GLOBALS['PMA_Config']->removeCookie('pma_lang'); PMA_userprefsRedirect('prefs_manage.php', $params); exit; } else { $error = $result; } exit; } }
/** * Updates one user preferences option (loads and saves to database). * * No validation is done! * * @param string $path configuration * @param mixed $value value * @param mixed $default_value default value * * @return void */ function PMA_persistOption($path, $value, $default_value) { $prefs = PMA_loadUserprefs(); if ($value === $default_value) { if (isset($prefs['config_data'][$path])) { unset($prefs['config_data'][$path]); } else { return; } } else { $prefs['config_data'][$path] = $value; } PMA_saveUserprefs($prefs['config_data']); }
/** * Process response to form * * @param FormDisplay &$form_display Form * @param ConfigFile &$cf Configuration file * @param PMA_Message|null &$error Error message * * @return void */ private function _processPageSettings(&$form_display, &$cf, &$error) { if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $result = PMA_saveUserprefs($cf->getConfigArray()); if ($result === true) { // reload page header('Location: ' . $_SERVER['REQUEST_URI']); exit; } else { $error = $result; } } }
continue; } $form_display->registerForm($form_name, $form, 1); } if (isset($_POST['revert'])) { // revert erroneous fields to their default values $form_display->fixErrors(); // redirect $url_params = array('form' => $form_param); PMA_sendHeaderLocation('./prefs_forms.php' . URL::getCommonRaw($url_params)); exit; } $error = null; if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $result = PMA_saveUserprefs($cf->getConfigArray()); if ($result === true) { // reload config $GLOBALS['PMA_Config']->loadUserPreferences(); $tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null; $hash = ltrim($tabHash, '#'); PMA_userprefsRedirect('prefs_forms.php', array('form' => $form_param), $hash); exit; } else { $error = $result; } } // display forms $response = Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts();
/** * Test for PMA_saveUserprefs * * @return void */ public function testSaveUserprefs() { $GLOBALS['server'] = 2; $_SESSION['relation'][2]['PMA_VERSION'] = PMA_VERSION; $_SESSION['relation'][2]['userconfigwork'] = null; unset($_SESSION['userconfig']); $result = PMA_saveUserprefs(array(1)); $this->assertTrue($result); $this->assertCount(2, $_SESSION['userconfig']); $this->assertEquals(array(1), $_SESSION['userconfig']['db']); /* TODO: This breaks sometimes as there might be time difference! */ $this->assertEquals(time(), $_SESSION['userconfig']['ts'], '', 2); $assert = true; if (isset($_SESSION['cache']['server_2']['userprefs'])) { $assert = false; } $this->assertTrue($assert); // case 2 $_SESSION['relation'][$GLOBALS['server']]['userconfigwork'] = 1; $_SESSION['relation'][$GLOBALS['server']]['db'] = "pmadb"; $_SESSION['relation'][$GLOBALS['server']]['userconfig'] = "testconf"; $_SESSION['relation'][$GLOBALS['server']]['user'] = "******"; $GLOBALS['controllink'] = null; $query1 = 'SELECT `username` FROM `pmadb`.`testconf` ' . 'WHERE `username` = \'user\''; $query2 = 'UPDATE `pmadb`.`testconf` SET `timevalue` = NOW(), `config_data` = \'' . json_encode(array(1)) . '\' WHERE `username` = \'user\''; $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->once())->method('fetchValue')->with($query1, 0, 0, null)->will($this->returnValue(true)); $dbi->expects($this->once())->method('tryQuery')->with($query2, null)->will($this->returnValue(true)); $dbi->expects($this->any())->method('escapeString')->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; $this->assertTrue(PMA_saveUserprefs(array(1))); // case 3 $query1 = 'SELECT `username` FROM `pmadb`.`testconf` ' . 'WHERE `username` = \'user\''; $query2 = 'INSERT INTO `pmadb`.`testconf` (`username`, `timevalue`,`config_data`) ' . 'VALUES (\'user\', NOW(), \'' . json_encode(array(1)) . '\')'; $dbi = $this->getMockBuilder('PMA\\libraries\\DatabaseInterface')->disableOriginalConstructor()->getMock(); $dbi->expects($this->once())->method('fetchValue')->with($query1, 0, 0, null)->will($this->returnValue(false)); $dbi->expects($this->once())->method('tryQuery')->with($query2, null)->will($this->returnValue(false)); $dbi->expects($this->once())->method('getError')->with(null)->will($this->returnValue("err1")); $dbi->expects($this->any())->method('escapeString')->will($this->returnArgument(0)); $GLOBALS['dbi'] = $dbi; $result = PMA_saveUserprefs(array(1)); $this->assertEquals('Could not save configuration<br /><br />err1', $result->getMessage()); }
continue; } $form_display->registerForm($form_name, $form, 1); } if (isset($_POST['revert'])) { // revert erroneous fields to their default values $form_display->fixErrors(); // redirect $url_params = array('form' => $form_param); PMA_sendHeaderLocation($cfg['PmaAbsoluteUri'] . 'prefs_forms.php' . PMA_generate_common_url($url_params, '&')); exit; } $error = null; if ($form_display->process(false) && !$form_display->hasErrors()) { // save settings $result = PMA_saveUserprefs(ConfigFile::getInstance()->getConfigArray()); if ($result === true) { // reload config $GLOBALS['PMA_Config']->loadUserPreferences(); $hash = ltrim(filter_input(INPUT_POST, 'tab_hash'), '#'); PMA_userprefsRedirect('prefs_forms.php', array('form' => $form_param), $hash); exit; } else { $error = $result; } } // display forms $response = PMA_Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('config.js');