Initial commit

This commit is contained in:
2022-11-21 09:47:28 +01:00
commit 76cec83d26
11652 changed files with 1980467 additions and 0 deletions

View File

@ -0,0 +1,232 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* This class is responsible for instantiating
* the various components of the navigation panel
*
* @package PhpMyAdmin-navigation
*/
namespace PMA\libraries\navigation;
use PMA\libraries\config\PageSettings;
use PMA\libraries\Message;
use PMA\libraries\Response;
use PMA\libraries\Util;
/**
* The navigation panel - displays server, db and table selection tree
*
* @package PhpMyAdmin-Navigation
*/
class Navigation
{
/**
* Renders the navigation tree, or part of it
*
* @return string The navigation tree
*/
public function getDisplay()
{
/* Init */
$retval = '';
if (!Response::getInstance()->isAjax()) {
$header = new NavigationHeader();
$retval = $header->getDisplay();
}
$tree = new NavigationTree();
if (! Response::getInstance()->isAjax()
|| ! empty($_REQUEST['full'])
|| ! empty($_REQUEST['reload'])
) {
if ($GLOBALS['cfg']['ShowDatabasesNavigationAsTree']) {
// provide database tree in navigation
$navRender = $tree->renderState();
} else {
// provide legacy pre-4.0 navigation
$navRender = $tree->renderDbSelect();
}
} else {
$navRender = $tree->renderPath();
}
if (! $navRender) {
$retval .= Message::error(
__('An error has occurred while loading the navigation display')
)->getDisplay();
} else {
$retval .= $navRender;
}
if (! Response::getInstance()->isAjax()) {
// closes the tags that were opened by the navigation header
$retval .= '</div>'; // pma_navigation_tree
$retval .= '<div id="pma_navi_settings_container">';
if (!defined('PMA_DISABLE_NAVI_SETTINGS')) {
$retval .= PageSettings::getNaviSettings();
}
$retval .= '</div>'; //pma_navi_settings_container
$retval .= '</div>'; // pma_navigation_content
$retval .= $this->_getDropHandler();
$retval .= '</div>'; // pma_navigation
}
return $retval;
}
/**
* Add an item of navigation tree to the hidden items list in PMA database.
*
* @param string $itemName name of the navigation tree item
* @param string $itemType type of the navigation tree item
* @param string $dbName database name
* @param string $tableName table name if applicable
*
* @return void
*/
public function hideNavigationItem(
$itemName, $itemType, $dbName, $tableName = null
) {
$navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
. "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
$sqlQuery = "INSERT INTO " . $navTable
. "(`username`, `item_name`, `item_type`, `db_name`, `table_name`)"
. " VALUES ("
. "'" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "',"
. "'" . $GLOBALS['dbi']->escapeString($itemName) . "',"
. "'" . $GLOBALS['dbi']->escapeString($itemType) . "',"
. "'" . $GLOBALS['dbi']->escapeString($dbName) . "',"
. "'" . (! empty($tableName)? $GLOBALS['dbi']->escapeString($tableName) : "" )
. "')";
PMA_queryAsControlUser($sqlQuery, false);
}
/**
* Inserts Drag and Drop Import handler
*
* @return string html code for drop handler
*/
private function _getDropHandler()
{
$retval = '';
$retval .= '<div class="pma_drop_handler">'
. __('Drop files here')
. '</div>';
$retval .= '<div class="pma_sql_import_status">';
$retval .= '<h2>SQL upload ( ';
$retval .= '<span class="pma_import_count">0</span> ';
$retval .= ') <span class="close">x</span>';
$retval .= '<span class="minimize">-</span></h2>';
$retval .= '<div></div>';
$retval .= '</div>';
return $retval;
}
/**
* Remove a hidden item of navigation tree from the
* list of hidden items in PMA database.
*
* @param string $itemName name of the navigation tree item
* @param string $itemType type of the navigation tree item
* @param string $dbName database name
* @param string $tableName table name if applicable
*
* @return void
*/
public function unhideNavigationItem(
$itemName, $itemType, $dbName, $tableName = null
) {
$navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
. "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
$sqlQuery = "DELETE FROM " . $navTable
. " WHERE"
. " `username`='"
. $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "'"
. " AND `item_name`='" . $GLOBALS['dbi']->escapeString($itemName) . "'"
. " AND `item_type`='" . $GLOBALS['dbi']->escapeString($itemType) . "'"
. " AND `db_name`='" . $GLOBALS['dbi']->escapeString($dbName) . "'"
. (! empty($tableName)
? " AND `table_name`='" . $GLOBALS['dbi']->escapeString($tableName) . "'"
: ""
);
PMA_queryAsControlUser($sqlQuery, false);
}
/**
* Returns HTML for the dialog to show hidden navigation items.
*
* @param string $dbName database name
* @param string $itemType type of the items to include
* @param string $tableName table name
*
* @return string HTML for the dialog to show hidden navigation items
*/
public function getItemUnhideDialog($dbName, $itemType = null, $tableName = null)
{
$html = '<form method="post" action="navigation.php" class="ajax">';
$html .= '<fieldset>';
$html .= PMA_URL_getHiddenInputs($dbName, $tableName);
$navTable = Util::backquote($GLOBALS['cfgRelation']['db'])
. "." . Util::backquote($GLOBALS['cfgRelation']['navigationhiding']);
$sqlQuery = "SELECT `item_name`, `item_type` FROM " . $navTable
. " WHERE `username`='"
. $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user']) . "'"
. " AND `db_name`='" . $GLOBALS['dbi']->escapeString($dbName) . "'"
. " AND `table_name`='"
. (! empty($tableName) ? $GLOBALS['dbi']->escapeString($tableName) : '') . "'";
$result = PMA_queryAsControlUser($sqlQuery, false);
$hidden = array();
if ($result) {
while ($row = $GLOBALS['dbi']->fetchArray($result)) {
$type = $row['item_type'];
if (! isset($hidden[$type])) {
$hidden[$type] = array();
}
$hidden[$type][] = $row['item_name'];
}
}
$GLOBALS['dbi']->freeResult($result);
$typeMap = array(
'group' => __('Groups:'),
'event' => __('Events:'),
'function' => __('Functions:'),
'procedure' => __('Procedures:'),
'table' => __('Tables:'),
'view' => __('Views:'),
);
if (empty($tableName)) {
$first = true;
foreach ($typeMap as $t => $lable) {
if ((empty($itemType) || $itemType == $t)
&& isset($hidden[$t])
) {
$html .= (! $first ? '<br/>' : '')
. '<strong>' . $lable . '</strong>';
$html .= '<table width="100%"><tbody>';
$odd = true;
foreach ($hidden[$t] as $hiddenItem) {
$html .= '<tr class="' . ($odd ? 'odd' : 'even') . '">';
$html .= '<td>' . htmlspecialchars($hiddenItem) . '</td>';
$html .= '<td style="width:80px"><a href="navigation.php'
. PMA_URL_getCommon()
. '&unhideNavItem=true'
. '&itemType=' . urlencode($t)
. '&itemName=' . urlencode($hiddenItem)
. '&dbName=' . urlencode($dbName) . '"'
. ' class="unhideNavItem ajax">'
. Util::getIcon('lightbulb.png', __('Show'))
. '</a></td>';
$odd = ! $odd;
}
$html .= '</tbody></table>';
$first = false;
}
}
}
$html .= '</fieldset>';
$html .= '</form>';
return $html;
}
}

View File

