2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functionality for the navigation tree
6 * @package PhpMyAdmin-Navigation
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/navigation/Nodes/Node_DatabaseChild.class.php';
15 * Represents a columns node in the navigation tree
17 * @package PhpMyAdmin-Navigation
19 class Node_Table
extends Node_DatabaseChild
22 * Initialises the class
24 * @param string $name An identifier for the new node
25 * @param int $type Type of node, may be one of CONTAINER or OBJECT
26 * @param bool $is_group Whether this object has been created
27 * while grouping nodes
31 public function __construct($name, $type = Node
::OBJECT, $is_group = false)
33 parent
::__construct($name, $type, $is_group);
34 switch($GLOBALS['cfg']['NavigationTreeDefaultTabTable']) {
35 case 'tbl_structure.php':
36 $this->icon
= PMA_Util
::getImage('b_props.png', __('Structure'));
38 case 'tbl_select.php':
39 $this->icon
= PMA_Util
::getImage('b_search.png', __('Search'));
41 case 'tbl_change.php':
42 $this->icon
= PMA_Util
::getImage('b_insrow.png', __('Insert'));
45 $this->icon
= PMA_Util
::getImage('b_sql.png', __('SQL'));
48 $this->icon
= PMA_Util
::getImage('b_browse.png', __('Browse'));
52 'text' => $GLOBALS['cfg']['DefaultTabTable']
53 . '?server=' . $GLOBALS['server']
54 . '&db=%2$s&table=%1$s'
55 . '&pos=0&token=' . $GLOBALS['token'],
56 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
57 . '?server=' . $GLOBALS['server']
58 . '&db=%2$s&table=%1$s&token=' . $GLOBALS['token']
60 $this->classes
= 'table';
64 * Returns the number of children of type $type present inside this container
65 * This method is overridden by the Node_Database and Node_Table classes
67 * @param string $type The type of item we are looking for
68 * ('columns' or 'indexes')
69 * @param string $searchClause A string used to filter the results of the query
73 public function getPresence($type = '', $searchClause = '')
76 $db = $this->realParent()->real_name
;
77 $table = $this->real_name
;
80 $db = PMA_Util
::sqlAddSlashes($db);
81 $table = PMA_Util
::sqlAddSlashes($table);
82 $query = "SELECT COUNT(*) ";
83 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
84 $query .= "WHERE `TABLE_NAME`='$table' ";
85 $query .= "AND `TABLE_SCHEMA`='$db'";
86 $retval = (int)$GLOBALS['dbi']->fetchValue($query);
89 $db = PMA_Util
::backquote($db);
90 $table = PMA_Util
::backquote($table);
91 $query = "SHOW INDEXES FROM $table FROM $db";
92 $retval = (int)$GLOBALS['dbi']->numRows(
93 $GLOBALS['dbi']->tryQuery($query)
97 $db = PMA_Util
::sqlAddSlashes($db);
98 $table = PMA_Util
::sqlAddSlashes($table);
99 $query = "SELECT COUNT(*) ";
100 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
101 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
102 $query .= "AND `EVENT_OBJECT_TABLE`='$table'";
103 $retval = (int)$GLOBALS['dbi']->fetchValue($query);
112 * Returns the names of children of type $type present inside this container
113 * This method is overridden by the Node_Database and Node_Table classes
115 * @param string $type The type of item we are looking for
116 * ('tables', 'views', etc)
117 * @param int $pos The offset of the list within the results
118 * @param string $searchClause A string used to filter the results of the query
122 public function getData($type, $pos, $searchClause = '')
124 $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
126 $db = $this->realParent()->real_name
;
127 $table = $this->real_name
;
130 $db = PMA_Util
::sqlAddSlashes($db);
131 $table = PMA_Util
::sqlAddSlashes($table);
132 $query = "SELECT `COLUMN_NAME` AS `name` ";
133 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
134 $query .= "WHERE `TABLE_NAME`='$table' ";
135 $query .= "AND `TABLE_SCHEMA`='$db' ";
136 $query .= "ORDER BY `COLUMN_NAME` ASC ";
137 $query .= "LIMIT " . intval($pos) . ", $maxItems";
138 $retval = $GLOBALS['dbi']->fetchResult($query);
141 $db = PMA_Util
::backquote($db);
142 $table = PMA_Util
::backquote($table);
143 $query = "SHOW INDEXES FROM $table FROM $db";
144 $handle = $GLOBALS['dbi']->tryQuery($query);
145 if ($handle === false) {
149 while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
150 if (! in_array($arr['Key_name'], $retval)) {
151 if ($pos <= 0 && $count < $maxItems) {
152 $retval[] = $arr['Key_name'];
160 $db = PMA_Util
::sqlAddSlashes($db);
161 $table = PMA_Util
::sqlAddSlashes($table);
162 $query = "SELECT `TRIGGER_NAME` AS `name` ";
163 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
164 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
165 $query .= "AND `EVENT_OBJECT_TABLE`='$table' ";
166 $query .= "ORDER BY `TRIGGER_NAME` ASC ";
167 $query .= "LIMIT " . intval($pos) . ", $maxItems";
168 $retval = $GLOBALS['dbi']->fetchResult($query);
177 * Returns the type of the item represented by the node.
179 * @return string type of the item
181 protected function getItemType()