Files
#jpgraph
#pma
CKEditor_4.6.1
Date
backup
bibelpopup
classes
config
fetch_bibel
fetch_chorbuch
html2pdf-master
html2pdf_v4.03
images
jpgraph
kalender
language
lib
lieder
livesearch
msd
overlib
pma
doc
examples
js
libraries
cache
certs
classes
Charsets
Command
Config
Controllers
Database
Dbal
Display
Engines
Exceptions
Export
Gis
Html
Import
Navigation
Nodes
Node.php
NodeColumn.php
NodeColumnContainer.php
NodeDatabase.php
NodeDatabaseChild.php
NodeDatabaseChildContainer.php
NodeDatabaseContainer.php
NodeEvent.php
NodeEventContainer.php
NodeFunction.php
NodeFunctionContainer.php
NodeIndex.php
NodeIndexContainer.php
NodeProcedure.php
NodeProcedureContainer.php
NodeTable.php
NodeTableContainer.php
NodeTrigger.php
NodeTriggerContainer.php
NodeView.php
NodeViewContainer.php
Navigation.php
NavigationTree.php
NodeFactory.php
Plugins
Properties
Providers
Query
Server
Setup
Table
Twig
Utils
Advisor.php
Bookmark.php
BrowseForeigners.php
Charsets.php
CheckUserPrivileges.php
Config.php
Console.php
Core.php
CreateAddField.php
DatabaseInterface.php
DbTableExists.php
Encoding.php
Error.php
ErrorHandler.php
ErrorReport.php
Export.php
File.php
FileListing.php
Font.php
Footer.php
Git.php
Header.php
Import.php
Index.php
IndexColumn.php
InsertEdit.php
InternalRelations.php
IpAllowDeny.php
Language.php
LanguageManager.php
Linter.php
ListAbstract.php
ListDatabase.php
Logging.php
Menu.php
Message.php
Mime.php
Normalization.php
OpenDocument.php
Operations.php
OutputBuffering.php
ParseAnalyze.php
Partition.php
Pdf.php
Plugins.php
Profiling.php
RecentFavoriteTable.php
Relation.php
RelationCleanup.php
Replication.php
ReplicationGui.php
ReplicationInfo.php
Response.php
Routing.php
Sanitize.php
SavedSearches.php
Scripts.php
Session.php
Sql.php
SqlQueryForm.php
StorageEngine.php
SubPartition.php
SystemDatabase.php
Table.php
TablePartitionDefinition.php
Template.php
Theme.php
ThemeManager.php
Tracker.php
Tracking.php
Transformations.php
TwoFactor.php
Types.php
Url.php
UserPassword.php
UserPreferences.php
Util.php
Version.php
VersionInformation.php
ZipExtension.php
advisory_rules_generic.php
advisory_rules_mysql_before80003.php
common.inc.php
config.default.php
config.values.php
language_stats.inc.php
routes.php
services.php
services_controllers.php
services_loader.php
vendor_config.php
locale
setup
sql
templates
themes
tmp
vendor
CONTRIBUTING.md
ChangeLog
LICENSE
README
RELEASE-DATE-5.1.1
babel.config.json
composer.json
composer.lock
config.inc.php
config.sample.inc.php
favicon.ico
index.php
package.json
print.css
robots.txt
show_config_errors.php
url.php
yarn.lock
templates
templates_c
++ Umstellung Luther 2017.sql
.gitattributes
.htaccess
Version8_bugs.txt
ajax.js_20170928
ansicht.php
ansicht.php_20200212
ansicht.php_20200915
ansicht.php_lut84_20180219
ansicht2.php
ansicht2.php_20200212
ansicht2.php_20200915
ansicht2.php_lut84_20180219
ausgabe.php
bes_gd.php
bibellookup.php_lut84_20180219
bibellookup_1984.php
bibellookup_2017.php
bibellookup_2017.php_20200212
changelog.php
config.inc.php
copy.js
faq_text.php
faq_text_ber.php
favicon.ico
fetch_data.php
ftp_ansicht.php
ftp_ansicht.php_20181214
func_agent.php
func_ansicht.php
func_ansicht.php_20200212
func_ansicht.php_20200915
func_ansicht.php_lut84_20180219
func_genUser.php
func_highlight.php
func_htmlclean.php
func_make_knk.php
func_make_knk_fa.php
func_make_knk_fa.php_lut84_20180219
func_make_reference_fa.php
func_make_reference_fa.php_lut84_20180219
func_rollenrechte.php
func_rollenrechte_20220202.php
func_write_lue_kat.php
further_publication.php
getSubCat.php
graph.php
graph_einzel.php
graph_hauptframe.php
graph_user.php
graph_user_hauptframe.php
hauptframe.php
hello.cgi
hello.pl
hilfe.php
historie.php
index.php
index2.php
indexframe.php
info.php
job_mail_delete_neue_user.php
job_mail_inaktiv.php
job_user_delete_neue_user.php
job_user_inaktiv.php
jquery.min.js
kat_cont.php
kat_cont.php_20201230
kat_cont.php_20221013
kat_cont_fa.php
kat_main.php
kat_main.php_lut84_20180219
kat_main_fa.php
kat_main_fa.php_lut84_20180219
katechismus.php
katechismus_fa.php
lesung.php
lieder.php
lieder.zip
livesearch.php
livestat.js
livestat.php
livestat2.php
login_log.php
logininfo.php
logout_admin.php
lue_ansicht.php
lue_bearbeiten.php
lue_erfassen.php
lue_inhalt.php
lue_inhalt.php_20200915
lue_inhalt.php_lut84_20180219
lue_notizen.php
lue_suche.php
lue_wahl.php
mail.php
make_ical.php
menuframe.php
nachsenden.php
notizen.php
outlook.php
outlook.php_20200212
outlook_ics.php
outlook_vcs.php
passwort_switch.php
pdf_gen.php
pdf_gen.php_20200915
pdf_gen.php_lut84_20180219
preview.php
profil.php
rollen.php
search_note.php
stichworte.php
suche.php
suche.php_20170928
suche_change.php
suche_simp.php
systemmail.php
test.php
test2.php
testmail.php
testmail2.php
topframe.php
upload.php
user_anlegen.php
user_bearbeiten.php
useronline.php
verweise.php
wort_bearbeiten.php
wort_bearbeiten.php_20170928
wort_erfassen.php
wort_erfassen.php_20170928
wort_exegese.php
wort_wahl.php
Leitgedanken/pma/libraries/classes/Navigation/Nodes/NodeTable.php
2022-11-21 09:47:28 +01:00