@ -0,0 +1,249 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Header for the navigation panel
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation;
use PMA;
use PMA\libraries\Template;
/**
* This class renders the logo, links, server selection,
* which are then displayed at the top of the navigation panel
*
* @package PhpMyAdmin-Navigation
*/
class NavigationHeader
{
/**
* Renders the navigation
*
* @return String HTML
*/
public function getDisplay()
{
if (empty($GLOBALS['url_query'])) {
$GLOBALS['url_query'] = PMA_URL_getCommon();
}
$link_url = PMA_URL_getCommon(
array(
'ajax_request' => true,
)
);
$class = ' class="list_container';
if ($GLOBALS['cfg']['NavigationLinkWithMainPanel']) {
$class .= ' synced';
}
if ($GLOBALS['cfg']['NavigationTreePointerEnable']) {
$class .= ' highlight';
}
$class .= '"';
$buffer = '<div id="pma_navigation">';
$buffer .= '<div id="pma_navigation_resizer"></div>';
$buffer .= '<div id="pma_navigation_collapser"></div>';
$buffer .= '<div id="pma_navigation_content">';
$buffer .= '<div id="pma_navigation_header">';
$buffer .= sprintf(
'<a class="hide navigation_url" href="navigation.php%s"></a>',
$link_url
);
$buffer .= $this->_logo();
$buffer .= $this->_links();
$buffer .= $this->_serverChoice();
$buffer .= PMA\libraries\Util::getImage(
'ajax_clock_small.gif',
__('Loading…'),
array(
'style' => 'visibility: hidden; display:none',
'class' => 'throbber',
)
);
$buffer .= '</div>'; // pma_navigation_header
$buffer .= '<div id="pma_navigation_tree"' . $class . '>';
return $buffer;
}
/**
* Create the code for displaying the phpMyAdmin
* logo based on configuration settings
*
* @return string HTML code for the logo
*/
private function _logo()
{
// display Logo, depending on $GLOBALS['cfg']['NavigationDisplayLogo']
if (!$GLOBALS['cfg']['NavigationDisplayLogo']) {
return Template::get('navigation/logo')
->render(array('displayLogo' => false));
}
$logo = 'phpMyAdmin';
if (@file_exists($GLOBALS['pmaThemeImage'] . 'logo_left.png')) {
$logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'logo_left.png" '
. 'alt="' . $logo . '" id="imgpmalogo" />';
} elseif (@file_exists($GLOBALS['pmaThemeImage'] . 'pma_logo2.png')) {
$logo = '<img src="' . $GLOBALS['pmaThemeImage'] . 'pma_logo2.png" '
. 'alt="' . $logo . '" id="imgpmalogo" />';
}
if (!$GLOBALS['cfg']['NavigationLogoLink']) {
return Template::get('navigation/logo')
->render(
array(
'displayLogo' => true,
'useLogoLink' => false,
'logo' => $logo,
)
);
}
$useLogoLink = true;
$linkAttriks = null;
$logoLink = trim(
htmlspecialchars($GLOBALS['cfg']['NavigationLogoLink'])
);
// prevent XSS, see PMASA-2013-9
// if link has protocol, allow only http and https
if (! PMA_checkLink($logoLink, true)) {
$logoLink = 'index.php';
}
switch ($GLOBALS['cfg']['NavigationLogoLinkWindow']) {
case 'new':
$linkAttriks = 'target="_blank" rel="noopener noreferrer"';
break;
case 'main':
// do not add our parameters for an external link
$host = parse_url(
$GLOBALS['cfg']['NavigationLogoLink'],
PHP_URL_HOST
);
if (empty($host)) {
$logoLink .= PMA_URL_getCommon();
} else {
$linkAttriks = 'target="_blank" rel="noopener noreferrer"';
}
}
return Template::get('navigation/logo')
->render(
array(
'displayLogo' => true,
'useLogoLink' => $useLogoLink,
'logoLink' => $logoLink,
'linkAttribs' => $linkAttriks,
'logo' => $logo,
)
);
}
/**
* Creates the code for displaying the links
* at the top of the navigation panel
*
* @return string HTML code for the links
*/
private function _links()
{
// always iconic
$showIcon = true;
$showText = false;
$retval = '<!-- LINKS START -->';
$retval .= '<div id="navipanellinks">';
$retval .= PMA\libraries\Util::getNavigationLink(
'index.php' . PMA_URL_getCommon(),
$showText,
__('Home'),
$showIcon,
'b_home.png'
);
// if we have chosen server
if ($GLOBALS['server'] != 0) {
// Logout for advanced authentication
if ($GLOBALS['cfg']['Server']['auth_type'] != 'config') {
$text = __('Log out');
} else {
$text = __('Empty session data');
}
$link = 'logout.php' . $GLOBALS['url_query'];
$retval .= PMA\libraries\Util::getNavigationLink(
$link,
$showText,
$text,
$showIcon,
's_loggoff.png',
'',
true
);
}
$retval .= PMA\libraries\Util::getNavigationLink(
PMA\libraries\Util::getDocuLink('index'),
$showText,
__('phpMyAdmin documentation'),
$showIcon,
'b_docs.png',
'',
false,
'documentation'
);
$retval .= PMA\libraries\Util::getNavigationLink(
PMA\libraries\Util::getMySQLDocuURL('', ''),
$showText,
__('Documentation'),
$showIcon,
'b_sqlhelp.png',
'',
false,
'mysql_doc'
);
$retval .= PMA\libraries\Util::getNavigationLink(
'#',
$showText,
__('Navigation panel settings'),
$showIcon,
's_cog.png',
'pma_navigation_settings_icon',
false,
'',
defined('PMA_DISABLE_NAVI_SETTINGS') ? array('hide') : array()
);
$retval .= PMA\libraries\Util::getNavigationLink(
'#',
$showText,
__('Reload navigation panel'),
$showIcon,
's_reload.png',
'pma_navigation_reload'
);
$retval .= '</div>';
$retval .= '<!-- LINKS ENDS -->';
return $retval;
}
/**
* Displays the MySQL servers choice form
*
* @return string HTML code for the MySQL servers choice
*/
private function _serverChoice()
{
$retval = '';
if ($GLOBALS['cfg']['NavigationDisplayServers']
&& count($GLOBALS['cfg']['Servers']) > 1
) {
include_once './libraries/select_server.lib.php';
$retval .= '<!-- SERVER CHOICE START -->';
$retval .= '<div id="serverChoice">';
$retval .= PMA_selectServer(true, true);
$retval .= '</div>';
$retval .= '<!-- SERVER CHOICE END -->';
}
return $retval;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,94 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* This class is responsible for creating Node objects
*
* @package PhpMyAdmin-navigation
*/
namespace PMA\libraries\navigation;
use PMA\libraries\navigation\nodes\Node;
use PMA\Psr4Autoloader;
/**
* Node factory - instantiates Node objects or objects derived from the Node class
*
* @package PhpMyAdmin-Navigation
*/
class NodeFactory
{
protected static $_namespace = 'PMA\\libraries\\navigation\\nodes\\%s';
/**
* Sanitizes the name of a Node class
*
* @param string $class The class name to be sanitized
*
* @return string
*/
private static function _sanitizeClass($class)
{
if (!preg_match('@^Node\w*$@', $class)) {
$class = 'Node';
trigger_error(
sprintf(
/* l10n: The word "Node" must not be translated here */
__('Invalid class name "%1$s", using default of "Node"'),
$class
),
E_USER_ERROR
);
}
return self::_checkClass($class);
}
/**
* Checks if a class exists and try to load it.
* Will return the default class name back if the
* file for some subclass is not available
*
* @param string $class The class name to check
*
* @return string
*/
private static function _checkClass($class)
{
$class = sprintf(self::$_namespace, $class);
if (!class_exists($class)
&& !Psr4Autoloader::getInstance()->loadClass($class)
) {
$class = sprintf(self::$_namespace, 'Node');
trigger_error(
sprintf(
__('Could not load class "%1$s"'),
$class
),
E_USER_ERROR
);
}
return $class;
}
/**
* Instantiates a Node object
*
* @param string $class The name of the class to instantiate
* @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 mixed
*/
public static function getInstance(
$class = 'Node',
$name = 'default',
$type = Node::OBJECT,
$is_group = false
) {
$class = self::_sanitizeClass($class);
return new $class($name, $type, $is_group);
}
}

View File

@ -0,0 +1,836 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree in the left frame
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA\libraries\Util;
/**
* The Node is the building block for the collapsible navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class Node
{
/**
* @var int Defines a possible node type
*/
const CONTAINER = 0;
/**
* @var int Defines a possible node type
*/
const OBJECT = 1;
/**
* @var string A non-unique identifier for the node
* This may be trimmed when grouping nodes
*/
public $name = "";
/**
* @var string A non-unique identifier for the node
* This will never change after being assigned
*/
public $real_name = "";
/**
* @var int May be one of CONTAINER or OBJECT
*/
public $type = Node::OBJECT;
/**
* @var bool Whether this object has been created while grouping nodes
* Only relevant if the node is of type CONTAINER
*/
public $is_group;
/**
* @var bool Whether to add a "display: none;" CSS
* rule to the node when rendering it
*/
public $visible = false;
/**
* @var Node A reference to the parent object of
* this node, NULL for the root node.
*/
public $parent;
/**
* @var Node[] An array of Node objects that are
* direct children of this node
*/
public $children = array();
/**
* @var Mixed A string used to group nodes, or an array of strings
* Only relevant if the node is of type CONTAINER
*/
public $separator = '';
/**
* @var int How many time to recursively apply the grouping function
* Only relevant if the node is of type CONTAINER
*/
public $separator_depth = 1;
/**
* @var string An IMG tag, used when rendering the node
*/
public $icon;
/**
* @var array An array of A tags, used when rendering the node
* The indexes in the array may be 'icon' and 'text'
*/
public $links;
/**
* @var string HTML title
*/
public $title;
/**
* @var string Extra CSS classes for the node
*/
public $classes = '';
/**
* @var bool Whether this node is a link for creating new objects
*/
public $isNew = false;
/**
* @var int The position for the pagination of
* the branch at the second level of the tree
*/
public $pos2 = 0;
/**
* @var int The position for the pagination of
* the branch at the third level of the tree
*/
public $pos3 = 0;
/**
* Initialises the class by setting the mandatory variables
*
* @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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
if (!empty($name)) {
$this->name = $name;
$this->real_name = $name;
}
if ($type === Node::CONTAINER) {
$this->type = Node::CONTAINER;
}
$this->is_group = (bool)$is_group;
}
/**
* Adds a child node to this node
*
* @param Node $child A child node
*
* @return void
*/
public function addChild($child)
{
$this->children[] = $child;
$child->parent = $this;
}
/**
* Returns a child node given it's name
*
* @param string $name The name of requested child
* @param bool $real_name Whether to use the "real_name"
* instead of "name" in comparisons
*
* @return false|Node The requested child node or false,
* if the requested node cannot be found
*/
public function getChild($name, $real_name = false)
{
if ($real_name) {
foreach ($this->children as $child) {
if ($child->real_name == $name) {
return $child;
}
}
} else {
foreach ($this->children as $child) {
if ($child->name == $name) {
return $child;
}
}
}
return false;
}
/**
* Removes a child node from this node
*
* @param string $name The name of child to be removed
*
* @return void
*/
public function removeChild($name)
{
foreach ($this->children as $key => $child) {
if ($child->name == $name) {
unset($this->children[$key]);
break;
}
}
}
/**
* Retrieves the parents for a node
*
* @param bool $self Whether to include the Node itself in the results
* @param bool $containers Whether to include nodes of type CONTAINER
* @param bool $groups Whether to include nodes which have $group == true
*
* @return array An array of parent Nodes
*/
public function parents($self = false, $containers = false, $groups = false)
{
$parents = array();
if ($self
&& ($this->type != Node::CONTAINER || $containers)
&& (!$this->is_group || $groups)
) {
$parents[] = $this;
}
$parent = $this->parent;
while (isset($parent)) {
if (($parent->type != Node::CONTAINER || $containers)
&& (!$parent->is_group || $groups)
) {
$parents[] = $parent;
}
$parent = $parent->parent;
}
return $parents;
}
/**
* Returns the actual parent of a node. If used twice on an index or columns
* node, it will return the table and database nodes. The names of the returned
* nodes can be used in SQL queries, etc...
*
* @return Node|false
*/
public function realParent()
{
$retval = $this->parents();
if (count($retval) <= 0) {
return false;
}
return $retval[0];
}
/**
* This function checks if the node has children nodes associated with it
*
* @param bool $count_empty_containers Whether to count empty child
* containers as valid children
*
* @return bool Whether the node has child nodes
*/
public function hasChildren($count_empty_containers = true)
{
$retval = false;
if ($count_empty_containers) {
if (count($this->children)) {
$retval = true;
}
} else {
foreach ($this->children as $child) {
if ($child->type == Node::OBJECT || $child->hasChildren(false)) {
$retval = true;
break;
}
}
}
return $retval;
}
/**
* Returns true if the node has some siblings (other nodes on the same tree
* level, in the same branch), false otherwise.
* The only exception is for nodes on
* the third level of the tree (columns and indexes), for which the function
* always returns true. This is because we want to render the containers
* for these nodes
*
* @return bool
*/
public function hasSiblings()
{
$retval = false;
$paths = $this->getPaths();
if (count($paths['aPath_clean']) > 3) {
$retval = true;
return $retval;
}
foreach ($this->parent->children as $child) {
if ($child !== $this
&& ($child->type == Node::OBJECT || $child->hasChildren(false))
) {
$retval = true;
break;
}
}
return $retval;
}
/**
* Returns the number of child nodes that a node has associated with it
*
* @return int The number of children nodes
*/
public function numChildren()
{
$retval = 0;
foreach ($this->children as $child) {
if ($child->type == Node::OBJECT) {
$retval++;
} else {
$retval += $child->numChildren();
}
}
return $retval;
}
/**
* Returns the actual path and the virtual paths for a node
* both as clean arrays and base64 encoded strings
*
* @return array
*/
public function getPaths()
{
$aPath = array();
$aPath_clean = array();
foreach ($this->parents(true, true, false) as $parent) {
$aPath[] = base64_encode($parent->real_name);
$aPath_clean[] = $parent->real_name;
}
$aPath = implode('.', array_reverse($aPath));
$aPath_clean = array_reverse($aPath_clean);
$vPath = array();
$vPath_clean = array();
foreach ($this->parents(true, true, true) as $parent) {
$vPath[] = base64_encode($parent->name);
$vPath_clean[] = $parent->name;
}
$vPath = implode('.', array_reverse($vPath));
$vPath_clean = array_reverse($vPath_clean);
return array(
'aPath' => $aPath,
'aPath_clean' => $aPath_clean,
'vPath' => $vPath,
'vPath_clean' => $vPath_clean,
);
}
/**
* Returns the names of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase and PMA\libraries\navigation\nodes\NodeTable 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']['FirstLevelNavigationItems'];
if (!$GLOBALS['cfg']['NavigationTreeEnableGrouping']
|| !$GLOBALS['cfg']['ShowDatabasesNavigationAsTree']
) {
if (isset($GLOBALS['cfg']['Server']['DisableIS'])
&& !$GLOBALS['cfg']['Server']['DisableIS']
) {
$query = "SELECT `SCHEMA_NAME` ";
$query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` ";
$query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
$query .= "ORDER BY `SCHEMA_NAME` ";
$query .= "LIMIT $pos, $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
return $retval;
}
if ($GLOBALS['dbs_to_test'] === false) {
$retval = array();
$query = "SHOW DATABASES ";
$query .= $this->_getWhereClause('Database', $searchClause);
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
return $retval;
}
$count = 0;
if (!$GLOBALS['dbi']->dataSeek($handle, $pos)) {
return $retval;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr[0];
$count++;
} else {
break;
}
}
return $retval;
}
$retval = array();
$count = 0;
foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
continue;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($this->_isHideDb($arr[0])) {
continue;
}
if (in_array($arr[0], $retval)) {
continue;
}
if ($pos <= 0 && $count < $maxItems) {
$retval[] = $arr[0];
$count++;
}
$pos--;
}
}
sort($retval);
return $retval;
}
$dbSeparator = $GLOBALS['cfg']['NavigationTreeDbSeparator'];
if (isset($GLOBALS['cfg']['Server']['DisableIS'])
&& !$GLOBALS['cfg']['Server']['DisableIS']
) {
$query = "SELECT `SCHEMA_NAME` ";
$query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA`, ";
$query .= "(";
$query .= "SELECT DB_first_level ";
$query .= "FROM ( ";
$query .= "SELECT DISTINCT SUBSTRING_INDEX(SCHEMA_NAME, ";
$query .= "'" . $GLOBALS['dbi']->escapeString($dbSeparator) . "', 1) ";
$query .= "DB_first_level ";
$query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
$query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
$query .= ") t ";
$query .= "ORDER BY DB_first_level ASC ";
$query .= "LIMIT $pos, $maxItems";
$query .= ") t2 ";
$query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
$query .= "AND 1 = LOCATE(CONCAT(DB_first_level, ";
$query .= "'" . $GLOBALS['dbi']->escapeString($dbSeparator) . "'), ";
$query .= "CONCAT(SCHEMA_NAME, ";
$query .= "'" . $GLOBALS['dbi']->escapeString($dbSeparator) . "')) ";
$query .= "ORDER BY SCHEMA_NAME ASC";
$retval = $GLOBALS['dbi']->fetchResult($query);
return $retval;
}
if ($GLOBALS['dbs_to_test'] === false) {
$query = "SHOW DATABASES ";
$query .= $this->_getWhereClause('Database', $searchClause);
$handle = $GLOBALS['dbi']->tryQuery($query);
$prefixes = array();
if ($handle !== false) {
$prefixMap = array();
$total = $pos + $maxItems;
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
$prefix = strstr($arr[0], $dbSeparator, true);
if ($prefix === false) {
$prefix = $arr[0];
}
$prefixMap[$prefix] = 1;
if (sizeof($prefixMap) == $total) {
break;
}
}
$prefixes = array_slice(array_keys($prefixMap), $pos);
}
$query = "SHOW DATABASES ";
$query .= $this->_getWhereClause('Database', $searchClause);
$query .= "AND (";
$subClauses = array();
foreach ($prefixes as $prefix) {
$subClauses[] = " LOCATE('"
. $GLOBALS['dbi']->escapeString($prefix) . $dbSeparator
. "', "
. "CONCAT(`Database`, '" . $dbSeparator . "')) = 1 ";
}
$query .= implode("OR", $subClauses) . ")";
$retval = $GLOBALS['dbi']->fetchResult($query);
return $retval;
}
$retval = array();
$prefixMap = array();
$total = $pos + $maxItems;
foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
continue;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($this->_isHideDb($arr[0])) {
continue;
}
$prefix = strstr($arr[0], $dbSeparator, true);
if ($prefix === false) {
$prefix = $arr[0];
}
$prefixMap[$prefix] = 1;
if (sizeof($prefixMap) == $total) {
break 2;
}
}
}
$prefixes = array_slice(array_keys($prefixMap), $pos);
foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
continue;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($this->_isHideDb($arr[0])) {
continue;
}
if (in_array($arr[0], $retval)) {
continue;
}
foreach ($prefixes as $prefix) {
$starts_with = strpos(
$arr[0] . $dbSeparator,
$prefix . $dbSeparator
) === 0;
if ($starts_with) {
$retval[] = $arr[0];
break;
}
}
}
}
sort($retval);
return $retval;
}
/**
* Returns the number of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase and PMA\libraries\navigation\nodes\NodeTable 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 = '')
{
if (!$GLOBALS['cfg']['NavigationTreeEnableGrouping']
|| !$GLOBALS['cfg']['ShowDatabasesNavigationAsTree']
) {
if (isset($GLOBALS['cfg']['Server']['DisableIS'])
&& !$GLOBALS['cfg']['Server']['DisableIS']
) {
$query = "SELECT COUNT(*) ";
$query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
$query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
return $retval;
}
if ($GLOBALS['dbs_to_test'] === false) {
$query = "SHOW DATABASES ";
$query .= $this->_getWhereClause('Database', $searchClause);
$retval = $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
return $retval;
}
$retval = 0;
foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$retval += $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
return $retval;
}
$dbSeparator = $GLOBALS['cfg']['NavigationTreeDbSeparator'];
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$query = "SELECT COUNT(*) ";
$query .= "FROM ( ";
$query .= "SELECT DISTINCT SUBSTRING_INDEX(SCHEMA_NAME, ";
$query .= "'$dbSeparator', 1) ";
$query .= "DB_first_level ";
$query .= "FROM INFORMATION_SCHEMA.SCHEMATA ";
$query .= $this->_getWhereClause('SCHEMA_NAME', $searchClause);
$query .= ") t ";
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
return $retval;
}
if ($GLOBALS['dbs_to_test'] !== false) {
$prefixMap = array();
foreach ($this->_getDatabasesToSearch($searchClause) as $db) {
$query = "SHOW DATABASES LIKE '" . $db . "'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
continue;
}
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($this->_isHideDb($arr[0])) {
continue;
}
$prefix = strstr($arr[0], $dbSeparator, true);
if ($prefix === false) {
$prefix = $arr[0];
}
$prefixMap[$prefix] = 1;
}
}
$retval = count($prefixMap);
return $retval;
}
$prefixMap = array();
$query = "SHOW DATABASES ";
$query .= $this->_getWhereClause('Database', $searchClause);
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle !== false) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
$prefix = strstr($arr[0], $dbSeparator, true);
if ($prefix === false) {
$prefix = $arr[0];
}
$prefixMap[$prefix] = 1;
}
}
$retval = count($prefixMap);
return $retval;
}
/**
* Detemines whether a given database should be hidden according to 'hide_db'
*
* @param string $db database name
*
* @return boolean whether to hide
*/
private function _isHideDb($db)
{
if (!empty($GLOBALS['cfg']['Server']['hide_db'])
&& preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)
) {
return true;
}
return false;
}
/**
* Get the list of databases for 'SHOW DATABASES LIKE' queries.
* If a search clause is set it gets the highest priority while only_db gets
* the next priority. In case both are empty list of databases determined by
* GRANTs are used
*
* @param string $searchClause search clause
*
* @return array array of databases
*/
private function _getDatabasesToSearch($searchClause)
{
if (!empty($searchClause)) {
$databases = array(
"%" . $GLOBALS['dbi']->escapeString($searchClause, true) . "%",
);
} elseif (!empty($GLOBALS['cfg']['Server']['only_db'])) {
$databases = $GLOBALS['cfg']['Server']['only_db'];
} elseif (!empty($GLOBALS['dbs_to_test'])) {
$databases = $GLOBALS['dbs_to_test'];
}
sort($databases);
return $databases;
}
/**
* Returns the WHERE clause depending on the $searchClause parameter
* and the hide_db directive
*
* @param string $columnName Column name of the column having database names
* @param string $searchClause A string used to filter the results of the query
*
* @return string
*/
private function _getWhereClause($columnName, $searchClause = '')
{
$whereClause = "WHERE TRUE ";
if (!empty($searchClause)) {
$whereClause .= "AND " . Util::backquote($columnName)
. " LIKE '%";
$whereClause .= $GLOBALS['dbi']->escapeString(
$searchClause,
true
);
$whereClause .= "%' ";
}
if (!empty($GLOBALS['cfg']['Server']['hide_db'])) {
$whereClause .= "AND " . Util::backquote($columnName)
. " NOT REGEXP '"
. $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['hide_db'])
. "' ";
}
if (!empty($GLOBALS['cfg']['Server']['only_db'])) {
if (is_string($GLOBALS['cfg']['Server']['only_db'])) {
$GLOBALS['cfg']['Server']['only_db'] = array(
$GLOBALS['cfg']['Server']['only_db'],
);
}
$whereClause .= "AND (";
$subClauses = array();
foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) {
$subClauses[] = " " . Util::backquote($columnName)
. " LIKE '"
. $GLOBALS['dbi']->escapeString($each_only_db) . "' ";
}
$whereClause .= implode("OR", $subClauses) . ") ";
}
return $whereClause;
}
/**
* Returns HTML for control buttons displayed infront of a node
*
* @return String HTML for control buttons
*/
public function getHtmlForControlButtons()
{
return '';
}
/**
* Returns CSS classes for a node
*
* @param boolean $match Whether the node matched loaded tree
*
* @return String with html classes.
*/
public function getCssClasses($match)
{
if (!$GLOBALS['cfg']['NavigationTreeEnableExpansion']
) {
return '';
}
$result = array('expander');
if ($this->is_group || $match) {
$result[] = 'loaded';
}
if ($this->type == Node::CONTAINER) {
$result[] = 'container';
}
return implode(' ', $result);
}
/**
* Returns icon for the node
*
* @param boolean $match Whether the node matched loaded tree
*
* @return String with image name
*/
public function getIcon($match)
{
if (!$GLOBALS['cfg']['NavigationTreeEnableExpansion']
) {
return '';
} elseif ($match && !$this->is_group) {
$this->visible = true;
return Util::getImage('b_minus.png');
} else {
return Util::getImage('b_plus.png', __('Expand/Collapse'));
}
}
/**
* Gets the count of hidden elements for each database
*
* @return array array containing the count of hidden elements for each database
*/
public function getNavigationHidingData()
{
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['navwork']) {
$navTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote(
$cfgRelation['navigationhiding']
);
$sqlQuery = "SELECT `db_name`, COUNT(*) AS `count` FROM " . $navTable
. " WHERE `username`='"
. $GLOBALS['dbi']->escapeString(
$GLOBALS['cfg']['Server']['user']
) . "'"
. " GROUP BY `db_name`";
$counts = $GLOBALS['dbi']->fetchResult(
$sqlQuery,
'db_name',
'count',
$GLOBALS['controllink']
);
return $counts;
}
return null;
}
}

