From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- .../libraries/classes/Config/PageSettings.php | 233 +++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 srcs/phpmyadmin/libraries/classes/Config/PageSettings.php (limited to 'srcs/phpmyadmin/libraries/classes/Config/PageSettings.php') diff --git a/srcs/phpmyadmin/libraries/classes/Config/PageSettings.php b/srcs/phpmyadmin/libraries/classes/Config/PageSettings.php new file mode 100644 index 0000000..57232e1 --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Config/PageSettings.php @@ -0,0 +1,233 @@ +userPreferences = new UserPreferences(); + + $formClass = PageFormList::get($formGroupName); + if ($formClass === null) { + return; + } + + if (isset($_REQUEST['printview']) && $_REQUEST['printview'] == '1') { + return; + } + + if (! empty($elemId)) { + $this->_elemId = $elemId; + } + $this->_groupName = $formGroupName; + + $cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings); + $this->userPreferences->pageInit($cf); + + $formDisplay = new $formClass($cf); + + // Process form + $error = null; + if (isset($_POST['submit_save']) + && $_POST['submit_save'] == $formGroupName + ) { + $this->_processPageSettings($formDisplay, $cf, $error); + } + + // Display forms + $this->_HTML = $this->_getPageSettingsDisplay($formDisplay, $error); + } + + /** + * Process response to form + * + * @param FormDisplay $formDisplay Form + * @param ConfigFile $cf Configuration file + * @param Message|null $error Error message + * + * @return void + */ + private function _processPageSettings(&$formDisplay, &$cf, &$error) + { + if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) { + // save settings + $result = $this->userPreferences->save($cf->getConfigArray()); + if ($result === true) { + // reload page + $response = Response::getInstance(); + Core::sendHeaderLocation( + $response->getFooter()->getSelfUrl() + ); + exit; + } else { + $error = $result; + } + } + } + + /** + * Store errors in _errorHTML + * + * @param FormDisplay $formDisplay Form + * @param Message|null $error Error message + * + * @return void + */ + private function _storeError(&$formDisplay, &$error) + { + $retval = ''; + if ($error) { + $retval .= $error->getDisplay(); + } + if ($formDisplay->hasErrors()) { + // form has errors + $retval .= '
' + . '' . __( + 'Cannot save settings, submitted configuration form contains ' + . 'errors!' + ) . '' + . $formDisplay->displayErrors() + . '
'; + } + $this->_errorHTML = $retval; + } + + /** + * Display page-related settings + * + * @param FormDisplay $formDisplay Form + * @param Message $error Error message + * + * @return string + */ + private function _getPageSettingsDisplay(&$formDisplay, &$error) + { + $response = Response::getInstance(); + + $retval = ''; + + $this->_storeError($formDisplay, $error); + + $retval .= '
'; + $retval .= '
'; + $retval .= $formDisplay->getDisplay( + true, + true, + false, + $response->getFooter()->getSelfUrl(), + [ + 'submit_save' => $this->_groupName, + ] + ); + $retval .= '
'; + $retval .= '
'; + + return $retval; + } + + /** + * Get HTML output + * + * @return string + */ + public function getHTML() + { + return $this->_HTML; + } + + /** + * Get error HTML output + * + * @return string + */ + public function getErrorHTML() + { + return $this->_errorHTML; + } + + /** + * Group to show for Page-related settings + * @param string $formGroupName The name of config form group to display + * @return PageSettings + */ + public static function showGroup($formGroupName) + { + $object = new PageSettings($formGroupName); + + $response = Response::getInstance(); + $response->addHTML($object->getErrorHTML()); + $response->addHTML($object->getHTML()); + + return $object; + } + + /** + * Get HTML for navigation settings + * @return string + */ + public static function getNaviSettings() + { + $object = new PageSettings('Navi', 'pma_navigation_settings'); + + $response = Response::getInstance(); + $response->addHTML($object->getErrorHTML()); + return $object->getHTML(); + } +} -- cgit