Fixed warnings on table structure page and table data page

This commit is contained in:
Lionel Laffineur 2023-12-03 23:04:42 +01:00
parent 4deb8a4085
commit 5f7daff1e0
6 changed files with 132 additions and 106 deletions

View file

@ -544,6 +544,11 @@ if (!defined("DRIVER")) {
$return = array(); $return = array();
foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) { foreach (get_rows("SHOW FULL COLUMNS FROM " . table($table)) as $row) {
preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["Type"], $match); preg_match('~^([^( ]+)(?:\((.+)\))?( unsigned)?( zerofill)?$~', $row["Type"], $match);
for ($i = 0; $i < 5; $i++) {
if (isset($match[$i]) === false) {
$match[$i] = null;
}
}
$return[$row["Field"]] = array( $return[$row["Field"]] = array(
"field" => $row["Field"], "field" => $row["Field"],
"full_type" => $row["Type"], "full_type" => $row["Type"],

View file

@ -398,21 +398,23 @@ class Adminer {
} }
} }
$change_next = "this.parentNode.firstChild.onchange();"; $change_next = "this.parentNode.firstChild.onchange();";
foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) { if (isset($_GET["where"])) {
if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) { foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) {
echo "<div>" . select_input( if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) {
" name='where[$i][col]'", echo "<div>" . select_input(
$columns, " name='where[$i][col]'",
$val["col"], $columns,
($val ? "selectFieldChange" : "selectAddRow"), $val["col"],
"(" . lang('anywhere') . ")" ($val ? "selectFieldChange" : "selectAddRow"),
); "(" . lang('anywhere') . ")"
echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next); );
echo "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "'>"; echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next);
echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", ""); echo "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "'>";
echo "<input type='image' src='../adminer/static/cross.gif' class='jsonly icon' title='", h(lang('Remove')), "' alt='x'>"; echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", "");
echo script('qsl(".icon").onclick = selectRemoveRow;', ""); echo "<input type='image' src='../adminer/static/cross.gif' class='jsonly icon' title='", h(lang('Remove')), "' alt='x'>";
echo "</div>\n"; echo script('qsl(".icon").onclick = selectRemoveRow;', "");
echo "</div>\n";
}
} }
} }
echo "</div></fieldset>\n"; echo "</div></fieldset>\n";
@ -427,14 +429,16 @@ class Adminer {
function selectOrderPrint($order, $columns, $indexes) { function selectOrderPrint($order, $columns, $indexes) {
print_fieldset("sort", lang('Sort'), $order); print_fieldset("sort", lang('Sort'), $order);
$i = 0; $i = 0;
foreach ((array) $_GET["order"] as $key => $val) { if (isset($_GET["order"])) {
if ($val != "") { foreach ((array) $_GET["order"] as $key => $val) {
echo "<div>" . select_input(" name='order[$i]'", $columns, $val, "selectFieldChange"); if ($val != "") {
echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')); echo "<div>" . select_input(" name='order[$i]'", $columns, $val, "selectFieldChange");
echo " <input type='image' src='../adminer/static/cross.gif' class='jsonly icon' title='", h(lang('Remove')), "' alt='x'>"; echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending'));
echo script('qsl(".icon").onclick = selectRemoveRow;', ""); echo " <input type='image' src='../adminer/static/cross.gif' class='jsonly icon' title='", h(lang('Remove')), "' alt='x'>";
echo "</div>\n"; echo script('qsl(".icon").onclick = selectRemoveRow;', "");
$i++; echo "</div>\n";
$i++;
}
} }
} }
echo "<div>" . select_input(" name='order[$i]'", $columns, "", "selectAddRow"); echo "<div>" . select_input(" name='order[$i]'", $columns, "", "selectAddRow");
@ -526,11 +530,13 @@ class Adminer {
global $functions, $grouping; global $functions, $grouping;
$select = array(); // select expressions, empty for * $select = array(); // select expressions, empty for *
$group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
foreach ((array) $_GET["columns"] as $key => $val) { if (isset($_GET["columns"])) {
if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) { foreach ((array) $_GET["columns"] as $key => $val) {
$select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*")); if ($val["fun"] == "count" || ($val["col"] != "" && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
if (!in_array($val["fun"], $grouping)) { $select[$key] = apply_sql_function($val["fun"], ($val["col"] != "" ? idf_escape($val["col"]) : "*"));
$group[] = $select[$key]; if (!in_array($val["fun"], $grouping)) {
$group[] = $select[$key];
}
} }
} }
} }
@ -550,39 +556,41 @@ class Adminer {
$return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")"; $return[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . q($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
} }
} }
foreach ((array) $_GET["where"] as $key => $val) { if (isset($_GET["where"])) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) { foreach ((array) $_GET["where"] as $key => $val) {
$prefix = ""; if ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators)) {
$cond = " $val[op]"; $prefix = "";
if (preg_match('~IN$~', $val["op"])) { $cond = " $val[op]";
$in = process_length($val["val"]); if (preg_match('~IN$~', $val["op"])) {
$cond .= " " . ($in != "" ? $in : "(NULL)"); $in = process_length($val["val"]);
} elseif ($val["op"] == "SQL") { $cond .= " " . ($in != "" ? $in : "(NULL)");
$cond = " $val[val]"; // SQL injection } elseif ($val["op"] == "SQL") {
} elseif ($val["op"] == "LIKE %%") { $cond = " $val[val]"; // SQL injection
$cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); } elseif ($val["op"] == "LIKE %%") {
} elseif ($val["op"] == "ILIKE %%") { $cond = " LIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
$cond = " ILIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%"); } elseif ($val["op"] == "ILIKE %%") {
} elseif ($val["op"] == "FIND_IN_SET") { $cond = " ILIKE " . $this->processInput($fields[$val["col"]], "%$val[val]%");
$prefix = "$val[op](" . q($val["val"]) . ", "; } elseif ($val["op"] == "FIND_IN_SET") {
$cond = ")"; $prefix = "$val[op](" . q($val["val"]) . ", ";
} elseif (!preg_match('~NULL$~', $val["op"])) { $cond = ")";
$cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]); } elseif (!preg_match('~NULL$~', $val["op"])) {
} $cond .= " " . $this->processInput($fields[$val["col"]], $val["val"]);
if ($val["col"] != "") { }
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond; if ($val["col"] != "") {
} else { $return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond;
// find anywhere } else {
$cols = array(); // find anywhere
foreach ($fields as $name => $field) { $cols = array();
if ((preg_match('~^[-\d.' . (preg_match('~IN$~', $val["op"]) ? ',' : '') . ']+$~', $val["val"]) || !preg_match('~' . number_type() . '|bit~', $field["type"])) foreach ($fields as $name => $field) {
&& (!preg_match("~[\x80-\xFF]~", $val["val"]) || preg_match('~char|text|enum|set~', $field["type"])) if ((preg_match('~^[-\d.' . (preg_match('~IN$~', $val["op"]) ? ',' : '') . ']+$~', $val["val"]) || !preg_match('~' . number_type() . '|bit~', $field["type"]))
&& (!preg_match('~date|timestamp~', $field["type"]) || preg_match('~^\d+-\d+-\d+~', $val["val"])) && (!preg_match("~[\x80-\xFF]~", $val["val"]) || preg_match('~char|text|enum|set~', $field["type"]))
) { && (!preg_match('~date|timestamp~', $field["type"]) || preg_match('~^\d+-\d+-\d+~', $val["val"]))
$cols[] = $prefix . $driver->convertSearch(idf_escape($name), $val, $field) . $cond; ) {
} $cols[] = $prefix . $driver->convertSearch(idf_escape($name), $val, $field) . $cond;
}
}
$return[] = ($cols ? "(" . implode(" OR ", $cols) . ")" : "1 = 0");
} }
$return[] = ($cols ? "(" . implode(" OR ", $cols) . ")" : "1 = 0");
} }
} }
} }
@ -596,11 +604,13 @@ class Adminer {
*/ */
function selectOrderProcess($fields, $indexes) { function selectOrderProcess($fields, $indexes) {
$return = array(); $return = array();
foreach ((array) $_GET["order"] as $key => $val) { if (isset($_GET["order"])) {
if ($val != "") { foreach ((array) $_GET["order"] as $key => $val) {
$return[] = (preg_match('~^((COUNT\(DISTINCT |[A-Z0-9_]+\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\)|COUNT\(\*\))$~', $val) ? $val : idf_escape($val)) //! MS SQL uses [] if ($val != "") {
. (isset($_GET["desc"][$key]) ? " DESC" : "") $return[] = (preg_match('~^((COUNT\(DISTINCT |[A-Z0-9_]+\()(`(?:[^`]|``)+`|"(?:[^"]|"")+")\)|COUNT\(\*\))$~', $val) ? $val : idf_escape($val)) //! MS SQL uses []
; . (isset($_GET["desc"][$key]) ? " DESC" : "")
;
}
} }
} }
return $return; return $return;

View file

@ -80,7 +80,7 @@ var thousandsSeparator = '<?php echo js_escape(lang(',')); ?>';
echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; '; echo '<a href="' . h($link . "&db=" . urlencode(DB) . (support("scheme") ? "&ns=" : "")) . '">' . h(DB) . '</a> &raquo; ';
} }
if (is_array($breadcrumb)) { if (is_array($breadcrumb)) {
if ($_GET["ns"] != "") { if (isset($_GET["ns"]) && $_GET["ns"] != "") {
echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; '; echo '<a href="' . h(substr(ME, 0, -1)) . '">' . h($_GET["ns"]) . '</a> &raquo; ';
} }
foreach ($breadcrumb as $key => $val) { foreach ($breadcrumb as $key => $val) {

View file

@ -47,7 +47,7 @@ function get_driver($id) {
$query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page); $query = $adminer->selectQueryBuild($select, $where, $group, $order, $limit, $page);
if (!$query) { if (!$query) {
$query = "SELECT" . limit( $query = "SELECT" . limit(
($_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table), (isset($_GET["page"]) && $_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . implode(", ", $select) . "\nFROM " . table($table),
($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""), ($where ? "\nWHERE " . implode(" AND ", $where) : "") . ($group && $is_group ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : ""),
($limit != "" ? +$limit : null), ($limit != "" ? +$limit : null),
($page ? $limit * $page : 0), ($page ? $limit * $page : 0),

View file

@ -14,7 +14,7 @@ include "./include/tmpfile.inc.php";
$enum_length = "'(?:''|[^'\\\\]|\\\\.)*'"; $enum_length = "'(?:''|[^'\\\\]|\\\\.)*'";
$inout = "IN|OUT|INOUT"; $inout = "IN|OUT|INOUT";
if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) { if (isset($_GET["select"]) && ((isset($_POST["edit"]) && $_POST["edit"]) || (isset($_POST["clone"]) && $_POST["clone"])) && (isset($_POST["save"]) || !$_POST["save"])) {
$_GET["edit"] = $_GET["select"]; $_GET["edit"] = $_GET["select"];
} }
if (isset($_GET["callf"])) { if (isset($_GET["callf"])) {

View file

@ -4,8 +4,12 @@ $table_status = table_status1($TABLE);
$indexes = indexes($TABLE); $indexes = indexes($TABLE);
$fields = fields($TABLE); $fields = fields($TABLE);
$foreign_keys = column_foreign_keys($TABLE); $foreign_keys = column_foreign_keys($TABLE);
$oid = $table_status["Oid"]; $oid = (isset($table_status["Oid"]) ? $table_status["Oid"] : null);
parse_str($_COOKIE["adminer_import"], $adminer_import); if (isset($_COOKIE["adminer_import"])) {
parse_str($_COOKIE["adminer_import"], $adminer_import);
} else {
$adminer_import = [];
}
$rights = array(); // privilege => 0 $rights = array(); // privilege => 0
$columns = array(); // selectable columns $columns = array(); // selectable columns
@ -22,12 +26,12 @@ foreach ($fields as $key => $field) {
} }
list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes); list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
$is_group = count($group) < count($select) || strstr($select[0], "DISTINCT"); $is_group = count($group) < count($select) || (isset($select[0]) && strstr($select[0], "DISTINCT"));
$where = $adminer->selectSearchProcess($fields, $indexes); $where = $adminer->selectSearchProcess($fields, $indexes);
$order = $adminer->selectOrderProcess($fields, $indexes); $order = $adminer->selectOrderProcess($fields, $indexes);
$limit = $adminer->selectLimitProcess(); $limit = $adminer->selectLimitProcess();
if ($_GET["val"] && is_ajax()) { if (isset($_GET["val"]) && $_GET["val"] && is_ajax()) {
header("Content-Type: text/plain; charset=utf-8"); header("Content-Type: text/plain; charset=utf-8");
foreach ($_GET["val"] as $unique_idf => $row) { foreach ($_GET["val"] as $unique_idf => $row) {
$as = convert_field($fields[key($row)]); $as = convert_field($fields[key($row)]);
@ -225,11 +229,13 @@ if (is_ajax()) {
$set = null; $set = null;
if (isset($rights["insert"]) || !support("table")) { if (isset($rights["insert"]) || !support("table")) {
$set = ""; $set = "";
foreach ((array) $_GET["where"] as $val) { if (isset($_GET["where"])) {
if ($foreign_keys[$val["col"]] && count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "=" foreach ((array) $_GET["where"] as $val) {
|| (!$val["op"] && !preg_match('~[_%]~', $val["val"])) // LIKE in Editor if ($foreign_keys[$val["col"]] && count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
)) { || (!$val["op"] && !preg_match('~[_%]~', $val["val"])) // LIKE in Editor
$set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]); )) {
$set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
}
} }
} }
} }
@ -253,7 +259,7 @@ if (!$columns && support("table")) {
$adminer->selectActionPrint($indexes); $adminer->selectActionPrint($indexes);
echo "</form>\n"; echo "</form>\n";
$page = $_GET["page"]; $page = (isset($_GET["page"]) ? $_GET["page"] : null);
if ($page == "last") { if ($page == "last") {
$found_rows = $connection->result(count_rows($TABLE, $where, $is_group, $group)); $found_rows = $connection->result(count_rows($TABLE, $where, $is_group, $group));
$page = floor(max(0, $found_rows - 1) / $limit); $page = floor(max(0, $found_rows - 1) / $limit);
@ -301,7 +307,7 @@ if (!$columns && support("table")) {
} }
// use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest) // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
if ($_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql") { if (isset($_GET["page"]) && $_GET["page"] != "last" && $limit != "" && $group && $is_group && $jush == "sql") {
$found_rows = $connection->result(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode $found_rows = $connection->result(" SELECT FOUND_ROWS()"); // space to allow mysql.trace_mode
} }
@ -316,7 +322,7 @@ if (!$columns && support("table")) {
echo "<thead><tr>" . (!$group && $select echo "<thead><tr>" . (!$group && $select
? "" ? ""
: "<td><input type='checkbox' id='all-page' class='jsonly'>" . script("qs('#all-page').onclick = partial(formCheck, /check/);", "") : "<td><input type='checkbox' id='all-page' class='jsonly'>" . script("qs('#all-page').onclick = partial(formCheck, /check/);", "")
. " <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "' title='" . lang('Modify') . "' class='edit-all'>" . lang('Modify') . "</a>"); . " <a href='" . h(isset($_GET["modify"]) && $_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "' title='" . lang('Modify') . "' class='edit-all'>" . lang('Modify') . "</a>");
$names = array(); $names = array();
$functions = array(); $functions = array();
reset($select); reset($select);
@ -333,7 +339,7 @@ if (!$columns && support("table")) {
$href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key); $href = remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key);
$desc = "&desc%5B0%5D=1"; $desc = "&desc%5B0%5D=1";
echo "<th id='th[" . h(bracket_escape($key)) . "]'>" . script("mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});", ""); echo "<th id='th[" . h(bracket_escape($key)) . "]'>" . script("mixin(qsl('th'), {onmouseover: partial(columnMouse), onmouseout: partial(columnMouse, ' hidden')});", "");
echo '<a href="' . h($href . ($order[0] == $column || $order[0] == $key || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*) echo '<a href="' . h($href . ((isset($order[0]) && $order[0] == $column) || (isset($order[0]) && $order[0] == $key) || (!$order && $is_group && $group[0] == $column) ? $desc : '')) . '">'; // $order[0] == $key - COUNT(*)
echo apply_sql_function($val["fun"] ?? null, $name) . "</a>"; //! columns looking like functions echo apply_sql_function($val["fun"] ?? null, $name) . "</a>"; //! columns looking like functions
echo "<span class='column hidden'>"; echo "<span class='column hidden'>";
echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>"; echo "<a href='" . h($href . $desc) . "' title='" . lang('descending') . "' class='text'> ↓</a>";
@ -349,7 +355,7 @@ if (!$columns && support("table")) {
} }
$lengths = array(); $lengths = array();
if ($_GET["modify"]) { if (isset($_GET["modify"]) && $_GET["modify"]) {
foreach ($rows as $row) { foreach ($rows as $row) {
foreach ($row as $key => $val) { foreach ($row as $key => $val) {
$lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val)))); $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
@ -386,7 +392,7 @@ if (!$columns && support("table")) {
$unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val === false ? "f" : $val) : "null%5B%5D=" . urlencode($key)); $unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val === false ? "f" : $val) : "null%5B%5D=" . urlencode($key));
} }
echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>"
. checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"])) . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) (isset($_POST["check"]) ? $_POST["check"] : null)))
. ($is_group || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "' class='edit' title='" . lang('edit') . "'>" . lang('edit') . "</a>") . ($is_group || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "' class='edit' title='" . lang('edit') . "'>" . lang('edit') . "</a>")
); );
@ -403,18 +409,20 @@ if (!$columns && support("table")) {
$link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf; $link = ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf;
} }
if (!$link && $val !== null) { // link related items if (!$link && $val !== null) { // link related items
foreach ((array) $foreign_keys[$key] as $foreign_key) { if (isset($foreign_keys[$key])) {
if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) { foreach ((array) $foreign_keys[$key] as $foreign_key) {
$link = ""; if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
foreach ($foreign_key["source"] as $i => $source) { $link = "";
$link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]); foreach ($foreign_key["source"] as $i => $source) {
} $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
$link = ($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link; // InnoDB supports non-UNIQUE keys }
if ($foreign_key["ns"]) { $link = ($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link; // InnoDB supports non-UNIQUE keys
$link = preg_replace('~([?&]ns=)[^&]+~', '\1' . urlencode($foreign_key["ns"]), $link); if ($foreign_key["ns"]) {
} $link = preg_replace('~([?&]ns=)[^&]+~', '\1' . urlencode($foreign_key["ns"]), $link);
if (count($foreign_key["source"]) == 1) { }
break; if (count($foreign_key["source"]) == 1) {
break;
}
} }
} }
} }
@ -441,7 +449,7 @@ if (!$columns && support("table")) {
$editable = !is_array($row[$key]) && is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key]; $editable = !is_array($row[$key]) && is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
$text = preg_match('~text|lob~', $field["type"] ?? null); $text = preg_match('~text|lob~', $field["type"] ?? null);
echo "<td id='$id'"; echo "<td id='$id'";
if (($_GET["modify"] && $editable) || $value !== null) { if ((isset($_GET["modify"]) && $_GET["modify"] && $editable) || $value !== null) {
$h_value = h($value !== null ? $value : $row[$key]); $h_value = h($value !== null ? $value : $row[$key]);
echo ">" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>"); echo ">" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>");
} else { } else {
@ -471,7 +479,8 @@ if (!$columns && support("table")) {
if (!is_ajax()) { if (!is_ajax()) {
if ($rows || $page) { if ($rows || $page) {
$exact_count = true; $exact_count = true;
if ($_GET["page"] != "last") { $found_rows = null;
if (isset($_GET["page"]) && $_GET["page"] != "last") {
if ($limit == "" || (count($rows) < $limit && ($rows || !$page))) { if ($limit == "" || (count($rows) < $limit && ($rows || !$page))) {
$found_rows = ($page ? $page * $limit : 0) + count($rows); $found_rows = ($page ? $page * $limit : 0) + count($rows);
} elseif ($jush != "sql" || !$is_group) { } elseif ($jush != "sql" || !$is_group) {
@ -536,8 +545,8 @@ if (!$columns && support("table")) {
if ($adminer->selectCommandPrint()) { if ($adminer->selectCommandPrint()) {
?> ?>
<fieldset<?php echo ($_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div> <fieldset<?php echo (isset($_GET["modify"]) && $_GET["modify"] ? '' : ' class="jsonly"'); ?>><legend><?php echo lang('Modify'); ?></legend><div>
<input type="submit" value="<?php echo lang('Save'); ?>"<?php echo ($_GET["modify"] ? '' : ' title="' . lang('Ctrl+click on a value to modify it.') . '"'); ?>> <input type="submit" value="<?php echo lang('Save'); ?>"<?php echo (isset($_GET["modify"]) && $_GET["modify"] ? '' : ' title="' . lang('Ctrl+click on a value to modify it.') . '"'); ?>>
</div></fieldset> </div></fieldset>
<fieldset><legend><?php echo lang('Selected'); ?> <span id="selected"></span></legend><div> <fieldset><legend><?php echo lang('Selected'); ?> <span id="selected"></span></legend><div>
<input type="submit" name="edit" value="<?php echo lang('Edit'); ?>"> <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
@ -548,17 +557,19 @@ if (!$columns && support("table")) {
} }
$format = $adminer->dumpFormat(); $format = $adminer->dumpFormat();
foreach ((array) $_GET["columns"] as $column) { if (isset($_GET["columns"])) {
if ($column["fun"]) { foreach ((array) $_GET["columns"] as $column) {
unset($format['sql']); if ($column["fun"]) {
break; unset($format['sql']);
break;
}
} }
} }
if ($format) { if ($format) {
print_fieldset("export", lang('Export') . " <span id='selected2'></span>"); print_fieldset("export", lang('Export') . " <span id='selected2'></span>");
$output = $adminer->dumpOutput(); $output = $adminer->dumpOutput();
echo ($output ? html_select("output", $output, $adminer_import["output"]) . " " : ""); echo ($output ? html_select("output", $output, (isset($adminer_import["output"]) ? $adminer_import["output"] : null)) . " " : "");
echo html_select("format", $format, $adminer_import["format"]); echo html_select("format", $format, (isset($adminer_import["format"]) ? $adminer_import["format"] : null));
echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n"; echo " <input type='submit' name='export' value='" . lang('Export') . "'>\n";
echo "</div></fieldset>\n"; echo "</div></fieldset>\n";
} }
@ -574,7 +585,7 @@ if (!$columns && support("table")) {
echo script("qsl('a').onclick = partial(toggle, 'import');", ""); echo script("qsl('a').onclick = partial(toggle, 'import');", "");
echo "<span id='import' class='hidden'>: "; echo "<span id='import' class='hidden'>: ";
echo "<input type='file' name='csv_file'> "; echo "<input type='file' name='csv_file'> ";
echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_import["format"], 1); // 1 - select echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), (isset($adminer_import["format"]) ? $adminer_import["format"] : null), 1); // 1 - select
echo " <input type='submit' name='import' value='" . lang('Import') . "'>"; echo " <input type='submit' name='import' value='" . lang('Import') . "'>";
echo "</span>"; echo "</span>";
echo "</div>"; echo "</div>";