View File

@ -0,0 +1,44 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a columns node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeColumn 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('pause.png', __('Column'));
$this->links = array(
'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
. '&amp;change_column=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s&amp;field=%1$s'
. '&amp;change_column=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
'title' => __('Structure'),
);
}
}

View File

@ -0,0 +1,59 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
use PMA\libraries\Util;
/**
* Represents a container for column nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeColumnContainer extends Node
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Columns'), Node::CONTAINER);
$this->icon = Util::getImage('pause.png', __('Columns'));
$this->links = array(
'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->real_name = 'columns';
$new_label = _pgettext('Create new column', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = Util::getImage('b_column_add.png', $new_label);
$new->links = array(
'text' => 'tbl_addfield.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s'
. '&amp;field_where=last&after_field='
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_addfield.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s'
. '&amp;field_where=last&after_field='
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$new->classes = 'new_column italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,712 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA\libraries\Util;
/**
* Represents a database node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeDatabase extends Node
{
/**
* The number of hidden items in this database
*
* @var int
*/
protected $hiddenCount = 0;
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = Util::getImage(
's_db.png',
__('Database operations')
);
$script_name = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabDatabase'],
'database'
);
$this->links = array(
'text' => $script_name
. '?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_operations.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '],
'title' => __('Structure'),
);
$this->classes = 'database';
}
/**
* Returns the number of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase
* and PMA\libraries\navigation\nodes\NodeTable 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
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
public function getPresence($type = '', $searchClause = '', $singleItem = false)
{
$retval = 0;
switch ($type) {
case 'tables':
$retval = $this->_getTableCount($searchClause, $singleItem);
break;
case 'views':
$retval = $this->_getViewCount($searchClause, $singleItem);
break;
case 'procedures':
$retval = $this->_getProcedureCount($searchClause, $singleItem);
break;
case 'functions':
$retval = $this->_getFunctionCount($searchClause, $singleItem);
break;
case 'events':
$retval = $this->_getEventCount($searchClause, $singleItem);
break;
default:
break;
}
return $retval;
}
/**
* Returns the number of tables or views present inside this database
*
* @param string $which tables|views
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getTableOrViewCount($which, $searchClause, $singleItem)
{
$db = $this->real_name;
if ($which == 'tables') {
$condition = '=';
} else {
$condition = '!=';
}
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
$query .= "WHERE `TABLE_SCHEMA`='$db' ";
$query .= "AND `TABLE_TYPE`" . $condition . "'BASE TABLE' ";
if (! empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'TABLE_NAME'
);
}
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$query = "SHOW FULL TABLES FROM ";
$query .= Util::backquote($db);
$query .= " WHERE `Table_type`" . $condition . "'BASE TABLE' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'Tables_in_' . $db
);
}
$retval = $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
return $retval;
}
/**
* Returns the number of tables present inside this database
*
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getTableCount($searchClause, $singleItem)
{
return $this->_getTableOrViewCount(
'tables',
$searchClause,
$singleItem
);
}
/**
* Returns the number of views present inside this database
*
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getViewCount($searchClause, $singleItem)
{
return $this->_getTableOrViewCount(
'views',
$searchClause,
$singleItem
);
}
/**
* Returns the number of procedures present inside this database
*
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getProcedureCount($searchClause, $singleItem)
{
$db = $this->real_name;
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
$query .= "WHERE `ROUTINE_SCHEMA` "
. Util::getCollateForIS() . "='$db'";
$query .= "AND `ROUTINE_TYPE`='PROCEDURE' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'ROUTINE_NAME'
);
}
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'Name'
);
}
$retval = $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
return $retval;
}
/**
* Returns the number of functions present inside this database
*
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getFunctionCount($searchClause, $singleItem)
{
$db = $this->real_name;
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
$query .= "WHERE `ROUTINE_SCHEMA` "
. Util::getCollateForIS() . "='$db' ";
$query .= "AND `ROUTINE_TYPE`='FUNCTION' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'ROUTINE_NAME'
);
}
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SHOW FUNCTION STATUS WHERE `Db`='$db' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'Name'
);
}
$retval = $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
return $retval;
}
/**
* Returns the number of events present inside this database
*
* @param string $searchClause A string used to filter the results of
* the query
* @param boolean $singleItem Whether to get presence of a single known
* item or false in none
*
* @return int
*/
private function _getEventCount($searchClause, $singleItem)
{
$db = $this->real_name;
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
$query .= "WHERE `EVENT_SCHEMA` "
. Util::getCollateForIS() . "='$db' ";
if (!empty($searchClause)) {
$query .= "AND " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'EVENT_NAME'
);
}
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$db = Util::backquote($db);
$query = "SHOW EVENTS FROM $db ";
if (!empty($searchClause)) {
$query .= "WHERE " . $this->_getWhereClauseForSearch(
$searchClause,
$singleItem,
'Name'
);
}
$retval = $GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
return $retval;
}
/**
* Returns the WHERE clause for searching inside a database
*
* @param string $searchClause A string used to filter the results of the query
* @param boolean $singleItem Whether to get presence of a single known item
* @param string $columnName Name of the column in the result set to match
*
* @return string WHERE clause for searching
*/
private function _getWhereClauseForSearch(
$searchClause,
$singleItem,
$columnName
) {
$query = '';
if ($singleItem) {
$query .= Util::backquote($columnName) . " = ";
$query .= "'" . $GLOBALS['dbi']->escapeString($searchClause) . "'";
} else {
$query .= Util::backquote($columnName) . " LIKE ";
$query .= "'%" . $GLOBALS['dbi']->escapeString($searchClause)
. "%'";
}
return $query;
}
/**
* Returns the names of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase
* and PMA\libraries\navigation\nodes\NodeTable 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 = '')
{
$retval = array();
switch ($type) {
case 'tables':
$retval = $this->_getTables($pos, $searchClause);
break;
case 'views':
$retval = $this->_getViews($pos, $searchClause);
break;
case 'procedures':
$retval = $this->_getProcedures($pos, $searchClause);
break;
case 'functions':
$retval = $this->_getFunctions($pos, $searchClause);
break;
case 'events':
$retval = $this->_getEvents($pos, $searchClause);
break;
default:
break;
}
// Remove hidden items so that they are not displayed in navigation tree
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['navwork']) {
$hiddenItems = $this->getHiddenItems(substr($type, 0, -1));
foreach ($retval as $key => $item) {
if (in_array($item, $hiddenItems)) {
unset($retval[$key]);
}
}
}
return $retval;
}
/**
* Return list of hidden items of given type
*
* @param string $type The type of items we are looking for
* ('table', 'function', 'group', etc.)
*
* @return array Array containing hidden items of given type
*/
public function getHiddenItems($type)
{
$db = $this->real_name;
$cfgRelation = PMA_getRelationsParam();
if (empty($cfgRelation['navigationhiding'])) {
return array();
}
$navTable = Util::backquote($cfgRelation['db'])
. "." . Util::backquote($cfgRelation['navigationhiding']);
$sqlQuery = "SELECT `item_name` FROM " . $navTable
. " WHERE `username`='" . $cfgRelation['user'] . "'"
. " AND `item_type`='" . $type
. "'" . " AND `db_name`='" . $GLOBALS['dbi']->escapeString($db)
. "'";
$result = PMA_queryAsControlUser($sqlQuery, false);
$hiddenItems = array();
if ($result) {
while ($row = $GLOBALS['dbi']->fetchArray($result)) {
$hiddenItems[] = $row[0];
}
}
$GLOBALS['dbi']->freeResult($result);
return $hiddenItems;
}
/**
* Returns the list of tables or views inside this database
*
* @param string $which tables|views
* @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
*/
private function _getTablesOrViews($which, $pos, $searchClause)
{
if ($which == 'tables') {
$condition = '=';
} else {
$condition = '!=';
}
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
$retval = array();
$db = $this->real_name;
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$escdDb = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT `TABLE_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
$query .= "WHERE `TABLE_SCHEMA`='$escdDb' ";
$query .= "AND `TABLE_TYPE`" . $condition . "'BASE TABLE' ";
if (! empty($searchClause)) {
$query .= "AND `TABLE_NAME` LIKE '%";
$query .= $GLOBALS['dbi']->escapeString($searchClause);
$query .= "%'";
}
$query .= "ORDER BY `TABLE_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
} else {
$query = " SHOW FULL TABLES FROM ";
$query .= Util::backquote($db);
$query .= " WHERE `Table_type`" . $condition . "'BASE TABLE' ";
if (!empty($searchClause)) {
$query .= "AND " . Util::backquote(
"Tables_in_" . $db
);
$query .= " LIKE '%" . $GLOBALS['dbi']->escapeString(
$searchClause
);
$query .= "%'";
}
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle !== false) {
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr[0];
$count++;
} else {
break;
}
}
}
}
}
return $retval;
}
/**
* Returns the list of tables inside this database
*
* @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
*/
private function _getTables($pos, $searchClause)
{
return $this->_getTablesOrViews('tables', $pos, $searchClause);
}
/**
* Returns the list of views inside this database
*
* @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
*/
private function _getViews($pos, $searchClause)
{
return $this->_getTablesOrViews('views', $pos, $searchClause);
}
/**
* Returns the list of procedures or functions inside this database
*
* @param string $routineType PROCEDURE|FUNCTION
* @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
*/
private function _getRoutines($routineType, $pos, $searchClause)
{
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
$retval = array();
$db = $this->real_name;
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$escdDb = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT `ROUTINE_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`ROUTINES` ";
$query .= "WHERE `ROUTINE_SCHEMA` "
. Util::getCollateForIS() . "='$escdDb'";
$query .= "AND `ROUTINE_TYPE`='" . $routineType . "' ";
if (!empty($searchClause)) {
$query .= "AND `ROUTINE_NAME` LIKE '%";
$query .= $GLOBALS['dbi']->escapeString($searchClause);
$query .= "%'";
}
$query .= "ORDER BY `ROUTINE_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
} else {
$escdDb = $GLOBALS['dbi']->escapeString($db);
$query = "SHOW " . $routineType . " STATUS WHERE `Db`='$escdDb' ";
if (!empty($searchClause)) {
$query .= "AND `Name` LIKE '%";
$query .= $GLOBALS['dbi']->escapeString($searchClause);
$query .= "%'";
}
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle !== false) {
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Name'];
$count++;
} else {
break;
}
}
}
}
}
return $retval;
}
/**
* Returns the list of procedures inside this database
*
* @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
*/
private function _getProcedures($pos, $searchClause)
{
return $this->_getRoutines('PROCEDURE', $pos, $searchClause);
}
/**
* Returns the list of functions inside this database
*
* @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
*/
private function _getFunctions($pos, $searchClause)
{
return $this->_getRoutines('FUNCTION', $pos, $searchClause);
}
/**
* Returns the list of events inside this database
*
* @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
*/
private function _getEvents($pos, $searchClause)
{
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
$retval = array();
$db = $this->real_name;
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$escdDb = $GLOBALS['dbi']->escapeString($db);
$query = "SELECT `EVENT_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` ";
$query .= "WHERE `EVENT_SCHEMA` "
. Util::getCollateForIS() . "='$escdDb' ";
if (!empty($searchClause)) {
$query .= "AND `EVENT_NAME` LIKE '%";
$query .= $GLOBALS['dbi']->escapeString($searchClause);
$query .= "%'";
}
$query .= "ORDER BY `EVENT_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
} else {
$escdDb = Util::backquote($db);
$query = "SHOW EVENTS FROM $escdDb ";
if (!empty($searchClause)) {
$query .= "WHERE `Name` LIKE '%";
$query .= $GLOBALS['dbi']->escapeString($searchClause);
$query .= "%'";
}
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle !== false) {
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Name'];
$count++;
} else {
break;
}
}
}
}
}
return $retval;
}
/**
* Returns HTML for control buttons displayed infront of a node
*
* @return String HTML for control buttons
*/
public function getHtmlForControlButtons()
{
$ret = '';
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['navwork']) {
if ($this->hiddenCount > 0) {
$ret = '<span class="dbItemControls">'
. '<a href="navigation.php'
. PMA_URL_getCommon()
. '&showUnhideDialog=true'
. '&dbName=' . urlencode($this->real_name) . '"'
. ' class="showUnhide ajax">'
. Util::getImage(
'lightbulb.png',
__('Show hidden items')
)
. '</a></span>';
}
}
return $ret;
}
/**
* Sets the number of hidden items in this database
*
* @param int $count hidden item count
*
* @return void
*/
public function setHiddenCount($count)
{
$this->hiddenCount = $count;
}
/**
* Returns the number of hidden items in this database
*
* @return int hidden item count
*/
public function getHiddenCount()
{
return $this->hiddenCount;
}
}

