diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b0a69ec..b4a5cf69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Adminer dev +- Tables overview: allow sorting (bug #1231) - Select: Disable Ctrl+click inline edit without UPDATE privilege - Select: Display NULL in column title - Export: Remember unchecked objects (regression from 5.0.6) diff --git a/adminer/db.inc.php b/adminer/db.inc.php index 2cd351ac..c35911cb 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -56,8 +56,9 @@ page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema' if (adminer()->homepage()) { if ($_GET["ns"] !== "") { + $order = $_GET["order"]; echo "

" . lang('Tables and views') . "

\n"; - $tables_list = tables_list(); + $tables_list = ($order ? table_status() : tables_list()); if (!$tables_list) { echo "

" . lang('No tables.') . "\n"; } else { @@ -79,7 +80,7 @@ if (adminer()->homepage()) { echo script("mixin(qsl('table'), {onclick: tableClick, ondblclick: partialArg(tableClick, true)});"); echo ''; echo '' . script("qs('#check-all').onclick = partial(formCheck, /^(tables|views)\[/);", ""); - echo '' . lang('Table'); + echo '' . lang('Table') . ''; $columns = array("Engine" => array(lang('Engine') . doc_link(array('sql' => 'storage-engines.html')))); if (collations()) { $columns["Collation"] = array(lang('Collation') . doc_link(array('sql' => 'charset-charsets.html', 'mariadb' => 'supported-character-sets-and-collations/'))); @@ -98,27 +99,40 @@ if (adminer()->homepage()) { if (support("comment")) { $columns["Comment"] = array(lang('Comment') . doc_link(array('sql' => 'show-table-status.html', 'pgsql' => 'functions-info.html#FUNCTIONS-INFO-COMMENT-TABLE'))); } - foreach ($columns as $column) { - echo "$column[0]"; + foreach ($columns as $key => $column) { + echo "$column[0]"; } echo "\n"; + if ($order) { + uasort($tables_list, function ($a, $b) use ($order) { + $return = ($a[$order] < $b[$order] ? -1 : ($a[$order] > $b[$order] ? 1 : 0)); // <=> available since PHP 7.1 + return (in_array($order, array('Engine', 'Collation', 'Comment')) ? $return : -$return); + }); + } + $tables = 0; - foreach ($tables_list as $name => $type) { - $view = ($type !== null && !preg_match('~table|sequence~i', $type)); + foreach ($tables_list as $name => $status) { + $view = ($order ? is_view($status) : $status !== null && !preg_match('~table|sequence~i', $status)); + $status = ($order ? $status : array('Engine' => $status)); $id = h("Table-" . $name); echo '' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array("$name", $tables_views, true), "", "", "", $id); // "$name" to check numeric table names echo '' . (support("table") || support("indexes") ? "" . h($name) . '' : h($name)); - if ($view && !preg_match('~materialized~i', $type)) { + if ($view && !preg_match('~materialized~i', $status['Engine'])) { $title = lang('View'); - echo '' . (support("view") ? "$title" : $title); + echo '' . (support("view") ? "$title" : $title); echo '?'; + echo '' . h($status['Comment']); } else { foreach ($columns as $key => $column) { $id = " id='$key-" . h($name) . "'"; + $val = idx($status, $key, '?'); echo ($column[1] - ? "?" - : "" + ? "" . (is_numeric($val) + ? ($val < 0 ? '?' : ($key == "Rows" && $val && $status["Engine"] == (JUSH == "pgsql" ? "table" : "InnoDB") ? '~ ' : '') . format_number($val)) + : $val + ) . "" + : "" . h($val) ); } $tables++; @@ -128,14 +142,14 @@ if (adminer()->homepage()) { echo "" . lang('%d in total', count($tables_list)); echo "" . h(JUSH == "sql" ? get_val("SELECT @@default_storage_engine") : ""); - echo "" . h(db_collation(DB, collations())); + echo (collations() ? "" . h(db_collation(DB, collations())) : ''); foreach (array("Data_length", "Index_length", "Data_free") as $key) { echo ($columns[$key] ? "" : ""); } echo "\n"; echo "\n"; - echo script("ajaxSetHtml('" . js_escape(ME) . "script=db');"); + echo ($order ? '' : script("ajaxSetHtml('" . js_escape(ME) . "script=db');")); echo "\n"; if (!information_schema(DB)) { $vacuum = " " . on_help("'VACUUM'");