Upgrade phpmyadmin project (commit 2 of 3; This commits brings in phpmyadmin version...
[openemr.git] / phpmyadmin / libraries / navigation / Nodes / Node_Table.class.php
blobe984c17de1415d7d855f3def71ec8347a3bf7f96
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Functionality for the navigation tree
6 * @package PhpMyAdmin-Navigation
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/navigation/Nodes/Node_DatabaseChild.class.php';
14 /**
15 * Represents a columns node in the navigation tree
17 * @package PhpMyAdmin-Navigation
19 class Node_Table extends Node_DatabaseChild
21 /**
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
29 * @return Node_Table
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'));
37 break;
38 case 'tbl_select.php':
39 $this->icon = PMA_Util::getImage('b_search.png', __('Search'));
40 break;
41 case 'tbl_change.php':
42 $this->icon = PMA_Util::getImage('b_insrow.png', __('Insert'));
43 break;
44 case 'tbl_sql.php':
45 $this->icon = PMA_Util::getImage('b_sql.png', __('SQL'));
46 break;
47 case 'sql.php':
48 $this->icon = PMA_Util::getImage('b_browse.png', __('Browse'));
49 break;
51 $this->links = array(
52 'text' => $GLOBALS['cfg']['DefaultTabTable']
53 . '?server=' . $GLOBALS['server']
54 . '&amp;db=%2$s&amp;table=%1$s'
55 . '&amp;pos=0&amp;token=' . $GLOBALS['token'],
56 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
57 . '?server=' . $GLOBALS['server']
58 . '&amp;db=%2$s&amp;table=%1$s&amp;token=' . $GLOBALS['token']
60 $this->classes = 'table';
63 /**
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
71 * @return int
73 public function getPresence($type = '', $searchClause = '')
75 $retval = 0;
76 $db = $this->realParent()->real_name;
77 $table = $this->real_name;
78 switch ($type) {
79 case 'columns':
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);
87 break;
88 case 'indexes':
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)
95 break;
96 case 'triggers':
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);
104 break;
105 default:
106 break;
108 return $retval;
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
120 * @return array
122 public function getData($type, $pos, $searchClause = '')
124 $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
125 $retval = array();
126 $db = $this->realParent()->real_name;
127 $table = $this->real_name;
128 switch ($type) {
129 case 'columns':
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);
139 break;
140 case 'indexes':
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) {
146 break;
148 $count = 0;
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'];
153 $count++;
155 $pos--;
158 break;
159 case 'triggers':
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);
169 break;
170 default:
171 break;
173 return $retval;
177 * Returns the type of the item represented by the node.
179 * @return string type of the item
181 protected function getItemType()
183 return 'table';