Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / navigation / Nodes / Node_Table.class.php
blobc5449d9228033fa6b309477a14114f00eb6c0481
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 /**
13 * Represents a columns node in the navigation tree
15 * @package PhpMyAdmin-Navigation
17 class Node_Table extends Node
19 /**
20 * Initialises the class
22 * @param string $name An identifier for the new node
23 * @param int $type Type of node, may be one of CONTAINER or OBJECT
24 * @param bool $is_group Whether this object has been created
25 * while grouping nodes
27 * @return Node_Table
29 public function __construct($name, $type = Node::OBJECT, $is_group = false)
31 parent::__construct($name, $type, $is_group);
32 $this->icon = PMA_Util::getImage('b_browse.png');
33 $this->links = array(
34 'text' => 'sql.php?server=' . $GLOBALS['server']
35 . '&amp;db=%2$s&amp;table=%1$s'
36 . '&amp;pos=0&amp;token=' . $GLOBALS['token'],
37 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
38 . '?server=' . $GLOBALS['server']
39 . '&amp;db=%2$s&amp;table=%1$s&amp;token=' . $GLOBALS['token']
43 /**
44 * Returns the number of children of type $type present inside this container
45 * This method is overridden by the Node_Database and Node_Table classes
47 * @param string $type The type of item we are looking for
48 * ('columns' or 'indexes')
49 * @param string $searchClause A string used to filter the results of the query
51 * @return int
53 public function getPresence($type = '', $searchClause = '')
55 $retval = 0;
56 $db = $this->realParent()->real_name;
57 $table = $this->real_name;
58 switch ($type) {
59 case 'columns':
60 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
61 $db = PMA_Util::sqlAddSlashes($db);
62 $table = PMA_Util::sqlAddSlashes($table);
63 $query = "SELECT COUNT(*) ";
64 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
65 $query .= "WHERE `TABLE_NAME`='$table' ";
66 $query .= "AND `TABLE_SCHEMA`='$db'";
67 $retval = (int)PMA_DBI_fetch_value($query);
68 } else {
69 $db = PMA_Util::backquote($db);
70 $table = PMA_Util::backquote($table);
71 $query = "SHOW COLUMNS FROM $table FROM $db";
72 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
74 break;
75 case 'indexes':
76 $db = PMA_Util::backquote($db);
77 $table = PMA_Util::backquote($table);
78 $query = "SHOW INDEXES FROM $table FROM $db";
79 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
80 break;
81 case 'triggers':
82 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
83 $db = PMA_Util::sqlAddSlashes($db);
84 $table = PMA_Util::sqlAddSlashes($table);
85 $query = "SELECT COUNT(*) ";
86 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
87 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
88 $query .= "AND `EVENT_OBJECT_TABLE`='$table'";
89 $retval = (int)PMA_DBI_fetch_value($query);
90 } else {
91 $db = PMA_Util::backquote($db);
92 $table = PMA_Util::sqlAddSlashes($table);
93 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
94 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
96 break;
97 default:
98 break;
100 return $retval;
104 * Returns the names of children of type $type present inside this container
105 * This method is overridden by the Node_Database and Node_Table classes
107 * @param string $type The type of item we are looking for
108 * ('tables', 'views', etc)
109 * @param int $pos The offset of the list within the results
110 * @param string $searchClause A string used to filter the results of the query
112 * @return array
114 public function getData($type, $pos, $searchClause = '')
116 $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
117 $retval = array();
118 $db = $this->realParent()->real_name;
119 $table = $this->real_name;
120 switch ($type) {
121 case 'columns':
122 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
123 $db = PMA_Util::sqlAddSlashes($db);
124 $table = PMA_Util::sqlAddSlashes($table);
125 $query = "SELECT `COLUMN_NAME` AS `name` ";
126 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
127 $query .= "WHERE `TABLE_NAME`='$table' ";
128 $query .= "AND `TABLE_SCHEMA`='$db' ";
129 $query .= "ORDER BY `COLUMN_NAME` ASC ";
130 $query .= "LIMIT " . intval($pos) . ", $maxItems";
131 $retval = PMA_DBI_fetch_result($query);
132 } else {
133 $db = PMA_Util::backquote($db);
134 $table = PMA_Util::backquote($table);
135 $query = "SHOW COLUMNS FROM $table FROM $db";
136 $handle = PMA_DBI_try_query($query);
137 if ($handle !== false) {
138 $count = 0;
139 while ($arr = PMA_DBI_fetch_array($handle)) {
140 if ($pos <= 0 && $count < $maxItems) {
141 $retval[] = $arr['Field'];
142 $count++;
144 $pos--;
148 break;
149 case 'indexes':
150 $db = PMA_Util::backquote($db);
151 $table = PMA_Util::backquote($table);
152 $query = "SHOW INDEXES FROM $table FROM $db";
153 $handle = PMA_DBI_try_query($query);
154 if ($handle !== false) {
155 $count = 0;
156 while ($arr = PMA_DBI_fetch_array($handle)) {
157 if (! in_array($arr['Key_name'], $retval)) {
158 if ($pos <= 0 && $count < $maxItems) {
159 $retval[] = $arr['Key_name'];
160 $count++;
162 $pos--;
166 break;
167 case 'triggers':
168 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
169 $db = PMA_Util::sqlAddSlashes($db);
170 $table = PMA_Util::sqlAddSlashes($table);
171 $query = "SELECT `TRIGGER_NAME` AS `name` ";
172 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
173 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
174 $query .= "AND `EVENT_OBJECT_TABLE`='$table' ";
175 $query .= "ORDER BY `TRIGGER_NAME` ASC ";
176 $query .= "LIMIT " . intval($pos) . ", $maxItems";
177 $retval = PMA_DBI_fetch_result($query);
178 } else {
179 $db = PMA_Util::backquote($db);
180 $table = PMA_Util::sqlAddSlashes($table);
181 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
182 $handle = PMA_DBI_try_query($query);
183 if ($handle !== false) {
184 $count = 0;
185 while ($arr = PMA_DBI_fetch_array($handle)) {
186 if ($pos <= 0 && $count < $maxItems) {
187 $retval[] = $arr['Trigger'];
188 $count++;
190 $pos--;
194 break;
195 default:
196 break;
198 return $retval;
202 * Returns the comment associated with node
203 * This method should be overridden by specific type of nodes
205 * @return string
207 public function getComment()
209 $db = $this->realParent()->real_name;
210 $table = PMA_Util::sqlAddSlashes($this->real_name);
211 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
212 $db = PMA_Util::sqlAddSlashes($db);
213 $query = "SELECT `TABLE_COMMENT` ";
214 $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
215 $query .= "WHERE `TABLE_SCHEMA`='$db' ";
216 $query .= "AND `TABLE_NAME`='$table' ";
217 $retval = PMA_DBI_fetch_value($query);
218 } else {
219 $db = PMA_Util::backquote($db);
220 $query = "SHOW TABLE STATUS FROM $db ";
221 $query .= "WHERE Name = '$table'";
222 $arr = PMA_DBI_fetch_assoc(PMA_DBI_try_query($query));
223 $retval = $arr['Comment'];
225 return $retval;