From: jakubvrana Date: Mon, 16 Nov 2009 11:06:07 +0000 (+0000) Subject: Separate foreignKeyOptions X-Git-Tag: v3.0.0~301 X-Git-Url: https://git.joonet.de/?a=commitdiff_plain;h=14ec96a0900672751a23de82bad9530c16d26893;p=adminer.git Separate foreignKeyOptions git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1243 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 19b18186..b7b95060 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -1,7 +1,7 @@ ="); - var $values = array(); + var $values = array(); // protected function name() { return lang('Editor'); @@ -187,14 +187,14 @@ ORDER BY ORDINAL_POSITION"); $i = -1; foreach ($columns as $name => $desc) { $key = $keys[$name]; - $options = $this->editInput($_GET["select"], array("field" => $name), " name='where[$i][val]'", $_GET["where"][$key]["val"]); + $options = $this->foreignKeyOptions($_GET["select"], $name); if ($options) { + echo "
" . h($desc) . ":
\n"; + $i--; unset($columns[$name]); if (isset($key)) { unset($_GET["where"][$key]); } - echo "
" . h($desc) . ": $options
\n"; - $i--; } } $i = 0; @@ -393,32 +393,12 @@ ORDER BY ORDINAL_POSITION"); } function editInput($table, $field, $attrs, $value) { - global $connection; if ($field["type"] == "enum") { return ($field["null"] ? "" : ""); } - $foreignKeys = column_foreign_keys($table); - foreach ((array) $foreignKeys[$field["field"]] as $foreignKey) { - if (count($foreignKey["source"]) == 1) { - $id = idf_escape($foreignKey["target"][0]); - $name = $this->rowDescription($foreignKey["table"]); - if (strlen($name)) { - $return = &$this->values[$foreignKey["table"]]; - if (!isset($return)) { - $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " ORDER BY 2 LIMIT 1001"); - $return = array(); - if ($result->num_rows < 1001) { // optionlist with more than 1000 options would be too big - $return[""] = ""; - while ($row = $result->fetch_row()) { - $return[$row[0]] = $row[1]; - } - } - } - if ($return) { - return "" . optionlist($return, $value, true) . ""; - } - } - } + $options = $this->foreignKeyOptions($table, $field["field"]); + if ($options) { + return "" . optionlist($options, $value, true) . ""; } if ($field["full_type"] == "tinyint(1)") { // bool return '"; @@ -438,7 +418,7 @@ ORDER BY ORDINAL_POSITION"); if (ereg('date|timestamp', $field["type"]) && preg_match('(^' . str_replace('\\$1', '(?P[0-9]*)', preg_replace('~(\\\\\\$([2-6]))~', '(?P[0-9]{1,2})', preg_quote(lang('$1-$3-$5')))) . '(.*))', $value, $match)) { $return = (strlen($match["p1"]) ? $match["p1"] : (strlen($match["p2"]) ? ($match["p2"] < 70 ? 20 : 19) . $match["p2"] : gmdate("Y"))) . "-$match[p3]$match[p4]-$match[p5]$match[p6]" . end($match); } - $return = $connection->quote($value); + $return = $connection->quote($return); if (!ereg('varchar|text', $field["type"]) && $field["full_type"] != "tinyint(1)" && !strlen($value)) { $return = "NULL"; } @@ -492,6 +472,31 @@ ORDER BY ORDINAL_POSITION"); } } + function foreignKeyOptions($table, $column) { // protected + global $connection; + $foreignKeys = column_foreign_keys($table); + foreach ((array) $foreignKeys[$column] as $foreignKey) { + if (count($foreignKey["source"]) == 1) { + $id = idf_escape($foreignKey["target"][0]); + $name = $this->rowDescription($foreignKey["table"]); + if (strlen($name)) { + $return = &$this->values[$foreignKey["table"]]; + if (!isset($return)) { + $result = $connection->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " ORDER BY 2 LIMIT 1001"); + $return = array(); + if ($result->num_rows < 1001) { // optionlist with more than 1000 options would be too big + $return[""] = ""; + while ($row = $result->fetch_row()) { + $return[$row[0]] = $row[1]; + } + } + } + return $return; + } + } + } + } + } $adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);