123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- <?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
- *
- * @package PhpMyAdmin-Navigation
- */
- 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',
- __('Database operations')
- );
- $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':
- $db = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT COUNT(*) ";
- $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
- $query .= "WHERE `TABLE_SCHEMA`='$db' ";
- if (PMA_DRIZZLE) {
- $query .= "AND `TABLE_TYPE`='BASE' ";
- } else {
- $query .= "AND `TABLE_TYPE`='BASE TABLE' ";
- }
- if (! empty($searchClause)) {
- $query .= "AND `TABLE_NAME` LIKE '%";
- $query .= PMA_Util::sqlAddSlashes(
- $searchClause, true
- );
- $query .= "%'";
- }
- $retval = (int)$GLOBALS['dbi']->fetchValue($query);
- break;
- case 'views':
- $db = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT COUNT(*) ";
- $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
- $query .= "WHERE `TABLE_SCHEMA`='$db' ";
- if (PMA_DRIZZLE) {
- $query .= "AND `TABLE_TYPE`!='BASE' ";
- } else {
- $query .= "AND `TABLE_TYPE`!='BASE TABLE' ";
- }
- if (! empty($searchClause)) {
- $query .= "AND `TABLE_NAME` LIKE '%";
- $query .= PMA_Util::sqlAddSlashes(
- $searchClause, true
- );
- $query .= "%'";
- }
- $retval = (int)$GLOBALS['dbi']->fetchValue($query);
- break;
- case 'procedures':
- $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)$GLOBALS['dbi']->fetchValue($query);
- break;
- case 'functions':
- $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)$GLOBALS['dbi']->fetchValue($query);
- break;
- case 'events':
- $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)$GLOBALS['dbi']->fetchValue($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':
- $escdDb = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT `TABLE_NAME` AS `name` ";
- $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
- $query .= "WHERE `TABLE_SCHEMA`='$escdDb' ";
- if (PMA_DRIZZLE) {
- $query .= "AND `TABLE_TYPE`='BASE' ";
- } else {
- $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 = $GLOBALS['dbi']->fetchResult($query);
- break;
- case 'views':
- $escdDb = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT `TABLE_NAME` AS `name` ";
- $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
- $query .= "WHERE `TABLE_SCHEMA`='$escdDb' ";
- if (PMA_DRIZZLE) {
- $query .= "AND `TABLE_TYPE`!='BASE' ";
- } else {
- $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 = $GLOBALS['dbi']->fetchResult($query);
- break;
- case 'procedures':
- $escdDb = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT `ROUTINE_NAME` AS `name` ";
- $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
- $query .= "WHERE `ROUTINE_SCHEMA`='$escdDb'";
- $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 = $GLOBALS['dbi']->fetchResult($query);
- break;
- case 'functions':
- $escdDb = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT `ROUTINE_NAME` AS `name` ";
- $query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
- $query .= "WHERE `ROUTINE_SCHEMA`='$escdDb' ";
- $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 = $GLOBALS['dbi']->fetchResult($query);
- break;
- case 'events':
- $escdDb = PMA_Util::sqlAddSlashes($db);
- $query = "SELECT `EVENT_NAME` AS `name` ";
- $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
- $query .= "WHERE `EVENT_SCHEMA`='$escdDb' ";
- 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 = $GLOBALS['dbi']->fetchResult($query);
- break;
- default:
- break;
- }
- // Remove hidden items so that they are not displayed in navigation tree
- $cfgRelation = PMA_getRelationsParam();
- if ($cfgRelation['navwork']) {
- $navTable = PMA_Util::backquote($cfgRelation['db'])
- . "." . PMA_Util::backquote($cfgRelation['navigationhiding']);
- $sqlQuery = "SELECT `item_name` FROM " . $navTable
- . " WHERE `username`='" . $cfgRelation['user'] . "'"
- . " AND `item_type`='" . substr($type, 0, -1) . "'"
- . " AND `db_name`='" . PMA_Util::sqlAddSlashes($db) . "'";
- $result = PMA_queryAsControlUser($sqlQuery, false);
- if ($result) {
- $hiddenItems = array();
- while ($row = $GLOBALS['dbi']->fetchArray($result)) {
- $hiddenItems[] = $row[0];
- }
- foreach ($retval as $key => $item) {
- if (in_array($item, $hiddenItems)) {
- unset($retval[$key]);
- }
- }
- }
- $GLOBALS['dbi']->freeResult($result);
- }
- return $retval;
- }
- /**
- * Returns HTML for show hidden button displayed infront of database node
- *
- * @return String HTML for show hidden button
- */
- public function getHtmlForControlButtons()
- {
- $ret = '';
- $db = $this->real_name;
- $cfgRelation = PMA_getRelationsParam();
- if ($cfgRelation['navwork']) {
- $navTable = PMA_Util::backquote($cfgRelation['db'])
- . "." . PMA_Util::backquote($cfgRelation['navigationhiding']);
- $sqlQuery = "SELECT COUNT(*) FROM " . $navTable
- . " WHERE `username`='"
- . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "'"
- . " AND `db_name`='" . PMA_Util::sqlAddSlashes($db) . "'";
- $count = $GLOBALS['dbi']->fetchValue(
- $sqlQuery, 0, 0, $GLOBALS['controllink']
- );
- if ($count > 0) {
- $ret = '<span class="dbItemControls">'
- . '<a href="navigation.php?'
- . PMA_URL_getCommon()
- . '&showUnhideDialog=true'
- . '&dbName=' . urldecode($db) . '"'
- . ' class="showUnhide ajax">'
- . PMA_Util::getImage(
- 'lightbulb.png', __('Show hidden items')
- )
- . '</a></span>';
- }
- }
- return $ret;
- }
- }
- ?>
|