View File

@ -0,0 +1,54 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a node that is a child of a database node
* This may either be a concrete child such as table or a container
* such as table container
*
* @package PhpMyAdmin-Navigation
*/
abstract class NodeDatabaseChild extends Node
{
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected abstract function getItemType();
/**
* Returns HTML for control buttons displayed infront of a node
*
* @return String HTML for control buttons
*/
public function getHtmlForControlButtons()
{
$ret = '';
$cfgRelation = PMA_getRelationsParam();
if ($cfgRelation['navwork']) {
$db = $this->realParent()->real_name;
$item = $this->real_name;
$ret = '<span class="navItemControls">'
. '<a href="navigation.php'
. PMA_URL_getCommon()
. '&hideNavItem=true'
. '&itemType=' . urlencode($this->getItemType())
. '&itemName=' . urlencode($item)
. '&dbName=' . urlencode($db) . '"'
. ' class="hideNavItem ajax">'
. PMA\libraries\Util::getImage('lightbulb_off.png', __('Hide'))
. '</a></span>';
}
return $ret;
}
}

View File

@ -0,0 +1,43 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Represents container node that carries children of a database
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
/**
* Represents container node that carries children of a database
*
* @package PhpMyAdmin-Navigation
*/
abstract class NodeDatabaseChildContainer extends NodeDatabaseChild
{
/**
* Initialises the class by setting the common variables
*
* @param string $name An identifier for the new node
* @param int $type Type of node, may be one of CONTAINER or OBJECT
*/
public function __construct($name, $type = Node::OBJECT)
{
parent::__construct($name, $type);
if ($GLOBALS['cfg']['NavigationTreeEnableGrouping']) {
$this->separator = $GLOBALS['cfg']['NavigationTreeTableSeparator'];
$this->separator_depth = (int)(
$GLOBALS['cfg']['NavigationTreeTableLevel']
);
}
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'group';
}
}

