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 $this->icon
= array();
35 $this->_addIcon($GLOBALS['cfg']['NavigationTreeDefaultTabTable']);
36 $this->_addIcon($GLOBALS['cfg']['NavigationTreeDefaultTabTable2']);
37 switch($GLOBALS['cfg']['DefaultTabTable']) {
38 case 'tbl_structure.php':
39 $this->title
= __('Structure');
41 case 'tbl_select.php':
42 $this->title
= __('Search');
44 case 'tbl_change.php':
45 $this->title
= __('Insert');
48 $this->title
= __('SQL');
51 $this->title
= __('Browse');
55 'text' => $GLOBALS['cfg']['DefaultTabTable']
56 . '?server=' . $GLOBALS['server']
57 . '&db=%2$s&table=%1$s'
58 . '&pos=0&token=' . $_SESSION[' PMA_token '],
60 $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
61 . '?server=' . $GLOBALS['server']
62 . '&db=%2$s&table=%1$s&token='
63 . $_SESSION[' PMA_token '],
64 $GLOBALS['cfg']['NavigationTreeDefaultTabTable2']
65 . '?server=' . $GLOBALS['server']
66 . '&db=%2$s&table=%1$s&token='
67 . $_SESSION[' PMA_token ']
69 'title' => $this->title
71 $this->classes
= 'table';
75 * Returns the number of children of type $type present inside this container
76 * This method is overridden by the Node_Database and Node_Table classes
78 * @param string $type The type of item we are looking for
79 * ('columns' or 'indexes')
80 * @param string $searchClause A string used to filter the results of the query
84 public function getPresence($type = '', $searchClause = '')
87 $db = $this->realParent()->real_name
;
88 $table = $this->real_name
;
91 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
92 $db = PMA_Util
::sqlAddSlashes($db);
93 $table = PMA_Util
::sqlAddSlashes($table);
94 $query = "SELECT COUNT(*) ";
95 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
96 $query .= "WHERE `TABLE_NAME`='$table' ";
97 $query .= "AND `TABLE_SCHEMA`='$db'";
98 $retval = (int)$GLOBALS['dbi']->fetchValue($query);
100 $db = PMA_Util
::backquote($db);
101 $table = PMA_Util
::backquote($table);
102 $query = "SHOW COLUMNS FROM $table FROM $db";
103 $retval = (int)$GLOBALS['dbi']->numRows(
104 $GLOBALS['dbi']->tryQuery($query)
109 $db = PMA_Util
::backquote($db);
110 $table = PMA_Util
::backquote($table);
111 $query = "SHOW INDEXES FROM $table FROM $db";
112 $retval = (int)$GLOBALS['dbi']->numRows(
113 $GLOBALS['dbi']->tryQuery($query)
117 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
118 $db = PMA_Util
::sqlAddSlashes($db);
119 $table = PMA_Util
::sqlAddSlashes($table);
120 $query = "SELECT COUNT(*) ";
121 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
122 $query .= "WHERE `EVENT_OBJECT_SCHEMA` "
123 . PMA_Util
::getCollateForIS() . "='$db' ";
124 $query .= "AND `EVENT_OBJECT_TABLE` "
125 . PMA_Util
::getCollateForIS() . "='$table'";
126 $retval = (int)$GLOBALS['dbi']->fetchValue($query);
128 $db = PMA_Util
::backquote($db);
129 $table = PMA_Util
::sqlAddSlashes($table);
130 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
131 $retval = (int)$GLOBALS['dbi']->numRows(
132 $GLOBALS['dbi']->tryQuery($query)
143 * Returns the names of children of type $type present inside this container
144 * This method is overridden by the Node_Database and Node_Table classes
146 * @param string $type The type of item we are looking for
147 * ('tables', 'views', etc)
148 * @param int $pos The offset of the list within the results
149 * @param string $searchClause A string used to filter the results of the query
153 public function getData($type, $pos, $searchClause = '')
155 $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
157 $db = $this->realParent()->real_name
;
158 $table = $this->real_name
;
161 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
162 $db = PMA_Util
::sqlAddSlashes($db);
163 $table = PMA_Util
::sqlAddSlashes($table);
164 $query = "SELECT `COLUMN_NAME` AS `name` ";
165 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
166 $query .= "WHERE `TABLE_NAME`='$table' ";
167 $query .= "AND `TABLE_SCHEMA`='$db' ";
168 $query .= "ORDER BY `COLUMN_NAME` ASC ";
169 $query .= "LIMIT " . intval($pos) . ", $maxItems";
170 $retval = $GLOBALS['dbi']->fetchResult($query);
174 $db = PMA_Util
::backquote($db);
175 $table = PMA_Util
::backquote($table);
176 $query = "SHOW COLUMNS FROM $table FROM $db";
177 $handle = $GLOBALS['dbi']->tryQuery($query);
178 if ($handle === false) {
183 while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
184 if ($pos <= 0 && $count < $maxItems) {
185 $retval[] = $arr['Field'];
192 $db = PMA_Util
::backquote($db);
193 $table = PMA_Util
::backquote($table);
194 $query = "SHOW INDEXES FROM $table FROM $db";
195 $handle = $GLOBALS['dbi']->tryQuery($query);
196 if ($handle === false) {
201 while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
202 if (in_array($arr['Key_name'], $retval)) {
205 if ($pos <= 0 && $count < $maxItems) {
206 $retval[] = $arr['Key_name'];
213 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
214 $db = PMA_Util
::sqlAddSlashes($db);
215 $table = PMA_Util
::sqlAddSlashes($table);
216 $query = "SELECT `TRIGGER_NAME` AS `name` ";
217 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
218 $query .= "WHERE `EVENT_OBJECT_SCHEMA` "
219 . PMA_Util
::getCollateForIS() . "='$db' ";
220 $query .= "AND `EVENT_OBJECT_TABLE` "
221 . PMA_Util
::getCollateForIS() . "='$table' ";
222 $query .= "ORDER BY `TRIGGER_NAME` ASC ";
223 $query .= "LIMIT " . intval($pos) . ", $maxItems";
224 $retval = $GLOBALS['dbi']->fetchResult($query);
228 $db = PMA_Util
::backquote($db);
229 $table = PMA_Util
::sqlAddSlashes($table);
230 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
231 $handle = $GLOBALS['dbi']->tryQuery($query);
232 if ($handle === false) {
237 while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
238 if ($pos <= 0 && $count < $maxItems) {
239 $retval[] = $arr['Trigger'];
252 * Returns the type of the item represented by the node.
254 * @return string type of the item
256 protected function getItemType()
262 * Add an icon to navigation tree
264 * @param string $page Page name to redirect
268 private function _addIcon($page)
275 case 'tbl_structure.php':
276 $this->icon
[] = PMA_Util
::getImage('b_props.png', __('Structure'));
278 case 'tbl_select.php':
279 $this->icon
[] = PMA_Util
::getImage('b_search.png', __('Search'));
281 case 'tbl_change.php':
282 $this->icon
[] = PMA_Util
::getImage('b_insrow.png', __('Insert'));
285 $this->icon
[] = PMA_Util
::getImage('b_sql.png', __('SQL'));
288 $this->icon
[] = PMA_Util
::getImage('b_browse.png', __('Browse'));