From 04d6d5ca99ebfd1cebb8ce06618fb3811fc1a8aa Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 9 Jan 2020 10:55:03 +0100 Subject: phpmyadmin working --- srcs/phpmyadmin/libraries/classes/Console.php | 158 ++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 srcs/phpmyadmin/libraries/classes/Console.php (limited to 'srcs/phpmyadmin/libraries/classes/Console.php') diff --git a/srcs/phpmyadmin/libraries/classes/Console.php b/srcs/phpmyadmin/libraries/classes/Console.php new file mode 100644 index 0000000..50ac77a --- /dev/null +++ b/srcs/phpmyadmin/libraries/classes/Console.php @@ -0,0 +1,158 @@ +_isEnabled = true; + $this->relation = new Relation($GLOBALS['dbi']); + $this->template = new Template(); + } + + /** + * Set the ajax flag to indicate whether + * we are servicing an ajax request + * + * @param bool $isAjax Whether we are servicing an ajax request + * + * @return void + */ + public function setAjax(bool $isAjax): void + { + $this->_isAjax = $isAjax; + } + + /** + * Disables the rendering of the footer + * + * @return void + */ + public function disable(): void + { + $this->_isEnabled = false; + } + + /** + * Renders the bookmark content + * + * @access public + * @return string + */ + public static function getBookmarkContent(): string + { + $template = new Template(); + $cfgBookmark = Bookmark::getParams($GLOBALS['cfg']['Server']['user']); + if ($cfgBookmark) { + $bookmarks = Bookmark::getList( + $GLOBALS['dbi'], + $GLOBALS['cfg']['Server']['user'] + ); + $count_bookmarks = count($bookmarks); + if ($count_bookmarks > 0) { + $welcomeMessage = sprintf( + _ngettext( + 'Showing %1$d bookmark (both private and shared)', + 'Showing %1$d bookmarks (both private and shared)', + $count_bookmarks + ), + $count_bookmarks + ); + } else { + $welcomeMessage = __('No bookmarks'); + } + unset($count_bookmarks, $private_message, $shared_message); + return $template->render('console/bookmark_content', [ + 'welcome_message' => $welcomeMessage, + 'bookmarks' => $bookmarks, + ]); + } + return ''; + } + + /** + * Returns the list of JS scripts required by console + * + * @return array list of scripts + */ + public function getScripts(): array + { + return ['console.js']; + } + + /** + * Renders the console + * + * @access public + * @return string + */ + public function getDisplay(): string + { + if ((! $this->_isAjax) && $this->_isEnabled) { + $cfgBookmark = Bookmark::getParams( + $GLOBALS['cfg']['Server']['user'] + ); + + $image = Util::getImage('console', __('SQL Query Console')); + $_sql_history = $this->relation->getHistory( + $GLOBALS['cfg']['Server']['user'] + ); + $bookmarkContent = static::getBookmarkContent(); + + return $this->template->render('console/display', [ + 'cfg_bookmark' => $cfgBookmark, + 'image' => $image, + 'sql_history' => $_sql_history, + 'bookmark_content' => $bookmarkContent, + ]); + } + return ''; + } +} -- cgit