327 lines
12 KiB
PHP

<?php
/**
* Functionality for the navigation tree
*/
declare(strict_types=1);
namespace PhpMyAdmin\Navigation\Nodes;
use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Url;
use PhpMyAdmin\Util;
use function in_array;
use function intval;
use function strpos;
/**
* Represents a columns node in the navigation tree
*/
class NodeTable extends NodeDatabaseChild
{
/** @var array IMG tags, used when rendering the node */
public $icon;
/**
* 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 $isGroup Whether this object has been created
* while grouping nodes
*/
public function __construct($name, $type = Node::OBJECT, $isGroup = false)
{
parent::__construct($name, $type, $isGroup);
$this->icon = [];
$this->addIcon(
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'],
'table'
)
);
$this->addIcon(
Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'],
'table'
)
);
$title = (string) Util::getTitleForTarget(
$GLOBALS['cfg']['DefaultTabTable']
);
$this->title = $title;
$scriptName = Util::getScriptNameForOption(
$GLOBALS['cfg']['DefaultTabTable'],
'table'
);
$firstIconLink = Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable'],
'table'
);
$secondIconLink = Util::getScriptNameForOption(
$GLOBALS['cfg']['NavigationTreeDefaultTabTable2'],
'table'
);
$this->links = [
'text' => $scriptName . (strpos($scriptName, '?') === false ? '?' : '&')
. 'server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s'
. '&amp;pos=0',
'icon' => [
$firstIconLink . (strpos($firstIconLink, '?') === false ? '?' : '&')
. 'server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s',
$secondIconLink . (strpos($secondIconLink, '?') === false ? '?' : '&')
. 'server=' . $GLOBALS['server']
. '&amp;db=%2$s&amp;table=%1$s',
],
'title' => $this->title,
];
$this->classes = 'table';
}
/**
* Returns the number of children of type $type present inside this container
* This method is overridden by the PhpMyAdmin\Navigation\Nodes\NodeDatabase
* and PhpMyAdmin\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 = '')
{
global $dbi;
$retval = 0;
$db = $this->realParent()->realName;
$table = $this->realName;
switch ($type) {
case 'columns':
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$db = $dbi->escapeString($db);
$table = $dbi->escapeString($table);
$query = 'SELECT COUNT(*) ';
$query .= 'FROM `INFORMATION_SCHEMA`.`COLUMNS` ';
$query .= "WHERE `TABLE_NAME`='" . $table . "' ";
$query .= "AND `TABLE_SCHEMA`='" . $db . "'";
$retval = (int) $dbi->fetchValue($query);
} else {
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = 'SHOW COLUMNS FROM ' . $table . ' FROM ' . $db . '';
$retval = (int) $dbi->numRows(
$dbi->tryQuery($query)
);
}
break;
case 'indexes':
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = 'SHOW INDEXES FROM ' . $table . ' FROM ' . $db;
$retval = (int) $dbi->numRows(
$dbi->tryQuery($query)
);
break;
case 'triggers':
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$db = $dbi->escapeString($db);
$table = $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) $dbi->fetchValue($query);
} else {
$db = Util::backquote($db);
$table = $dbi->escapeString($table);
$query = 'SHOW TRIGGERS FROM ' . $db . " WHERE `Table` = '" . $table . "'";
$retval = (int) $dbi->numRows(
$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 PhpMyAdmin\Navigation\Nodes\NodeDatabase
* and PhpMyAdmin\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 = '')
{
global $dbi;
$maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
$retval = [];
$db = $this->realParent()->realName;
$table = $this->realName;
switch ($type) {
case 'columns':
if (! $GLOBALS['cfg']['Server']['DisableIS']) {
$db = $dbi->escapeString($db);
$table = $dbi->escapeString($table);
$query = 'SELECT `COLUMN_NAME` AS `name` ';
$query .= ',`COLUMN_KEY` AS `key` ';
$query .= ',`DATA_TYPE` AS `type` ';
$query .= ',`COLUMN_DEFAULT` AS `default` ';
$query .= ",IF (`IS_NULLABLE` = 'NO', '', 'nullable') AS `nullable` ";
$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 = $dbi->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = 'SHOW COLUMNS FROM ' . $table . ' FROM ' . $db;
$handle = $dbi->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($dbi->dataSeek($handle, $pos)) {
while ($arr = $dbi->fetchArray($handle)) {
if ($count >= $maxItems) {
break;
}
$retval[] = [
'name' => $arr['Field'],
'key' => $arr['Key'],
'type' => Util::extractColumnSpec($arr['Type'])['type'],
'default' => $arr['Default'],
'nullable' => ($arr['Null'] === 'NO' ? '' : 'nullable'),
];
$count++;
}
}
break;
case 'indexes':
$db = Util::backquote($db);
$table = Util::backquote($table);
$query = 'SHOW INDEXES FROM ' . $table . ' FROM ' . $db;
$handle = $dbi->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
while ($arr = $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 = $dbi->escapeString($db);
$table = $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 = $dbi->fetchResult($query);
break;
}
$db = Util::backquote($db);
$table = $dbi->escapeString($table);
$query = 'SHOW TRIGGERS FROM ' . $db . " WHERE `Table` = '" . $table . "'";
$handle = $dbi->tryQuery($query);
if ($handle === false) {
break;
}
$count = 0;
if ($dbi->dataSeek($handle, $pos)) {
while ($arr = $dbi->fetchArray($handle)) {
if ($count >= $maxItems) {
break;
}
$retval[] = $arr['Trigger'];
$count++;
}
}
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 Url::getFromRoute('/table/structure'):
$this->icon[] = Generator::getImage('b_props', __('Structure'));
break;
case Url::getFromRoute('/table/search'):
$this->icon[] = Generator::getImage('b_search', __('Search'));
break;
case Url::getFromRoute('/table/change'):
$this->icon[] = Generator::getImage('b_insrow', __('Insert'));
break;
case Url::getFromRoute('/table/sql'):
$this->icon[] = Generator::getImage('b_sql', __('SQL'));
break;
case Url::getFromRoute('/sql'):
$this->icon[] = Generator::getImage('b_browse', __('Browse'));
break;
}
}
}