View File

@ -0,0 +1,50 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
require_once './libraries/check_user_privileges.lib.php';
/**
* Represents a container for database nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeDatabaseContainer extends Node
{
/**
* Initialises the class
*
* @param string $name An identifier for the new node
*/
public function __construct($name)
{
parent::__construct($name, Node::CONTAINER);
if ($GLOBALS['is_create_db_priv']
&& $GLOBALS['cfg']['ShowCreateDb'] !== false
) {
$new = NodeFactory::getInstance(
'Node',
_pgettext('Create new database', 'New')
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_newdb.png', '');
$new->links = array(
'text' => 'server_databases.php?server=' . $GLOBALS['server']
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'server_databases.php?server=' . $GLOBALS['server']
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$new->classes = 'new_database italics';
$this->addChild($new);
}
}
}

View File

@ -0,0 +1,52 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a event node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeEvent extends NodeDatabaseChild
{
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('b_events.png');
$this->links = array(
'text' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;edit_item=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;export_item=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'event';
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'event';
}
}

View File

@ -0,0 +1,53 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for events nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeEventContainer extends NodeDatabaseChildContainer
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Events'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage('b_events.png', '');
$this->links = array(
'text' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token '],
);
$this->real_name = 'events';
$new = NodeFactory::getInstance(
'Node',
_pgettext('Create new event', 'New')
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_event_add.png', '');
$new->links = array(
'text' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1',
'icon' => 'db_events.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1',
);
$new->classes = 'new_event italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,52 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a function node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeFunction extends NodeDatabaseChild
{
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('b_routines.png', __('Function'));
$this->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=FUNCTION'
. '&amp;edit_item=1&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=FUNCTION'
. '&amp;execute_dialog=1&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'function';
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'function';
}
}

View File

@ -0,0 +1,59 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for functions nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeFunctionContainer extends NodeDatabaseChildContainer
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Functions'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage(
'b_routines.png',
__('Functions')
);
$this->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;type=FUNCTION',
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;type=FUNCTION',
);
$this->real_name = 'functions';
$new_label = _pgettext('Create new function', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_routine_add.png', $new_label);
$new->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1&amp;item_type=FUNCTION',
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1&amp;item_type=FUNCTION',
);
$new->classes = 'new_function italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,42 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a index node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeIndex 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('b_index.png', __('Index'));
$this->links = array(
'text' => 'tbl_indexes.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s&amp;index=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;table=%2$s&amp;index=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'index';
}
}

