diff options
Diffstat (limited to 'hugo/libraries/navigation/Nodes')
18 files changed, 1824 insertions, 0 deletions
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'] + . '&db=%3$s&table=%2$s&field=%1$s' + . '&change_column=1' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] + . '&db=%3$s&table=%2$s&field=%1$s' + . '&change_column=1' + . '&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'] + . '&db=%2$s&table=%1$s' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] + . '&db=%2$s&table=%1$s' + . '&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'] + . '&db=%3$s&table=%2$s' + . '&field_where=last&after_field=' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_addfield.php?server=' . $GLOBALS['server'] + . '&db=%3$s&table=%2$s' + . '&field_where=last&after_field=' + . '&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_operations.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&item_name=%1$s&edit_item=1' + . '&token=' . $GLOBALS['token'], + 'icon' => 'db_events.php?server=' . $GLOBALS['server'] + . '&db=%2$s&item_name=%1$s&export_item=1' + . '&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_events.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&token=' . $GLOBALS['token'] + . '&add_item=1', + 'icon' => 'db_events.php?server=' . $GLOBALS['server'] + . '&db=%2$s&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'] + . '&db=%2$s&item_name=%1$s&item_type=FUNCTION' + . '&edit_item=1&token=' . $GLOBALS['token'], + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%2$s&item_name=%1$s&item_type=FUNCTION' + . '&export_item=1&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&token=' . $GLOBALS['token'] + . '&add_item=1&item_type=FUNCTION', + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%2$s&token=' . $GLOBALS['token'] + . '&add_item=1&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'] + . '&db=%3$s&table=%2$s&index=%1$s' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server'] + . '&db=%3$s&table=%2$s&index=%1$s' + . '&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'] + . '&db=%2$s&table=%1$s' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] + . '&db=%2$s&table=%1$s' + . '&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'] + . '&create_index=1&added_fields=2' + . '&db=%3$s&table=%2$s&token=' . $GLOBALS['token'], + 'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server'] + . '&create_index=1&added_fields=2' + . '&db=%3$s&table=%2$s&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'] + . '&db=%2$s&item_name=%1$s&item_type=PROCEDURE' + . '&edit_item=1&token=' . $GLOBALS['token'], + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%2$s&item_name=%1$s&item_type=PROCEDURE' + . '&export_item=1&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&token=' . $GLOBALS['token'] + . '&add_item=1', + 'icon' => 'db_routines.php?server=' . $GLOBALS['server'] + . '&db=%2$s&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'] + . '&db=%2$s&table=%1$s' + . '&pos=0&token=' . $GLOBALS['token'], + 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] + . '?server=' . $GLOBALS['server'] + . '&db=%2$s&table=%1$s&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&token=' . $GLOBALS['token'], + 'icon' => 'tbl_create.php?server=' . $GLOBALS['server'] + . '&db=%2$s&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'] + . '&db=%3$s&item_name=%1$s&edit_item=1' + . '&token=' . $GLOBALS['token'], + 'icon' => 'db_triggers.php?server=' . $GLOBALS['server'] + . '&db=%3$s&item_name=%1$s&export_item=1' + . '&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'] + . '&db=%2$s&table=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_triggers.php?server=' . $GLOBALS['server'] + . '&db=%2$s&table=%1$s&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'] + . '&db=%3$s&token=' . $GLOBALS['token'] + . '&add_item=1', + 'icon' => 'db_triggers.php?server=' . $GLOBALS['server'] + . '&db=%3$s&token=' . $GLOBALS['token'] + . '&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'] + . '&db=%2$s&table=%1$s&pos=0' + . '&token=' . $GLOBALS['token'], + 'icon' => 'tbl_structure.php?server=' . $GLOBALS['server'] + . '&db=%2$s&table=%1$s' + . '&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'] + . '&db=%1$s&token=' . $GLOBALS['token'], + 'icon' => 'db_structure.php?server=' . $GLOBALS['server'] + . '&db=%1$s&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'] + . '&db=%2$s&token=' . $GLOBALS['token'], + 'icon' => 'view_create.php?server=' . $GLOBALS['server'] + . '&db=%2$s&token=' . $GLOBALS['token'], + ); + $new->classes = 'new_view italics'; + $this->addChild($new); + } +} + +?> |
