summaryrefslogtreecommitdiff
path: root/hugo/libraries/navigation
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--hugo/libraries/navigation/Navigation.class.php77
-rw-r--r--hugo/libraries/navigation/NavigationHeader.class.php305
-rw-r--r--hugo/libraries/navigation/NavigationTree.class.php1146
-rw-r--r--hugo/libraries/navigation/NodeFactory.class.php97
-rw-r--r--hugo/libraries/navigation/Nodes/Node.class.php444
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Column.class.php46
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Column_Container.class.php56
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Database.class.php436
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Event.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Event_Container.class.php52
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Function.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Function_Container.class.php52
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Index.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Index_Container.class.php54
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Procedure.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Procedure_Container.class.php52
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Table.class.php203
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Table_Container.class.php55
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Trigger.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_Trigger_Container.class.php53
-rw-r--r--hugo/libraries/navigation/Nodes/Node_View.class.php45
-rw-r--r--hugo/libraries/navigation/Nodes/Node_View_Container.class.php51
22 files changed, 3449 insertions, 0 deletions
diff --git a/hugo/libraries/navigation/Navigation.class.php b/hugo/libraries/navigation/Navigation.class.php
new file mode 100644
index 0000000..d140bbc
--- /dev/null
+++ b/hugo/libraries/navigation/Navigation.class.php
@@ -0,0 +1,77 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * This class is responsible for instanciating
+ * the various components of the navigation panel
+ *
+ * @package PhpMyAdmin-navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+require_once 'libraries/navigation/NodeFactory.class.php';
+require_once 'libraries/navigation/NavigationHeader.class.php';
+require_once 'libraries/navigation/NavigationTree.class.php';
+
+/**
+ * The navigation panel - displays server, db and table selection tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class PMA_Navigation
+{
+ /**
+ * Initialises the class
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ if (empty($GLOBALS['token'])) {
+ $GLOBALS['token'] = $_SESSION[' PMA_token '];
+ }
+ }
+
+ /**
+ * Renders the navigation tree, or part of it
+ *
+ * @return string The navigation tree
+ */
+ public function getDisplay()
+ {
+ /* Init */
+ $retval = '';
+ if (! PMA_Response::getInstance()->isAjax()) {
+ $header = new PMA_NavigationHeader();
+ $retval = $header->getDisplay();
+ }
+ $tree = new PMA_NavigationTree();
+ if (! PMA_Response::getInstance()->isAjax()
+ || ! empty($_REQUEST['full'])
+ || ! empty($_REQUEST['reload'])
+ ) {
+ $treeRender = $tree->renderState();
+ } else {
+ $treeRender = $tree->renderPath();
+ }
+
+ if (! $treeRender) {
+ $retval .= PMA_Message::error(
+ __('An error has occured while loading the navigation tree')
+ )->getDisplay();
+ } else {
+ $retval .= $treeRender;
+ }
+
+ if (! PMA_Response::getInstance()->isAjax()) {
+ // closes the tags that were opened by the navigation header
+ $retval .= '</div>';
+ $retval .= '</div>';
+ $retval .= '</div>';
+ }
+
+ return $retval;
+ }
+}
+?>
diff --git a/hugo/libraries/navigation/NavigationHeader.class.php b/hugo/libraries/navigation/NavigationHeader.class.php
new file mode 100644
index 0000000..adefeff
--- /dev/null
+++ b/hugo/libraries/navigation/NavigationHeader.class.php
@@ -0,0 +1,305 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Header for the navigation panel
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * This class renders the logo, links, server selection and recent tables,
+ * which are then displayed at the top of the naviagtion panel
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class PMA_NavigationHeader
+{
+ /**
+ * Renders the navigation
+ *
+ * @return void
+ */
+ public function getDisplay()
+ {
+ if (empty($GLOBALS['url_query'])) {
+ $GLOBALS['url_query'] = PMA_generate_common_url();
+ }
+ $link_url = PMA_generate_common_url(
+ array(
+ 'ajax_request' => true
+ )
+ );
+ $class = ' class="list_container';
+ if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
+ $class .= ' highlight';
+ }
+ $class .= '"';
+ $buffer = '<div id="pma_navigation">';
+ $buffer .= '<div id="pma_navigation_resizer"></div>';
+ $buffer .= '<div id="pma_navigation_collapser"></div>';
+ $buffer .= '<div id="pma_navigation_content">';
+ $buffer .= '<div id="pma_navigation_header">';
+ $buffer .= sprintf(
+ '<a class="hide navigation_url" href="navigation.php%s"></a>',
+ $link_url
+ );
+ $buffer .= $this->_logo();
+ $buffer .= $this->_links();
+ $buffer .= $this->_serverChoice();
+ $buffer .= $this->_recent();
+ $buffer .= PMA_Util::getImage(
+ 'ajax_clock_small.gif',
+ __('Loading'),
+ array('style' => 'visibility: hidden;', 'class' => 'throbber')
+ );
+ $buffer .= '</div>'; // pma_navigation_header
+ $buffer .= '<div id="pma_navigation_tree"' . $class . '>';
+ return $buffer;
+ }
+
+ /**
+ * Create the code for displaying the phpMyAdmin
+ * logo based on configuration settings
+ *
+ * @return string HTML code for the logo
+ */
+ private function _logo()
+ {
+ $retval = '<!-- LOGO START -->';
+ // display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
+ if ($GLOBALS['cfg']['NavigationDisplayLogo']) {
+ $logo = 'phpMyAdmin';
+ if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
+ $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" '
+ . 'alt="' . $logo . '" id="imgpmalogo" />';
+ } elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
+ $logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" '
+ . 'alt="' . $logo . '" id="imgpmalogo" />';
+ }
+ $retval .= '<div id="pmalogo">';
+ if ($GLOBALS['cfg']['NavigationLogoLink']) {
+ $logo_link = trim(htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink']));
+ // prevent XSS, see PMASA-2013-9
+ // if link has protocol, allow only http and https
+ if (preg_match('/^[a-z]+:/i', $logo_link)
+ && ! preg_match('/^https?:/i', $logo_link)) {
+ $logo_link = 'index.php';
+ }
+ $retval .= ' <a href="' . $logo_link;
+ switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
+ case 'new':
+ $retval .= '" target="_blank"';
+ break;
+ case 'main':
+ // do not add our parameters for an external link
+ if (substr(strtolower($GLOBALS['cfg']['NavigationLogoLink']), 0, 4) !== '://') {
+ $retval .= '?' . $GLOBALS['url_query'] . '"';
+ } else {
+ $retval .= '" target="_blank"';
+ }
+ }
+ $retval .= '>';
+ $retval .= $logo;
+ $retval .= '</a>';
+ } else {
+ $retval .= $logo;
+ }
+ $retval .= '</div>';
+ }
+ $retval .= '<!-- LOGO END -->';
+ return $retval;
+ }
+
+ /**
+ * Renders a single link for the top of the navigation panel
+ *
+ * @param string $link The url for the link
+ * @param bool $showText Whether to show the text or to
+ * only use it for title attributes
+ * @param string $text The text to display and use for title attributes
+ * @param bool $showIcon Whether to show the icon
+ * @param string $icon The filename of the icon to show
+ * @param string $linkId Value to use for the ID attribute
+ * @param string $disableAjax Whether to disable ajax page loading for this link
+ * @param string $linkTarget The name of the target frame for the link
+ *
+ * @return string HTML code for one link
+ */
+ private function _getLink(
+ $link,
+ $showText,
+ $text,
+ $showIcon,
+ $icon,
+ $linkId = '',
+ $disableAjax = false,
+ $linkTarget = ''
+ ) {
+ $retval = '<a href="' . $link . '"';
+ if (! empty($linkId)) {
+ $retval .= ' id="' . $linkId . '"';
+ }
+ if (! empty($linkTarget)) {
+ $retval .= ' target="' . $linkTarget . '"';
+ }
+ if ($disableAjax) {
+ $retval .= ' class="disableAjax"';
+ }
+ $retval .= ' title="' . $text . '">';
+ if ($showIcon) {
+ $retval .= PMA_Util::getImage(
+ $icon,
+ $text
+ );
+ }
+ if ($showText) {
+ $retval .= $text;
+ }
+ $retval .= '</a>';
+ if ($showText) {
+ $retval .= '<br />';
+ }
+ return $retval;
+ }
+
+ /**
+ * Creates the code for displaying the links
+ * at the top of the navigation frame
+ *
+ * @return string HTML code for the links
+ */
+ private function _links()
+ {
+ // always iconic
+ $showIcon = true;
+ $showText = false;
+
+ $retval = '<!-- LINKS START -->';
+ $retval .= '<div id="leftframelinks">';
+ $retval .= $this->_getLink(
+ 'index.php?' . PMA_generate_common_url(),
+ $showText,
+ __('Home'),
+ $showIcon,
+ 'b_home.png'
+ );
+ // if we have chosen server
+ if ($GLOBALS['server'] != 0) {
+ // Logout for advanced authentication
+ if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
+ $link = 'index.php?' . $GLOBALS['url_query'];
+ $link .= '&amp;old_usr=' . urlencode($GLOBALS['PHP_AUTH_USER']);
+ $retval .= $this->_getLink(
+ $link,
+ $showText,
+ __('Log out'),
+ $showIcon,
+ 's_loggoff.png',
+ '',
+ true
+ );
+ }
+ $link = 'querywindow.php?';
+ $link .= PMA_generate_common_url($GLOBALS['db'], $GLOBALS['table']);
+ $link .= '&amp;no_js=true';
+ $retval .= $this->_getLink(
+ $link,
+ $showText,
+ __('Query window'),
+ $showIcon,
+ 'b_selboard.png',
+ 'pma_open_querywindow',
+ true
+ );
+ }
+ $retval .= $this->_getLink(
+ PMA_Util::getDocuLink('index'),
+ $showText,
+ __('phpMyAdmin documentation'),
+ $showIcon,
+ 'b_docs.png',
+ '',
+ false,
+ 'documentation'
+ );
+ if ($showIcon) {
+ $retval .= PMA_Util::showMySQLDocu('', '', true);
+ }
+ if ($showText) {
+ // PMA_showMySQLDocu always spits out an icon,
+ // we just replace it with some perl regexp.
+ $link = preg_replace(
+ '/<img[^>]+>/i',
+ __('Documentation'),
+ PMA_Util::showMySQLDocu('', '', true)
+ );
+ $retval .= $link;
+ $retval .= '<br />';
+ }
+ $retval .= $this->_getLink(
+ '#',
+ $showText,
+ __('Reload navigation frame'),
+ $showIcon,
+ 's_reload.png',
+ 'pma_navigation_reload'
+ );
+ $retval .= '</div>';
+ $retval .= '<!-- LINKS ENDS -->';
+ return $retval;
+ }
+
+ /**
+ * Displays the MySQL servers choice form
+ *
+ * @return string HTML code for the MySQL servers choice
+ */
+ private function _serverChoice()
+ {
+ $retval = '';
+ if ($GLOBALS['cfg']['NavigationDisplayServers']
+ && count($GLOBALS['cfg']['Servers']) > 1
+ ) {
+ include_once './libraries/select_server.lib.php';
+ $retval .= '<!-- SERVER CHOICE START -->';
+ $retval .= '<div id="serverChoice">';
+ $retval .= PMA_selectServer(true, true);
+ $retval .= '</div>';
+ $retval .= '<!-- SERVER CHOICE END -->';
+ }
+ return $retval;
+ }
+
+ /**
+ * Displays a drop-down choice of most recently used tables
+ *
+ * @return string HTML code for the Recent tables
+ */
+ private function _recent()
+ {
+ $retval = '';
+ // display recently used tables
+ if ($GLOBALS['cfg']['NumRecentTables'] > 0) {
+ $retval .= '<!-- RECENT START -->';
+ $retval .= '<div id="recentTableList">';
+ $retval .= '<form method="post" ';
+ $retval .= 'action="' . $GLOBALS['cfg']['DefaultTabTable'] . '">';
+ $retval .= PMA_generate_common_hidden_inputs(
+ array(
+ 'db' => '',
+ 'table' => '',
+ 'server' => $GLOBALS['server']
+ )
+ );
+ $retval .= PMA_RecentTable::getInstance()->getHtmlSelect();
+ $retval .= '</form>';
+ $retval .= '</div>';
+ $retval .= '<!-- RECENT END -->';
+ }
+ return $retval;
+ }
+}
+?>
diff --git a/hugo/libraries/navigation/NavigationTree.class.php b/hugo/libraries/navigation/NavigationTree.class.php
new file mode 100644
index 0000000..24eaf93
--- /dev/null
+++ b/hugo/libraries/navigation/NavigationTree.class.php
@@ -0,0 +1,1146 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Displays a collapsible of database objects in the navigation frame
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class PMA_NavigationTree
+{
+ /**
+ * @var Node Reference to the root node of the tree
+ */
+ private $_tree;
+
+ /**
+ * @var array The actual paths to all expanded nodes in the tree
+ * This does not include nodes created after the grouping
+ * of nodes has been performed
+ */
+ private $_aPath = array();
+
+ /**
+ * @var array The virtual paths to all expanded nodes in the tree
+ * This includes nodes created after the grouping of
+ * nodes has been performed
+ */
+ private $_vPath = array();
+
+ /**
+ * @var int Position in the list of databases,
+ * used for pagination
+ */
+ private $_pos;
+
+ /**
+ * @var int The names of the type of items that are being paginated on
+ * the second level of the navigation tree. These may be
+ * tables, views, functions, procedures or events.
+ */
+ private $_pos2_name = array();
+
+ /**
+ * @var int The positions of nodes in the lists of tables, views,
+ * routines or events used for pagination
+ */
+ private $_pos2_value = array();
+
+ /**
+ * @var int The names of the type of items that are being paginated
+ * on the second level of the navigation tree.
+ * These may be columns or indexes
+ */
+ private $_pos3_name = array();
+
+ /**
+ * @var int The positions of nodes in the lists of columns or indexes
+ * used for pagination
+ */
+ private $_pos3_value = array();
+
+ /**
+ * @var string The search clause to use in SQL queries for
+ * fetching databases
+ * Used by the asynchronous fast filter
+ */
+ private $_searchClause = '';
+
+ /**
+ * @var string The search clause to use in SQL queries for
+ * fetching nodes
+ * Used by the asynchronous fast filter
+ */
+ private $_searchClause2 = '';
+
+ /**
+ * Initialises the class
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ // Save the position at which we are in the database list
+ if (isset($_REQUEST['pos'])) {
+ $this->_pos = (int) $_REQUEST['pos'];
+ }
+ if (! isset($this->_pos)) {
+ $this->_pos = $this->_getNavigationDbPos();
+ }
+ // Get the active node
+ if (isset($_REQUEST['aPath'])) {
+ $this->_aPath[0] = $this->_parsePath($_REQUEST['aPath']);
+ $this->_pos2_name[0] = $_REQUEST['pos2_name'];
+ $this->_pos2_value[0] = $_REQUEST['pos2_value'];
+ if (isset($_REQUEST['pos3_name'])) {
+ $this->_pos3_name[0] = $_REQUEST['pos3_name'];
+ $this->_pos3_value[0] = $_REQUEST['pos3_value'];
+ }
+ } else if (isset($_REQUEST['n0_aPath'])) {
+ $count = 0;
+ while (isset($_REQUEST['n' . $count . '_aPath'])) {
+ $this->_aPath[$count] = $this->_parsePath(
+ $_REQUEST['n' . $count . '_aPath']
+ );
+ $index = 'n' . $count . '_pos2_';
+ $this->_pos2_name[$count] = $_REQUEST[$index . 'name'];
+ $this->_pos2_value[$count] = $_REQUEST[$index . 'value'];
+ $index = 'n' . $count . '_pos3_';
+ if (isset($_REQUEST[$index])) {
+ $this->_pos3_name[$count] = $_REQUEST[$index . 'name'];
+ $this->_pos3_value[$count] = $_REQUEST[$index . 'value'];
+ }
+ $count++;
+ }
+ }
+ if (isset($_REQUEST['vPath'])) {
+ $this->_vPath[0] = $this->_parsePath($_REQUEST['vPath']);
+ } else if (isset($_REQUEST['n0_vPath'])) {
+ $count = 0;
+ while (isset($_REQUEST['n' . $count . '_vPath'])) {
+ $this->_vPath[$count] = $this->_parsePath(
+ $_REQUEST['n' . $count . '_vPath']
+ );
+ $count++;
+ }
+ }
+ if (isset($_REQUEST['searchClause'])) {
+ $this->_searchClause = $_REQUEST['searchClause'];
+ }
+ if (isset($_REQUEST['searchClause2'])) {
+ $this->_searchClause2 = $_REQUEST['searchClause2'];
+ }
+ // Initialise the tree by creating a root node
+ $node = PMA_NodeFactory::getInstance('Node', 'root', Node::CONTAINER);
+ $this->_tree = $node;
+ if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
+ $this->_tree->separator = $GLOBALS['cfg']['NavigationTreeDbSeparator'];
+ $this->_tree->separator_depth = 10000;
+ }
+ }
+
+ /**
+ * Returns the database position for the page selector
+ *
+ * @return int
+ */
+ private function _getNavigationDbPos()
+ {
+ $retval = 0;
+ if (! empty($GLOBALS['db'])) {
+ $query = "SELECT (COUNT(`SCHEMA_NAME`) DIV %d) * %d ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
+ $query .= "WHERE `SCHEMA_NAME` < '%s' ";
+ $query .= "ORDER BY `SCHEMA_NAME` ASC";
+ $retval = PMA_DBI_fetch_value(
+ sprintf(
+ $query,
+ (int)$GLOBALS['cfg']['MaxNavigationItems'],
+ (int)$GLOBALS['cfg']['MaxNavigationItems'],
+ PMA_Util::sqlAddSlashes($GLOBALS['db'])
+ )
+ );
+ }
+ return $retval;
+ }
+
+ /**
+ * Converts an encoded path to a node in string format to an array
+ *
+ * @param string $string The path to parse
+ *
+ * @return array
+ */
+ private function _parsePath($string)
+ {
+ $path = explode('.', $string);
+ foreach ($path as $key => $value) {
+ $path[$key] = base64_decode($value);
+ }
+ return $path;
+ }
+
+ /**
+ * Generates the tree structure so that it can be rendered later
+ *
+ * @return Node|false The active node or false in case of failure
+ */
+ private function _buildPath()
+ {
+ $retval = $this->_tree;
+
+ // Add all databases unconditionally
+ $data = $this->_tree->getData(
+ 'databases',
+ $this->_pos,
+ $this->_searchClause
+ );
+ foreach ($data as $db) {
+ $node = PMA_NodeFactory::getInstance('Node_Database', $db);
+ $this->_tree->addChild($node);
+ }
+
+ // Whether build other parts of the tree depends
+ // on whether we have any paths in $this->_aPath
+ foreach ($this->_aPath as $key => $path) {
+ $retval = $this->_buildPathPart(
+ $path,
+ $this->_pos2_name[$key],
+ $this->_pos2_value[$key],
+ isset($this->_pos3_name[$key]) ? $this->_pos3_name[$key] : '',
+ isset($this->_pos3_value[$key]) ? $this->_pos3_value[$key] : ''
+ );
+ }
+ return $retval;
+ }
+
+ /**
+ * Builds a branch of the tree
+ *
+ * @param array $path A paths pointing to the branch
+ * of the tree that needs to be built
+ * @param string $type2 The type of item being paginated on
+ * the second level of the tree
+ * @param int $pos2 The position for the pagination of
+ * the branch at the second level of the tree
+ * @param string $type3 The type of item being paginated on
+ * the third level of the tree
+ * @param int $pos3 The position for the pagination of
+ * the branch at the third level of the tree
+ *
+ * @return Node|false The active node or false in case of failure
+ */
+ private function _buildPathPart($path, $type2, $pos2, $type3, $pos3)
+ {
+ $retval = true;
+ if (count($path) > 1) {
+ array_shift($path); // remove 'root'
+ $db = $this->_tree->getChild($path[0]);
+ $retval = $db;
+
+ if ($db === false) {
+ return false;
+ }
+
+ $containers = $this->_addDbContainers($db, $type2, $pos2);
+
+ array_shift($path); // remove db
+
+ if ((count($path) > 0
+ && array_key_exists($path[0], $containers))
+ || count($containers) == 1
+ ) {
+ if (count($containers) == 1) {
+ $container = array_shift($containers);
+ } else {
+ $container = $db->getChild($path[0], true);
+ if ($container === false) {
+ return false;
+ }
+ }
+ $retval = $container;
+
+ if (count($container->children) <= 1) {
+ $dbData = $db->getData(
+ $container->real_name,
+ $pos2,
+ $this->_searchClause2
+ );
+ foreach ($dbData as $item) {
+ switch ($container->real_name) {
+ case 'events':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Event',
+ $item
+ );
+ break;
+ case 'functions':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Function',
+ $item
+ );
+ break;
+ case 'procedures':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Procedure',
+ $item
+ );
+ break;
+ case 'tables':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Table',
+ $item
+ );
+ break;
+ case 'views':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_View',
+ $item
+ );
+ break;
+ default:
+ break;
+ }
+ if (isset($node)) {
+ if ($type2 == $container->real_name) {
+ $node->pos2 = $pos2;
+ }
+ $container->addChild($node);
+ }
+ }
+ }
+ if (count($path) > 1 && $path[0] != 'tables') {
+ $retval = false;
+ } else {
+ array_shift($path); // remove container
+ if (count($path) > 0) {
+ $table = $container->getChild($path[0], true);
+ if ($table === false) {
+ return false;
+ }
+ $retval = $table;
+ $containers = $this->_addTableContainers(
+ $table,
+ $pos2,
+ $type3,
+ $pos3
+ );
+ array_shift($path); // remove table
+ if (count($path) > 0
+ && array_key_exists($path[0], $containers)
+ ) {
+ $container = $table->getChild($path[0], true);
+ $retval = $container;
+ $tableData = $table->getData(
+ $container->real_name,
+ $pos3
+ );
+ foreach ($tableData as $item) {
+ switch ($container->real_name) {
+ case 'indexes':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Index',
+ $item
+ );
+ break;
+ case 'columns':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Column',
+ $item
+ );
+ break;
+ case 'triggers':
+ $node = PMA_NodeFactory::getInstance(
+ 'Node_Trigger',
+ $item
+ );
+ break;
+ default:
+ break;
+ }
+ if (isset($node)) {
+ $node->pos2 = $container->parent->pos2;
+ if ($type3 == $container->real_name) {
+ $node->pos3 = $pos3;
+ }
+ $container->addChild($node);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Adds containers to a node that is a table
+ *
+ * References to existing children are returned
+ * if this function is called twice on the same node
+ *
+ * @param Node $table The table node, new containers will be
+ * attached to this node
+ * @param int $pos2 The position for the pagination of
+ * the branch at the second level of the tree
+ * @param string $type3 The type of item being paginated on
+ * the third level of the tree
+ * @param int $pos3 The position for the pagination of
+ * the branch at the third level of the tree
+ *
+ * @return array An array of new nodes
+ */
+ private function _addTableContainers($table, $pos2, $type3, $pos3)
+ {
+ $retval = array();
+ if ($table->hasChildren(true) == 0) {
+ if ($table->getPresence('columns')) {
+ $retval['columns'] = PMA_NodeFactory::getInstance(
+ 'Node_Column_Container'
+ );
+ }
+ if ($table->getPresence('indexes')) {
+ $retval['indexes'] = PMA_NodeFactory::getInstance(
+ 'Node_Index_Container'
+ );
+ }
+ if ($table->getPresence('triggers')) {
+ $retval['triggers'] = PMA_NodeFactory::getInstance(
+ 'Node_Trigger_Container'
+ );
+ }
+ // Add all new Nodes to the tree
+ foreach ($retval as $node) {
+ $node->pos2 = $pos2;
+ if ($type3 == $node->real_name) {
+ $node->pos3 = $pos3;
+ }
+ $table->addChild($node);
+ }
+ } else {
+ foreach ($table->children as $node) {
+ if ($type3 == $node->real_name) {
+ $node->pos3 = $pos3;
+ }
+ $retval[$node->real_name] = $node;
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Adds containers to a node that is a database
+ *
+ * References to existing children are returned
+ * if this function is called twice on the same node
+ *
+ * @param Node $db The database node, new containers will be
+ * attached to this node
+ * @param string $type The type of item being paginated on
+ * the second level of the tree
+ * @param int $pos2 The position for the pagination of
+ * the branch at the second level of the tree
+ *
+ * @return array An array of new nodes
+ */
+ private function _addDbContainers($db, $type, $pos2)
+ {
+ $retval = array();
+ if ($db->hasChildren(true) == 0) {
+ if ($db->getPresence('tables')) {
+ $retval['tables'] = PMA_NodeFactory::getInstance(
+ 'Node_Table_Container'
+ );
+ }
+ if ($db->getPresence('views')) {
+ $retval['views'] = PMA_NodeFactory::getInstance(
+ 'Node_View_Container'
+ );
+ }
+ if ($db->getPresence('functions')) {
+ $retval['functions'] = PMA_NodeFactory::getInstance(
+ 'Node_Function_Container'
+ );
+ }
+ if ($db->getPresence('procedures')) {
+ $retval['procedures'] = PMA_NodeFactory::getInstance(
+ 'Node_Procedure_Container'
+ );
+ }
+ if ($db->getPresence('events')) {
+ $retval['events'] = PMA_NodeFactory::getInstance(
+ 'Node_Event_Container'
+ );
+ }
+ // Add all new Nodes to the tree
+ foreach ($retval as $node) {
+ if ($type == $node->real_name) {
+ $node->pos2 = $pos2;
+ }
+ $db->addChild($node);
+ }
+ } else {
+ foreach ($db->children as $node) {
+ if ($type == $node->real_name) {
+ $node->pos2 = $pos2;
+ }
+ $retval[$node->real_name] = $node;
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Recursively groups tree nodes given a separator
+ *
+ * @param mixed $node The node to group or null
+ * to group the whole tree. If
+ * passed as an argument, $node
+ * must be of type CONTAINER
+ *
+ * @return void
+ */
+ public function groupTree($node = null)
+ {
+ if (! isset($node)) {
+ $node = $this->_tree;
+ }
+ $this->groupNode($node);
+ foreach ($node->children as $child) {
+ $this->groupTree($child);
+ }
+ }
+
+ /**
+ * Recursively groups tree nodes given a sperarator
+ *
+ * @param Node $node The node to group
+ *
+ * @return void
+ */
+ public function groupNode($node)
+ {
+ if ($node->type == Node::CONTAINER) {
+ $separators = array();
+ if (is_array($node->separator)) {
+ $separators = $node->separator;
+ } else if (strlen($node->separator)) {
+ $separators[] = $node->separator;
+ }
+ $prefixes = array();
+ if ($node->separator_depth > 0) {
+ foreach ($node->children as $child) {
+ $prefix_pos = false;
+ foreach ($separators as $separator) {
+ $sep_pos = strpos($child->name, $separator);
+ if ($sep_pos != false
+ && $sep_pos != strlen($child->name)
+ && $sep_pos != 0
+ && ($prefix_pos == false || $sep_pos < $prefix_pos)
+ ) {
+ $prefix_pos = $sep_pos;
+ }
+ }
+ if ($prefix_pos !== false) {
+ $prefix = substr($child->name, 0, $prefix_pos);
+ if (! isset($prefixes[$prefix])) {
+ $prefixes[$prefix] = 1;
+ } else {
+ $prefixes[$prefix]++;
+ }
+ }
+ }
+ }
+ foreach ($prefixes as $key => $value) {
+ if ($value == 1) {
+ unset($prefixes[$key]);
+ }
+ }
+ if (count($prefixes)) {
+ $groups = array();
+ foreach ($prefixes as $key => $value) {
+ $groups[$key] = new Node(
+ $key,
+ Node::CONTAINER,
+ true
+ );
+ $groups[$key]->separator = $node->separator;
+ $groups[$key]->separator_depth = $node->separator_depth - 1;
+ $groups[$key]->icon = '';
+ if (in_array(
+ $GLOBALS['cfg']['TableNavigationLinksMode'],
+ array('icons', 'both')
+ )
+ ) {
+ $groups[$key]->icon = PMA_Util::getImage(
+ 'b_group.png'
+ );
+ }
+ $groups[$key]->pos2 = $node->pos2;
+ $groups[$key]->pos3 = $node->pos3;
+ $node->addChild($groups[$key]);
+ foreach ($separators as $separator) {
+ // FIXME: this could be more efficient
+ foreach ($node->children as $child) {
+ $name_substring = substr(
+ $child->name, 0, strlen($key) + strlen($separator)
+ );
+ if ($name_substring == $key . $separator
+ && $child->type == Node::OBJECT
+ ) {
+ $class = get_class($child);
+ $new_child = PMA_NodeFactory::getInstance(
+ $class,
+ substr(
+ $child->name,
+ strlen($key) + strlen($separator)
+ )
+ );
+ $new_child->real_name = $child->real_name;
+ $new_child->icon = $child->icon;
+ $new_child->links = $child->links;
+ $new_child->pos2 = $child->pos2;
+ $new_child->pos3 = $child->pos3;
+ $groups[$key]->addChild($new_child);
+ foreach ($child->children as $elm) {
+ $new_child->addChild($elm);
+ }
+ $node->removeChild($child->name);
+ }
+ }
+ }
+ }
+ foreach ($prefixes as $key => $value) {
+ $this->groupNode($groups[$key]);
+ $groups[$key]->classes = "navGroup";
+ }
+ }
+ }
+ }
+
+ /**
+ * Renders a state of the tree, used in light mode when
+ * either JavaScript and/or Ajax are disabled
+ *
+ * @return string HTML code for the navigation tree
+ */
+ public function renderState()
+ {
+ $this->_buildPath();
+ $retval = $this->_fastFilterHtml($this->_tree);
+ $retval .= $this->_getPageSelector($this->_tree);
+ $this->groupTree();
+ $retval .= "<div id='pma_navigation_tree_content'><ul>";
+ $children = $this->_tree->children;
+ usort($children, array('PMA_NavigationTree', 'sortNode'));
+ $this->_setVisibility();
+ for ($i=0; $i<count($children); $i++) {
+ if ($i == 0) {
+ $retval .= $this->_renderNode($children[0], true, 'first');
+ } else if ($i + 1 != count($children)) {
+ $retval .= $this->_renderNode($children[$i], true);
+ } else {
+ $retval .= $this->_renderNode($children[$i], true, 'last');
+ }
+ }
+ $retval .= "</ul></div>";
+ return $retval;
+ }
+
+ /**
+ * Renders a part of the tree, used for Ajax
+ * requests in light mode
+ *
+ * @return string HTML code for the navigation tree
+ */
+ public function renderPath()
+ {
+ $node = $this->_buildPath();
+ if ($node === false) {
+ $retval = false;
+ } else {
+ $this->groupTree();
+ $retval = "<div class='list_container' style='display: none;'>";
+ $retval .= "<ul>";
+ $retval .= $this->_fastFilterHtml($node);
+ $retval .= $this->_getPageSelector($node);
+ $children = $node->children;
+ usort($children, array('PMA_NavigationTree', 'sortNode'));
+ for ($i=0; $i<count($children); $i++) {
+ if ($i + 1 != count($children)) {
+ $retval .= $this->_renderNode($children[$i], true);
+ } else {
+ $retval .= $this->_renderNode($children[$i], true, 'last');
+ }
+ }
+ $retval .= "</ul>";
+ $retval .= "</div>";
+ }
+
+ if (! empty($this->_searchClause) || ! empty($this->_searchClause2)) {
+ if (! empty($this->_searchClause2)) {
+ $results = $node->realParent()->getPresence(
+ $node->real_name,
+ $this->_searchClause2
+ );
+ } else {
+ $results = $this->_tree->getPresence(
+ 'databases',
+ $this->_searchClause
+ );
+ }
+
+ $clientResults = 0;
+ if (! empty($_REQUEST['results'])) {
+ $clientResults = (int)$_REQUEST['results'];
+ }
+ $otherResults = $results - $clientResults;
+ if ($otherResults < 1) {
+ $otherResults = '';
+ } else {
+ $otherResults = sprintf(
+ _ngettext(
+ '%s other result found',
+ '%s other results found',
+ $otherResults
+ ),
+ $otherResults
+ );
+ }
+ PMA_Response::getInstance()->addJSON(
+ 'results',
+ $otherResults
+ );
+ }
+ return $retval;
+ }
+
+ /**
+ * Renders the parameters that are required on the client
+ * side to know which page(s) we will be requesting data from
+ *
+ * @param Node $node The node to create the pagination parameters for
+ *
+ * @return string
+ */
+ private function _getPaginationParamsHtml($node)
+ {
+ $retval = '';
+ $paths = $node->getPaths();
+ if (isset($paths['aPath_clean'][2])) {
+ $retval .= "<span class='hide pos2_name'>";
+ $retval .= $paths['aPath_clean'][2];
+ $retval .= "</span>";
+ $retval .= "<span class='hide pos2_value'>";
+ $retval .= $node->pos2;
+ $retval .= "</span>";
+ }
+ if (isset($paths['aPath_clean'][4])) {
+ $retval .= "<span class='hide pos3_name'>";
+ $retval .= $paths['aPath_clean'][4];
+ $retval .= "</span>";
+ $retval .= "<span class='hide pos3_value'>";
+ $retval .= $node->pos3;
+ $retval .= "</span>";
+ }
+ return $retval;
+ }
+
+ /**
+ * Renders a single node or a branch of the tree
+ *
+ * @param Node $node The node to render
+ * @param int|bool $recursive Bool: Whether to render a single node or a branch
+ * Int: How many levels deep to render
+ * @param string $class An additional class for the list item
+ *
+ * @return string HTML code for the tree node or branch
+ */
+ private function _renderNode($node, $recursive = -1, $class = '')
+ {
+ $retval = '';
+ $paths = $node->getPaths();
+ if ($node->hasSiblings()
+ || isset($_REQUEST['results'])
+ || $node->realParent() === false
+ ) {
+ if ( $node->type == Node::CONTAINER
+ && count($node->children) == 0
+ && $GLOBALS['is_ajax_request'] != true
+ ) {
+ return '';
+ }
+ $liClass = '';
+ if ($class || $node->classes) {
+ $liClass = " class='" . trim($class . ' ' . $node->classes) . "'";
+ }
+ $retval .= "<li$liClass>";
+ $sterile = array(
+ 'events',
+ 'triggers',
+ 'functions',
+ 'procedures',
+ 'views',
+ 'columns',
+ 'indexes'
+ );
+ $parentName = '';
+ $parents = $node->parents(false, true);
+ if (count($parents)) {
+ $parentName = $parents[0]->real_name;
+ }
+ if ($node->is_group
+ || (! in_array($parentName, $sterile) && ! $node->isNew)
+ ) {
+ $loaded = '';
+ if ($node->is_group) {
+ $loaded = ' loaded';
+ }
+ $container = '';
+ if ($node->type == Node::CONTAINER) {
+ $container = ' container';
+ }
+ $retval .= "<div class='block'>";
+ $iClass = '';
+ if ($class == 'first') {
+ $iClass = " class='first'";
+ }
+ $retval .= "<i$iClass></i>";
+ if (strpos($class, 'last') === false) {
+ $retval .= "<b></b>";
+ }
+ $icon = PMA_Util::getImage('b_plus.png');
+ $match = 1;
+ foreach ($this->_aPath as $path) {
+ $match = 1;
+ foreach ($paths['aPath_clean'] as $key => $part) {
+ if (! isset($path[$key]) || $part != $path[$key]) {
+ $match = 0;
+ break;
+ }
+ }
+ if ($match) {
+ $loaded = ' loaded';
+ if (! $node->is_group) {
+ $icon = PMA_Util::getImage(
+ 'b_minus.png'
+ );
+ }
+ break;
+ }
+ }
+
+ foreach ($this->_vPath as $path) {
+ $match = 1;
+ foreach ($paths['vPath_clean'] as $key => $part) {
+ if ((! isset($path[$key]) || $part != $path[$key])) {
+ $match = 0;
+ break;
+ }
+ }
+ if ($match) {
+ $loaded = ' loaded';
+ $icon = PMA_Util::getImage('b_minus.png');
+ break;
+ }
+ }
+
+ $retval .= "<a class='expander$loaded$container'";
+ $retval .= " href='#'>";
+ $retval .= "<span class='hide aPath'>";
+ $retval .= $paths['aPath'];
+ $retval .= "</span>";
+ $retval .= "<span class='hide vPath'>";
+ $retval .= $paths['vPath'];
+ $retval .= "</span>";
+ $retval .= "<span class='hide pos'>";
+ $retval .= $this->_pos;
+ $retval .= "</span>";
+ $retval .= $this->_getPaginationParamsHtml($node);
+ $retval .= $icon;
+
+ $retval .= "</a>";
+ $retval .= "</div>";
+ } else {
+ $retval .= "<div class='block'>";
+ $iClass = '';
+ if ($class == 'first') {
+ $iClass = " class='first'";
+ }
+ $retval .= "<i$iClass></i>";
+ $retval .= $this->_getPaginationParamsHtml($node);
+ $retval .= "</div>";
+ }
+
+ $linkClass = '';
+ $haveAjax = array(
+ 'functions',
+ 'procedures',
+ 'events',
+ 'triggers',
+ 'indexes'
+ );
+ $parent = $node->parents(false, true);
+ if ($parent[0]->type == Node::CONTAINER
+ && (in_array($parent[0]->real_name, $haveAjax)
+ || ($parent[0]->real_name == 'views'
+ && $node->isNew == true
+ )
+ )
+ ) {
+ $linkClass = ' class="ajax"';
+ }
+
+ if ($node->type == Node::CONTAINER) {
+ $retval .= "<i>";
+ }
+ if (in_array(
+ $GLOBALS['cfg']['TableNavigationLinksMode'],
+ array('icons', 'both')
+ )
+ ) {
+ $retval .= "<div class='block'>";
+ if (isset($node->links['icon'])) {
+ $args = array();
+ foreach ($node->parents(true) as $parent) {
+ $args[] = urlencode($parent->real_name);
+ }
+ $link = vsprintf($node->links['icon'], $args);
+ $retval .= "<a$linkClass href='$link'>{$node->icon}</a>";
+ } else {
+ $retval .= "<u>{$node->icon}</u>";
+ }
+ $retval .= "</div>";
+ }
+ if (isset($node->links['text'])) {
+ $args = array();
+ foreach ($node->parents(true) as $parent) {
+ $args[] = urlencode($parent->real_name);
+ }
+ $link = vsprintf($node->links['text'], $args);
+ if ($node->type == Node::CONTAINER) {
+ $retval .= "<a href='$link'>";
+ $retval .= htmlspecialchars($node->name);
+ $retval .= "</a>";
+ } else {
+ $retval .= "<a$linkClass href='$link'>";
+ $retval .= htmlspecialchars($node->real_name);
+ $retval .= "</a>";
+ }
+ } else {
+ $retval .= "{$node->name}";
+ }
+ if ($node->type == Node::CONTAINER) {
+ $retval .= "</i>";
+ }
+ $wrap = true;
+ } else {
+ $node->visible = true;
+ $wrap = false;
+ $retval .= $this->_getPaginationParamsHtml($node);
+ }
+
+ if ($recursive) {
+ $hide = '';
+ if ($node->visible == false) {
+ $hide = " style='display: none;'";
+ }
+ $children = $node->children;
+ usort($children, array('PMA_NavigationTree', 'sortNode'));
+ $buffer = '';
+ for ($i=0; $i<count($children); $i++) {
+ if ($i + 1 != count($children)) {
+ $buffer .= $this->_renderNode(
+ $children[$i],
+ true,
+ $children[$i]->classes
+ );
+ } else {
+ $buffer .= $this->_renderNode(
+ $children[$i],
+ true,
+ $children[$i]->classes . ' last'
+ );
+ }
+ }
+ if (! empty($buffer)) {
+ if ($wrap) {
+ $retval .= "<div$hide class='list_container'><ul>";
+ }
+ $retval .= $this->_fastFilterHtml($node);
+ $retval .= $this->_getPageSelector($node);
+ $retval .= $buffer;
+ if ($wrap) {
+ $retval .= "</ul></div>";
+ }
+ }
+ }
+ if ($node->hasSiblings() || isset($_REQUEST['results'])) {
+ $retval .= "</li>";
+ }
+ return $retval;
+ }
+
+ /**
+ * Makes some nodes visible based on the which node is active
+ *
+ * @return nothing
+ */
+ private function _setVisibility()
+ {
+ foreach ($this->_vPath as $path) {
+ $node = $this->_tree;
+ foreach ($path as $value) {
+ $child = $node->getChild($value);
+ if ($child !== false) {
+ $child->visible = true;
+ $node = $child;
+ }
+ }
+ }
+ }
+
+ /**
+ * Generates the HTML code for displaying the fast filter for tables
+ *
+ * @param Node $node The node for which to generate the fast filter html
+ *
+ * @return string LI element used for the fast filter
+ */
+ private function _fastFilterHtml($node)
+ {
+ $retval = '';
+ if ($node === $this->_tree
+ && $this->_tree->getPresence() >= (int)$GLOBALS['cfg']['NavigationTreeDisplayDbFilterMinimum']
+ ) {
+ $url_params = array(
+ 'pos' => 0
+ );
+ $retval .= "<ul>";
+ $retval .= "<li class='fast_filter db_fast_filter'>";
+ $retval .= "<form class='ajax fast_filter'>";
+ $retval .= PMA_getHiddenFields($url_params);
+ $retval .= "<input class='searchClause' name='searchClause'";
+ $retval .= " value='" . __('filter databases by name') . "' />";
+ $retval .= "<span title='" . __('Clear Fast Filter') . "'>X</span>";
+ $retval .= "</form>";
+ $retval .= "</li>";
+ $retval .= "</ul>";
+ } else if (($node->type == Node::CONTAINER
+ && ( $node->real_name == 'tables'
+ || $node->real_name == 'views'
+ || $node->real_name == 'functions'
+ || $node->real_name == 'procedures'
+ || $node->real_name == 'events')
+ )
+ && $node->realParent()->getPresence($node->real_name) >= (int)$GLOBALS['cfg']['NavigationTreeDisplayItemFilterMinimum']
+ ) {
+ $paths = $node->getPaths();
+ $url_params = array(
+ 'pos' => $this->_pos,
+ 'aPath' => $paths['aPath'],
+ 'vPath' => $paths['vPath'],
+ 'pos2_name' => $node->real_name,
+ 'pos2_value' => 0
+ );
+ $retval .= "<li class='fast_filter'>";
+ $retval .= "<form class='ajax fast_filter'>";
+ $retval .= PMA_getHiddenFields($url_params);
+ $retval .= "<input class='searchClause' name='searchClause2'";
+ $retval .= " value='" . __('filter items by name') . "' />";
+ $retval .= "<span title='" . __('Clear Fast Filter') . "'>X</span>";
+ $retval .= "</form>";
+ $retval .= "</li>";
+ }
+ return $retval;
+ }
+
+ /**
+ * Generates the HTML code for displaying the list pagination
+ *
+ * @param Node $node The node for whose children the page
+ * selector will be created
+ *
+ * @return string
+ */
+ private function _getPageSelector($node)
+ {
+ $retval = '';
+ if ($node === $this->_tree) {
+ $retval .= PMA_Util::getListNavigator(
+ $this->_tree->getPresence('databases', $this->_searchClause),
+ $this->_pos,
+ array('server' => $GLOBALS['server']),
+ 'navigation.php',
+ 'frame_navigation',
+ $GLOBALS['cfg']['MaxNavigationItems'],
+ 'pos',
+ array('dbselector')
+ );
+ } else if ($node->type == Node::CONTAINER && ! $node->is_group) {
+ $paths = $node->getPaths();
+
+ $level = isset($paths['aPath_clean'][4]) ? 3 : 2;
+ $_url_params = array(
+ 'aPath' => $paths['aPath'],
+ 'vPath' => $paths['vPath'],
+ 'pos' => $this->_pos,
+ 'server' => $GLOBALS['server'],
+ 'pos2_name' => $paths['aPath_clean'][2]
+ );
+ if ($level == 3) {
+ $pos = $node->pos3;
+ $_url_params['pos2_value'] = $node->pos2;
+ $_url_params['pos3_name'] = $paths['aPath_clean'][4];
+ } else {
+ $pos = $node->pos2;
+ }
+ $num = $node->realParent()->getPresence(
+ $node->real_name,
+ $this->_searchClause2
+ );
+ $retval .= PMA_Util::getListNavigator(
+ $num,
+ $pos,
+ $_url_params,
+ 'navigation.php',
+ 'frame_navigation',
+ $GLOBALS['cfg']['MaxNavigationItems'],
+ 'pos' . $level . '_value'
+ );
+ }
+ return $retval;
+ }
+
+ /**
+ * Called by usort() for sorting the nodes in a container
+ *
+ * @param Node $a The first element used in the comparison
+ * @param Node $b The second element used in the comparison
+ *
+ * @return int See strnatcmp() and strcmp()
+ */
+ static public function sortNode($a, $b)
+ {
+ if ($a->isNew) {
+ return -1;
+ } else if ($b->isNew) {
+ return 1;
+ }
+ if ($GLOBALS['cfg']['NaturalOrder']) {
+ return strnatcasecmp($a->name, $b->name);
+ } else {
+ return strcasecmp($a->name, $b->name);
+ }
+ }
+}
+?>
diff --git a/hugo/libraries/navigation/NodeFactory.class.php b/hugo/libraries/navigation/NodeFactory.class.php
new file mode 100644
index 0000000..7d8106a
--- /dev/null
+++ b/hugo/libraries/navigation/NodeFactory.class.php
@@ -0,0 +1,97 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * This class is responsible for creating Node objects
+ *
+ * @package PhpMyAdmin-navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+require_once 'libraries/navigation/Nodes/Node.class.php';
+
+/**
+ * Node factory - instanciates Node objects or objects derived from the Node class
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class PMA_NodeFactory
+{
+ /**
+ * @var string $_path A template for generating paths to files
+ * that contain various Node classes
+ * @access private
+ */
+ private static $_path = 'libraries/navigation/Nodes/%s.class.php';
+ /**
+ * Sanitizes the name of a Node class
+ *
+ * @param string $class The class name to be sanitized
+ *
+ * @return string
+ */
+ private static function _sanitizeClass($class)
+ {
+ if ($class !== 'Node' && ! preg_match('@^Node_\w+(_\w+)?$@', $class)) {
+ $class = 'Node';
+ trigger_error(
+ sprintf(
+ /* l10n: The word "Node" must not be translated here */
+ __('Invalid class name "%1$s", using default of "Node"'),
+ $class
+ ),
+ E_USER_ERROR
+ );
+ }
+ return self::_checkFile($class);
+ }
+ /**
+ * Checks if a file exists for a given class name
+ * Will return the default class name back if the
+ * file for some subclass is not available
+ *
+ * @param string $class The class name to check
+ *
+ * @return string
+ */
+ private static function _checkFile($class)
+ {
+ $path = sprintf(self::$_path, $class);
+ if (! is_readable($path)) {
+ $class = 'Node';
+ trigger_error(
+ sprintf(
+ __('Could not include class "%1$s", file "%2$s" not found'),
+ $class,
+ 'Nodes/' . $class . '.class.php'
+ ),
+ E_USER_ERROR
+ );
+ }
+ return $class;
+ }
+ /**
+ * Instanciates a Node object
+ *
+ * @param string $class The name of the class to instanciate
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return string
+ */
+ public static function getInstance(
+ $class = 'Node',
+ $name = 'default',
+ $type = Node::OBJECT,
+ $is_group = false
+ ) {
+ $class = self::_sanitizeClass($class);
+ include_once sprintf(self::$_path, $class);
+ return new $class($name, $type, $is_group);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node.class.php b/hugo/libraries/navigation/Nodes/Node.class.php
new file mode 100644
index 0000000..c7593bb
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node.class.php
@@ -0,0 +1,444 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree in the left frame
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * The Node is the building block for the collapsible navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node
+{
+ /**
+ * @var int Defines a possible node type
+ */
+ const CONTAINER = 0;
+
+ /**
+ * @var int Defines a possible node type
+ */
+ const OBJECT = 1;
+
+ /**
+ * @var string A non-unique identifier for the node
+ * This may be trimmed when grouping nodes
+ */
+ public $name = "";
+
+ /**
+ * @var string A non-unique identifier for the node
+ * This will never change after being assigned
+ */
+ public $real_name = "";
+
+ /**
+ * @var int May be one of CONTAINER or OBJECT
+ */
+ public $type = Node::OBJECT;
+
+ /**
+ * @var bool Whether this object has been created while grouping nodes
+ * Only relevant if the node is of type CONTAINER
+ */
+ public $is_group;
+
+ /**
+ * @var bool Whether to add a "display: none;" CSS
+ * rule to the node when rendering it
+ */
+ public $visible = false;
+
+ /**
+ * @var Node A reference to the parent object of
+ * this node, NULL for the root node.
+ */
+ public $parent;
+
+ /**
+ * @var array An array of Node objects that are
+ * direct children of this node
+ */
+ public $children = array();
+
+ /**
+ * @var Mixed A string used to group nodes, or an array of strings
+ * Only relevant if the node is of type CONTAINER
+ */
+ public $separator = '';
+
+ /**
+ * @var int How many time to recursively apply the grouping function
+ * Only relevant if the node is of type CONTAINER
+ */
+ public $separator_depth = 1;
+
+ /**
+ * @var string An IMG tag, used when rendering the node
+ */
+ public $icon;
+
+ /**
+ * @var Array An array of A tags, used when rendering the node
+ * The indexes in the array may be 'icon' and 'text'
+ */
+ public $links;
+
+ /**
+ * @var string Extra CSS classes for the node
+ */
+ public $classes = '';
+
+ /**
+ * @var string Whether this node is a link for creating new objects
+ */
+ public $isNew = false;
+
+ /**
+ * @var int The position for the pagination of
+ * the branch at the second level of the tree
+ */
+ public $pos2 = 0;
+
+ /**
+ * @var int The position for the pagination of
+ * the branch at the third level of the tree
+ */
+ public $pos3 = 0;
+
+ /**
+ * Initialises the class by setting the mandatory variables
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ if (! empty($name)) {
+ $this->name = $name;
+ $this->real_name = $name;
+ }
+ if ($type === Node::CONTAINER) {
+ $this->type = Node::CONTAINER;
+ }
+ $this->is_group = (bool)$is_group;
+ }
+
+ /**
+ * Adds a child node to this node
+ *
+ * @param Node $child A child node
+ *
+ * @return nothing
+ */
+ public function addChild($child)
+ {
+ $this->children[] = $child;
+ $child->parent = $this;
+ }
+
+ /**
+ * Returns a child node given it's name
+ *
+ * @param string $name The name of requested child
+ * @param bool $real_name Whether to use the "real_name"
+ * instead of "name" in comparisons
+ *
+ * @return false|Node The requested child node or false,
+ * if the requested node cannot be found
+ */
+ public function getChild($name, $real_name = false)
+ {
+ if ($real_name) {
+ foreach ($this->children as $child) {
+ if ($child->real_name == $name) {
+ return $child;
+ }
+ }
+ } else {
+ foreach ($this->children as $child) {
+ if ($child->name == $name) {
+ return $child;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Removes a child node from this node
+ *
+ * @param string $name The name of child to be removed
+ *
+ * @return nothing
+ */
+ public function removeChild($name)
+ {
+ foreach ($this->children as $key => $child) {
+ if ($child->name == $name) {
+ unset($this->children[$key]);
+ break;
+ }
+ }
+ }
+
+ /**
+ * Retreives the parents for a node
+ *
+ * @param bool $self Whether to include the Node itself in the results
+ * @param bool $containers Whether to include nodes of type CONTAINER
+ * @param bool $groups Whether to include nodes which have $group == true
+ *
+ * @return array An array of parent Nodes
+ */
+ public function parents($self = false, $containers = false, $groups = false)
+ {
+ $parents = array();
+ if ($self
+ && ($this->type != Node::CONTAINER || $containers)
+ && ($this->is_group != true || $groups)
+ ) {
+ $parents[] = $this;
+ $self = false;
+ }
+ $parent = $this->parent;
+ while (isset($parent)) {
+ if ( ($parent->type != Node::CONTAINER || $containers)
+ && ($parent->is_group != true || $groups)
+ ) {
+ $parents[] = $parent;
+ }
+ $parent = $parent->parent;
+ }
+ return $parents;
+ }
+
+ /**
+ * Returns the actual parent of a node. If used twice on an index or columns
+ * node, it will return the table and database nodes. The names of the returned
+ * nodes can be used in SQL queries, etc...
+ *
+ * @return Node
+ */
+ public function realParent()
+ {
+ $retval = $this->parents();
+ if (count($retval) > 0) {
+ return $retval[0];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * This function checks if the node has children nodes associated with it
+ *
+ * @param bool $count_empty_containers Whether to count empty child
+ * containers as valid children
+ *
+ * @return bool Whether the node has child nodes
+ */
+ public function hasChildren($count_empty_containers = true)
+ {
+ $retval = false;
+ if ($count_empty_containers) {
+ if (count($this->children)) {
+ $retval = true;
+ }
+ } else {
+ foreach ($this->children as $child) {
+ if ($child->type == Node::OBJECT || $child->hasChildren(false)) {
+ $retval = true;
+ break;
+ }
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns true the node has some siblings (other nodes on the same tree level,
+ * in the same branch), false otherwise. The only exception is for nodes on
+ * the third level of the tree (columns and indexes), for which the function
+ * always returns true. This is because we want to render the containers
+ * for these nodes
+ *
+ * @return bool
+ */
+ public function hasSiblings()
+ {
+ $retval = false;
+ $paths = $this->getPaths();
+ if (count($paths['aPath_clean']) > 3) {
+ $retval = true;
+ } else {
+ foreach ($this->parent->children as $child) {
+ if ($child != $this
+ && ($child->type == Node::OBJECT || $child->hasChildren(false))
+ ) {
+ $retval = true;
+ break;
+ }
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns the number of child nodes that a node has associated with it
+ *
+ * @return int The number of children nodes
+ */
+ public function numChildren()
+ {
+ $retval = 0;
+ foreach ($this->children as $child) {
+ if ($child->type == Node::OBJECT) {
+ $retval++;
+ } else {
+ $retval += $child->numChildren();
+ }
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns the actual path and the virtual paths for a node
+ * both as clean arrays and base64 encoded strings
+ *
+ * @return array
+ */
+ public function getPaths()
+ {
+ $aPath = array();
+ $aPath_clean = array();
+ foreach ($this->parents(true, true, false) as $parent) {
+ $aPath[] = base64_encode($parent->real_name);
+ $aPath_clean[] = $parent->real_name;
+ }
+ $aPath = implode('.', array_reverse($aPath));
+ $aPath_clean = array_reverse($aPath_clean);
+
+ $vPath = array();
+ $vPath_clean = array();
+ foreach ($this->parents(true, true, true) as $parent) {
+ $vPath[] = base64_encode($parent->name);
+ $vPath_clean[] = $parent->name;
+ }
+ $vPath = implode('.', array_reverse($vPath));
+ $vPath_clean = array_reverse($vPath_clean);
+
+ return array(
+ 'aPath' => $aPath,
+ 'aPath_clean' => $aPath_clean,
+ 'vPath' => $vPath,
+ 'vPath_clean' => $vPath_clean
+ );
+ }
+
+ /**
+ * Returns the names of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('tables', 'views', etc)
+ * @param int $pos The offset of the list within the results
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return array
+ */
+ public function getData($type, $pos, $searchClause = '')
+ {
+ // @todo obey the DisableIS directive
+ $query = "SELECT `SCHEMA_NAME` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
+ $query .= $this->_getWhereClause($searchClause);
+ $query .= "ORDER BY `SCHEMA_NAME` ASC ";
+ $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}";
+ return PMA_DBI_fetch_result($query);
+ }
+
+ /**
+ * Returns the number of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('tables', 'views', etc)
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return int
+ */
+ public function getPresence($type = '', $searchClause = '')
+ {
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
+ $query .= $this->_getWhereClause($searchClause);
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $query = "SHOW DATABASES ";
+ if (! empty($searchClause)) {
+ $query .= "LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%' ";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns the WHERE clause depending on the $searchClause parameter
+ * and the hide_db directive
+ *
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return string
+ */
+ private function _getWhereClause($searchClause = '')
+ {
+ $whereClause = "WHERE TRUE ";
+ if (! empty($searchClause)) {
+ $whereClause .= "AND `SCHEMA_NAME` LIKE '%";
+ $whereClause .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $whereClause .= "%' ";
+ }
+
+ if (! empty($GLOBALS['cfg']['Server']['hide_db'])) {
+ $whereClause .= "AND `SCHEMA_NAME` NOT REGEXP '"
+ . $GLOBALS['cfg']['Server']['hide_db'] . "' ";
+ }
+
+ if (! empty($GLOBALS['cfg']['Server']['only_db'])) {
+ if (is_string($GLOBALS['cfg']['Server']['only_db'])) {
+ $GLOBALS['cfg']['Server']['only_db'] = array(
+ $GLOBALS['cfg']['Server']['only_db']
+ );
+ }
+ $whereClause .= "AND (";
+ $subClauses = array();
+ foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) {
+ $subClauses[] = " `SCHEMA_NAME` LIKE '"
+ . $each_only_db . "' ";
+ }
+ $whereClause .= implode("OR", $subClauses) . ")";
+ }
+ return $whereClause;
+ }
+
+}
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Column.class.php b/hugo/libraries/navigation/Nodes/Node_Column.class.php
new file mode 100644
index 0000000..083c6e4
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Column.class.php
@@ -0,0 +1,46 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a columns node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Column extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Column
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('pause.png', '');
+ $this->links = array(
+ 'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
+ . '&amp;change_column=1'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
+ . '&amp;change_column=1'
+ . '&amp;token=' . $GLOBALS['token']
+ );
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Column_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Column_Container.class.php
new file mode 100644
index 0000000..1ae57a8
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Column_Container.class.php
@@ -0,0 +1,56 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for column nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Column_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Column_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Columns'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('pause.png', '');
+ $this->links = array(
+ 'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;token=' . $GLOBALS['token'],
+ );
+ $this->real_name = 'columns';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new column', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_column_add.png', '');
+ $new->links = array(
+ 'text' => 'tbl_addfield.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s'
+ . '&amp;field_where=last&after_field='
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_addfield.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s'
+ . '&amp;field_where=last&after_field='
+ . '&amp;token=' . $GLOBALS['token'],
+ );
+ $new->classes = 'new_column italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Database.class.php b/hugo/libraries/navigation/Nodes/Node_Database.class.php
new file mode 100644
index 0000000..ba823dd
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Database.class.php
@@ -0,0 +1,436 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a database node in the navigation tree
+ */
+class Node_Database extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Database
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('s_db.png');
+ $this->links = array(
+ 'text' => $GLOBALS['cfg']['DefaultTabDatabase']
+ . '?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_operations.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'database';
+ }
+
+ /**
+ * Returns the number of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('tables', 'views', etc)
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return int
+ */
+ public function getPresence($type = '', $searchClause = '')
+ {
+ $retval = 0;
+ $db = $this->real_name;
+ switch ($type) {
+ case 'tables':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
+ $query .= "WHERE `TABLE_SCHEMA`='$db' ";
+ $query .= "AND `TABLE_TYPE`='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `TABLE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $query = "SHOW FULL TABLES FROM ";
+ $query .= PMA_Util::backquote($db);
+ $query .= " WHERE `Table_type`='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND " . PMA_Util::backquote(
+ "Tables_in_" . $db
+ );
+ $query .= " LIKE '%" . PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ case 'views':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
+ $query .= "WHERE `TABLE_SCHEMA`='$db' ";
+ $query .= "AND `TABLE_TYPE`!='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `TABLE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $query = "SHOW FULL TABLES FROM ";
+ $query .= PMA_Util::backquote($db);
+ $query .= " WHERE `Table_type`!='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND " . PMA_Util::backquote(
+ "Tables_in_" . $db
+ );
+ $query .= " LIKE '%" . PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ case 'procedures':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
+ $query .= "WHERE `ROUTINE_SCHEMA`='$db'";
+ $query .= "AND `ROUTINE_TYPE`='PROCEDURE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `ROUTINE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ case 'functions':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
+ $query .= "WHERE `ROUTINE_SCHEMA`='$db' ";
+ $query .= "AND `ROUTINE_TYPE`='FUNCTION' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `ROUTINE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SHOW FUNCTION STATUS WHERE `Db`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ case 'events':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
+ $query .= "WHERE `EVENT_SCHEMA`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `EVENT_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $query = "SHOW EVENTS FROM $db ";
+ if (! empty($searchClause)) {
+ $query .= "WHERE `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $retval = PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ default:
+ break;
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns the names of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('tables', 'views', etc)
+ * @param int $pos The offset of the list within the results
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return array
+ */
+ public function getData($type, $pos, $searchClause = '')
+ {
+ $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
+ $retval = array();
+ $db = $this->real_name;
+ switch ($type) {
+ case 'tables':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT `TABLE_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
+ $query .= "WHERE `TABLE_SCHEMA`='$db' ";
+ $query .= "AND `TABLE_TYPE`='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `TABLE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $query .= "ORDER BY `TABLE_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $query = " SHOW FULL TABLES FROM ";
+ $query .= PMA_Util::backquote($db);
+ $query .= " WHERE `Table_type`='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND " . PMA_Util::backquote(
+ "Tables_in_" . $db
+ );
+ $query .= " LIKE '%" . PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr[0];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'views':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT `TABLE_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
+ $query .= "WHERE `TABLE_SCHEMA`='$db' ";
+ $query .= "AND `TABLE_TYPE`!='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `TABLE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $query .= "ORDER BY `TABLE_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $query = "SHOW FULL TABLES FROM ";
+ $query .= PMA_Util::backquote($db);
+ $query .= " WHERE `Table_type`!='BASE TABLE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND " . PMA_Util::backquote(
+ "Tables_in_" . $db
+ );
+ $query .= " LIKE '%" . PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr[0];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'procedures':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT `ROUTINE_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
+ $query .= "WHERE `ROUTINE_SCHEMA`='$db'";
+ $query .= "AND `ROUTINE_TYPE`='PROCEDURE' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `ROUTINE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $query .= "ORDER BY `ROUTINE_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Name'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'functions':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT `ROUTINE_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
+ $query .= "WHERE `ROUTINE_SCHEMA`='$db' ";
+ $query .= "AND `ROUTINE_TYPE`='FUNCTION' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `ROUTINE_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $query .= "ORDER BY `ROUTINE_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SHOW FUNCTION STATUS WHERE `Db`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Name'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'events':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $query = "SELECT `EVENT_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
+ $query .= "WHERE `EVENT_SCHEMA`='$db' ";
+ if (! empty($searchClause)) {
+ $query .= "AND `EVENT_NAME` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $query .= "ORDER BY `EVENT_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $query = "SHOW EVENTS FROM $db ";
+ if (! empty($searchClause)) {
+ $query .= "WHERE `Name` LIKE '%";
+ $query .= PMA_Util::sqlAddSlashes(
+ $searchClause, true
+ );
+ $query .= "%'";
+ }
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Name'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return $retval;
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Event.class.php b/hugo/libraries/navigation/Nodes/Node_Event.class.php
new file mode 100644
index 0000000..021521b
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Event.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a event node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Event extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Event
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_events.png');
+ $this->links = array(
+ 'text' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;edit_item=1'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;export_item=1'
+ . '&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'event';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Event_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Event_Container.class.php
new file mode 100644
index 0000000..16bdd00
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Event_Container.class.php
@@ -0,0 +1,52 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for events nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Event_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Event_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Events'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_events.png', '');
+ $this->links = array(
+ 'text' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ );
+ $this->real_name = 'events';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new event', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_event_add.png', '');
+ $new->links = array(
+ 'text' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1',
+ 'icon' => 'db_events.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1',
+ );
+ $new->classes = 'new_event italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Function.class.php b/hugo/libraries/navigation/Nodes/Node_Function.class.php
new file mode 100644
index 0000000..98ac61f
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Function.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a function node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Function extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Function
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_routines.png');
+ $this->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=FUNCTION'
+ . '&amp;edit_item=1&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=FUNCTION'
+ . '&amp;export_item=1&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'function';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Function_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Function_Container.class.php
new file mode 100644
index 0000000..1ddc313
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Function_Container.class.php
@@ -0,0 +1,52 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for functions nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Function_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Column_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Functions'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_routines.png');
+ $this->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ );
+ $this->real_name = 'functions';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new function', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_routine_add.png', '');
+ $new->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1&amp;item_type=FUNCTION',
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1&amp;item_type=FUNCTION',
+ );
+ $new->classes = 'new_function italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Index.class.php b/hugo/libraries/navigation/Nodes/Node_Index.class.php
new file mode 100644
index 0000000..918a212
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Index.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a index node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Index extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Index
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_index.png');
+ $this->links = array(
+ 'text' => 'tbl_indexes.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s&amp;index=%1$s'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;table=%2$s&amp;index=%1$s'
+ . '&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'index';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Index_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Index_Container.class.php
new file mode 100644
index 0000000..732dfdd
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Index_Container.class.php
@@ -0,0 +1,54 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for index nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Index_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Index_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Indexes'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_index.png', '');
+ $this->links = array(
+ 'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;token=' . $GLOBALS['token'],
+ );
+ $this->real_name = 'indexes';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new index', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_index_add.png', '');
+ $new->links = array(
+ 'text' => 'tbl_indexes.php?server=' . $GLOBALS['server']
+ . '&amp;create_index=1&amp;added_fields=2'
+ . '&amp;db=%3$s&amp;table=%2$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server']
+ . '&amp;create_index=1&amp;added_fields=2'
+ . '&amp;db=%3$s&amp;table=%2$s&amp;token=' . $GLOBALS['token'],
+ );
+ $new->classes = 'new_index italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Procedure.class.php b/hugo/libraries/navigation/Nodes/Node_Procedure.class.php
new file mode 100644
index 0000000..5b13f8d
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Procedure.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a procedure node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Procedure extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Procedure
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_routines.png');
+ $this->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=PROCEDURE'
+ . '&amp;edit_item=1&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=PROCEDURE'
+ . '&amp;export_item=1&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'procedure';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Procedure_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Procedure_Container.class.php
new file mode 100644
index 0000000..8af1185
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Procedure_Container.class.php
@@ -0,0 +1,52 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for procedure nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Procedure_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Procedure_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Procedures'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_routines.png');
+ $this->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ );
+ $this->real_name = 'procedures';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new procedure', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_routine_add.png', '');
+ $new->links = array(
+ 'text' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1',
+ 'icon' => 'db_routines.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token']
+ . '&add_item=1',
+ );
+ $new->classes = 'new_procedure italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Table.class.php b/hugo/libraries/navigation/Nodes/Node_Table.class.php
new file mode 100644
index 0000000..b27e0da
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Table.class.php
@@ -0,0 +1,203 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a columns node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Table extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Table
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_browse.png');
+ $this->links = array(
+ 'text' => 'sql.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;pos=0&amp;token=' . $GLOBALS['token'],
+ 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
+ . '?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'table';
+ }
+
+ /**
+ * Returns the number of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('columns' or 'indexes')
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return int
+ */
+ public function getPresence($type = '', $searchClause = '')
+ {
+ $retval = 0;
+ $db = $this->realParent()->real_name;
+ $table = $this->real_name;
+ switch ($type) {
+ case 'columns':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
+ $query .= "WHERE `TABLE_NAME`='$table' ";
+ $query .= "AND `TABLE_SCHEMA`='$db'";
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::backquote($table);
+ $query = "SHOW COLUMNS FROM $table FROM $db";
+ $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ case 'indexes':
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::backquote($table);
+ $query = "SHOW INDEXES FROM $table FROM $db";
+ $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ break;
+ case 'triggers':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SELECT COUNT(*) ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
+ $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
+ $query .= "AND `EVENT_OBJECT_TABLE`='$table'";
+ $retval = (int)PMA_DBI_fetch_value($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
+ $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
+ }
+ break;
+ default:
+ break;
+ }
+ return $retval;
+ }
+
+ /**
+ * Returns the names of children of type $type present inside this container
+ * This method is overridden by the Node_Database and Node_Table classes
+ *
+ * @param string $type The type of item we are looking for
+ * ('tables', 'views', etc)
+ * @param int $pos The offset of the list within the results
+ * @param string $searchClause A string used to filter the results of the query
+ *
+ * @return array
+ */
+ public function getData($type, $pos, $searchClause = '')
+ {
+ $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
+ $retval = array();
+ $db = $this->realParent()->real_name;
+ $table = $this->real_name;
+ switch ($type) {
+ case 'columns':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SELECT `COLUMN_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
+ $query .= "WHERE `TABLE_NAME`='$table' ";
+ $query .= "AND `TABLE_SCHEMA`='$db' ";
+ $query .= "ORDER BY `COLUMN_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::backquote($table);
+ $query = "SHOW COLUMNS FROM $table FROM $db";
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Field'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'indexes':
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::backquote($table);
+ $query = "SHOW INDEXES FROM $table FROM $db";
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if (! in_array($arr['Key_name'], $retval)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Key_name'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ case 'triggers':
+ if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
+ $db = PMA_Util::sqlAddSlashes($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SELECT `TRIGGER_NAME` AS `name` ";
+ $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
+ $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
+ $query .= "AND `EVENT_OBJECT_TABLE`='$table' ";
+ $query .= "ORDER BY `TRIGGER_NAME` ASC ";
+ $query .= "LIMIT " . intval($pos) . ", $maxItems";
+ $retval = PMA_DBI_fetch_result($query);
+ } else {
+ $db = PMA_Util::backquote($db);
+ $table = PMA_Util::sqlAddSlashes($table);
+ $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
+ $handle = PMA_DBI_try_query($query);
+ if ($handle !== false) {
+ $count = 0;
+ while ($arr = PMA_DBI_fetch_array($handle)) {
+ if ($pos <= 0 && $count < $maxItems) {
+ $retval[] = $arr['Trigger'];
+ $count++;
+ }
+ $pos--;
+ }
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ return $retval;
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Table_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Table_Container.class.php
new file mode 100644
index 0000000..0efa9fc
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Table_Container.class.php
@@ -0,0 +1,55 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for table nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Table_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Table_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Tables'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_browse.png', '');
+ $this->links = array(
+ 'text' => 'db_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ );
+ if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
+ $this->separator = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
+ $this->separator_depth = (int)($GLOBALS['cfg']['NavigationTreeTableLevel']);
+ }
+ $this->real_name = 'tables';
+ $this->classes = 'tableContainer';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new table', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_table_add.png', '');
+ $new->links = array(
+ 'text' => 'tbl_create.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_create.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'],
+ );
+ $new->classes = 'new_table italics';
+ $this->addChild($new);
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Trigger.class.php b/hugo/libraries/navigation/Nodes/Node_Trigger.class.php
new file mode 100644
index 0000000..bc51106
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Trigger.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a trigger node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Trigger extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_Trigger
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_triggers.png');
+ $this->links = array(
+ 'text' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;item_name=%1$s&amp;edit_item=1'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;item_name=%1$s&amp;export_item=1'
+ . '&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'trigger';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_Trigger_Container.class.php b/hugo/libraries/navigation/Nodes/Node_Trigger_Container.class.php
new file mode 100644
index 0000000..7f8f3cb
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_Trigger_Container.class.php
@@ -0,0 +1,53 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for trigger nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_Trigger_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_Trigger_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Triggers'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_triggers.png');
+ $this->links = array(
+ 'text' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s&amp;token=' . $GLOBALS['token']
+ );
+ $this->real_name = 'triggers';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new trigger', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_trigger_add.png', '');
+ $new->links = array(
+ 'text' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;token=' . $GLOBALS['token']
+ . '&amp;add_item=1',
+ 'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
+ . '&amp;db=%3$s&amp;token=' . $GLOBALS['token']
+ . '&amp;add_item=1',
+ );
+ $new->classes = 'new_trigger italics';
+ $this->addChild($new);
+ }
+
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_View.class.php b/hugo/libraries/navigation/Nodes/Node_View.class.php
new file mode 100644
index 0000000..f9d3cfc
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_View.class.php
@@ -0,0 +1,45 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a view node in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_View extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @param string $name An identifier for the new node
+ * @param int $type Type of node, may be one of CONTAINER or OBJECT
+ * @param bool $is_group Whether this object has been created
+ * while grouping nodes
+ *
+ * @return Node_View
+ */
+ public function __construct($name, $type = Node::OBJECT, $is_group = false)
+ {
+ parent::__construct($name, $type, $is_group);
+ $this->icon = PMA_Util::getImage('b_views.png');
+ $this->links = array(
+ 'text' => 'sql.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s&amp;pos=0'
+ . '&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;table=%1$s'
+ . '&amp;token=' . $GLOBALS['token']
+ );
+ $this->classes = 'view';
+ }
+}
+
+?>
diff --git a/hugo/libraries/navigation/Nodes/Node_View_Container.class.php b/hugo/libraries/navigation/Nodes/Node_View_Container.class.php
new file mode 100644
index 0000000..39544fb
--- /dev/null
+++ b/hugo/libraries/navigation/Nodes/Node_View_Container.class.php
@@ -0,0 +1,51 @@
+<?php
+/* vim: set expandtab sw=4 ts=4 sts=4: */
+/**
+ * Functionality for the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+if (! defined('PHPMYADMIN')) {
+ exit;
+}
+
+/**
+ * Represents a container for view nodes in the navigation tree
+ *
+ * @package PhpMyAdmin-Navigation
+ */
+class Node_View_Container extends Node
+{
+ /**
+ * Initialises the class
+ *
+ * @return Node_View_Container
+ */
+ public function __construct()
+ {
+ parent::__construct(__('Views'), Node::CONTAINER);
+ $this->icon = PMA_Util::getImage('b_views.png', '');
+ $this->links = array(
+ 'text' => 'db_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'db_structure.php?server=' . $GLOBALS['server']
+ . '&amp;db=%1$s&amp;token=' . $GLOBALS['token'],
+ );
+ $this->classes = 'viewContainer';
+ $this->real_name = 'views';
+
+ $new = PMA_NodeFactory::getInstance('Node', _pgettext('Create new view', 'New'));
+ $new->isNew = true;
+ $new->icon = PMA_Util::getImage('b_view_add.png', '');
+ $new->links = array(
+ 'text' => 'view_create.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'],
+ 'icon' => 'view_create.php?server=' . $GLOBALS['server']
+ . '&amp;db=%2$s&amp;token=' . $GLOBALS['token'],
+ );
+ $new->classes = 'new_view italics';
+ $this->addChild($new);
+ }
+}
+
+?>