View File

@ -0,0 +1,58 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for index nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeIndexContainer extends Node
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Indexes'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage('b_index.png', __('Indexes'));
$this->links = array(
'text' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->real_name = 'indexes';
$new_label = _pgettext('Create new index', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_index_add.png', $new_label);
$new->links = array(
'text' => 'tbl_indexes.php?server=' . $GLOBALS['server']
. '&amp;create_index=1&amp;added_fields=2'
. '&amp;db=%3$s&amp;table=%2$s&amp;token='
. $_SESSION[' PMA_token '],
'icon' => 'tbl_indexes.php?server=' . $GLOBALS['server']
. '&amp;create_index=1&amp;added_fields=2'
. '&amp;db=%3$s&amp;table=%2$s&amp;token='
. $_SESSION[' PMA_token '],
);
$new->classes = 'new_index italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a procedure node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeProcedure extends NodeDatabaseChild
{
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage(
'b_routines.png',
__('Procedure')
);
$this->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=PROCEDURE'
. '&amp;edit_item=1&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;item_name=%1$s&amp;item_type=PROCEDURE'
. '&amp;execute_dialog=1&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'procedure';
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'procedure';
}
}

View File

@ -0,0 +1,59 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for procedure nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeProcedureContainer extends NodeDatabaseChildContainer
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Procedures'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage(
'b_routines.png',
__('Procedures')
);
$this->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;type=PROCEDURE',
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;type=PROCEDURE',
);
$this->real_name = 'procedures';
$new_label = _pgettext('Create new procedure', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_routine_add.png', $new_label);
$new->links = array(
'text' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1',
'icon' => 'db_routines.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token ']
. '&add_item=1',
);
$new->classes = 'new_procedure italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,319 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA\libraries\Util;
/**
* Represents a columns node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeTable extends NodeDatabaseChild
{
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = array();
$this->_addIcon(
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'],
'table'
)
);
$this->_addIcon(
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'],
'table'
)
);
$title = Util::getTitleForTarget(
$GLOBALS['cfg']['DefaultTabTable']
);
$this->title = $title;
$script_name = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabTable'],
'table'
);
$this->links = array(
'text' => $script_name
. '?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;pos=0&amp;token=' . $_SESSION[' PMA_token '],
'icon' => array(
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'],
'table'
)
. '?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s&amp;token='
. $_SESSION[' PMA_token '],
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'],
'table'
)
. '?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s&amp;token='
. $_SESSION[' PMA_token '],
),
'title' => $this->title,
);
$this->classes = 'table';
}
/**
* Returns the number of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase
* and PMA\libraries\navigation\nodes\NodeTable classes
*
* @param string $type The type of item we are looking for
* ('columns' or 'indexes')
* @param string $searchClause A string used to filter the results of the query
*
* @return int
*/
public function getPresence($type = '', $searchClause = '')
{
$retval = 0;
$db = $this->realParent()->real_name;
$table = $this->real_name;
switch ($type) {
case 'columns':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
$query .= "WHERE `TABLE_NAME`='$table' ";
$query .= "AND `TABLE_SCHEMA`='$db'";
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW COLUMNS FROM $table FROM $db";
$retval = (int)$GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
break;
case 'indexes':
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW INDEXES FROM $table FROM $db";
$retval = (int)$GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
break;
case 'triggers':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SELECT COUNT(*) ";
$query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
$query .= "WHERE `EVENT_OBJECT_SCHEMA` "
. Util::getCollateForIS() . "='$db' ";
$query .= "AND `EVENT_OBJECT_TABLE` "
. Util::getCollateForIS() . "='$table'";
$retval = (int)$GLOBALS['dbi']->fetchValue($query);
} else {
$db = Util::backquote($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
$retval = (int)$GLOBALS['dbi']->numRows(
$GLOBALS['dbi']->tryQuery($query)
);
}
break;
default:
break;
}
return $retval;
}
/**
* Returns the names of children of type $type present inside this container
* This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase
* and PMA\libraries\navigation\nodes\NodeTable 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->realParent()->real_name;
$table = $this->real_name;
switch ($type) {
case 'columns':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SELECT `COLUMN_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
$query .= "WHERE `TABLE_NAME`='$table' ";
$query .= "AND `TABLE_SCHEMA`='$db' ";
$query .= "ORDER BY `COLUMN_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW COLUMNS FROM $table FROM $db";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Field'];
$count++;
} else {
break;
}
}
}
break;
case 'indexes':
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = "SHOW INDEXES FROM $table FROM $db";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if (in_array($arr['Key_name'], $retval)) {
continue;
}
if ($pos <= 0 && $count < $maxItems) {
$retval[] = $arr['Key_name'];
$count++;
}
$pos--;
}
break;
case 'triggers':
if (!$GLOBALS['cfg']['Server']['DisableIS']) {
$db = $GLOBALS['dbi']->escapeString($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SELECT `TRIGGER_NAME` AS `name` ";
$query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
$query .= "WHERE `EVENT_OBJECT_SCHEMA` "
. Util::getCollateForIS() . "='$db' ";
$query .= "AND `EVENT_OBJECT_TABLE` "
. Util::getCollateForIS() . "='$table' ";
$query .= "ORDER BY `TRIGGER_NAME` ASC ";
$query .= "LIMIT " . intval($pos) . ", $maxItems";
$retval = $GLOBALS['dbi']->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = $GLOBALS['dbi']->escapeString($table);
$query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
$handle = $GLOBALS['dbi']->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
if ($count < $maxItems) {
$retval[] = $arr['Trigger'];
$count++;
} else {
break;
}
}
}
break;
default:
break;
}
return $retval;
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'table';
}
/**
* Add an icon to navigation tree
*
* @param string $page Page name to redirect
*
* @return void
*/
private function _addIcon($page)
{
if (empty($page)) {
return;
}
switch ($page) {
case 'tbl_structure.php':
$this->icon[] = Util::getImage(
'b_props.png',
__('Structure')
);
break;
case 'tbl_select.php':
$this->icon[] = Util::getImage(
'b_search.png',
__('Search')
);
break;
case 'tbl_change.php':
$this->icon[] = Util::getImage(
'b_insrow.png',
__('Insert')
);
break;
case 'tbl_sql.php':
$this->icon[] = Util::getImage('b_sql.png', __('SQL'));
break;
case 'sql.php':
$this->icon[] = Util::getImage(
'b_browse.png',
__('Browse')
);
break;
}
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for table nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeTableContainer extends NodeDatabaseChildContainer
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Tables'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage('b_browse.png', __('Tables'));
$this->links = array(
'text' => 'db_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;tbl_type=table'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;tbl_type=table'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->real_name = 'tables';
$this->classes = 'tableContainer subContainer';
$new_label = _pgettext('Create new table', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_table_add.png', $new_label);
$new->links = array(
'text' => 'tbl_create.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_create.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '],
);
$new->classes = 'new_table italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,42 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a trigger node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeTrigger 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('b_triggers.png');
$this->links = array(
'text' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;item_name=%1$s&amp;edit_item=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;item_name=%1$s&amp;export_item=1'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'trigger';
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for trigger nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeTriggerContainer extends Node
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Triggers'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage('b_triggers.png');
$this->links = array(
'text' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s&amp;token='
. $_SESSION[' PMA_token '],
'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s&amp;token='
. $_SESSION[' PMA_token '],
);
$this->real_name = 'triggers';
$new = NodeFactory::getInstance(
'Node',
_pgettext('Create new trigger', 'New')
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_trigger_add.png', '');
$new->links = array(
'text' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;add_item=1',
'icon' => 'db_triggers.php?server=' . $GLOBALS['server']
. '&amp;db=%3$s&amp;token=' . $_SESSION[' PMA_token ']
. '&amp;add_item=1',
);
$new->classes = 'new_trigger italics';
$this->addChild($new);
}
}

View File

@ -0,0 +1,52 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
/**
* Represents a view node in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeView extends NodeDatabaseChild
{
/**
* 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
*/
public function __construct($name, $type = Node::OBJECT, $is_group = false)
{
parent::__construct($name, $type, $is_group);
$this->icon = PMA\libraries\Util::getImage('b_props.png', __('View'));
$this->links = array(
'text' => 'sql.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s&amp;pos=0'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'tbl_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'view';
}
/**
* Returns the type of the item represented by the node.
*
* @return string type of the item
*/
protected function getItemType()
{
return 'view';
}
}

View File

@ -0,0 +1,55 @@
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Functionality for the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
namespace PMA\libraries\navigation\nodes;
use PMA;
use PMA\libraries\navigation\NodeFactory;
/**
* Represents a container for view nodes in the navigation tree
*
* @package PhpMyAdmin-Navigation
*/
class NodeViewContainer extends NodeDatabaseChildContainer
{
/**
* Initialises the class
*/
public function __construct()
{
parent::__construct(__('Views'), Node::CONTAINER);
$this->icon = PMA\libraries\Util::getImage('b_views.png', __('Views'));
$this->links = array(
'text' => 'db_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;tbl_type=view'
. '&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'db_structure.php?server=' . $GLOBALS['server']
. '&amp;db=%1$s&amp;tbl_type=view'
. '&amp;token=' . $_SESSION[' PMA_token '],
);
$this->classes = 'viewContainer subContainer';
$this->real_name = 'views';
$new_label = _pgettext('Create new view', 'New');
$new = NodeFactory::getInstance(
'Node',
$new_label
);
$new->isNew = true;
$new->icon = PMA\libraries\Util::getImage('b_view_add.png', $new_label);
$new->links = array(
'text' => 'view_create.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '],
'icon' => 'view_create.php?server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;token=' . $_SESSION[' PMA_token '],
);
$new->classes = 'new_view italics';
$this->addChild($new);
}
}