Edit foreign plugin
This commit is contained in:
parent
f8ae1d6360
commit
08e70e6309
|
@ -20,6 +20,7 @@ function adminer_object() {
|
||||||
new AdminerForeignSystem,
|
new AdminerForeignSystem,
|
||||||
new AdminerEnumOption,
|
new AdminerEnumOption,
|
||||||
new AdminerTablesFilter,
|
new AdminerTablesFilter,
|
||||||
|
new AdminerEditForeign,
|
||||||
);
|
);
|
||||||
|
|
||||||
/* It is possible to combine customization and plugins:
|
/* It is possible to combine customization and plugins:
|
||||||
|
|
|
@ -575,14 +575,14 @@ ORDER BY ORDINAL_POSITION", null, "") as $row) { //! requires MySQL 5
|
||||||
|
|
||||||
function _foreignKeyOptions($table, $column, $value = null) {
|
function _foreignKeyOptions($table, $column, $value = null) {
|
||||||
global $connection;
|
global $connection;
|
||||||
if (list($table, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
|
if (list($target, $id, $name) = $this->_foreignColumn(column_foreign_keys($table), $column)) {
|
||||||
$return = &$this->_values[$table];
|
$return = &$this->_values[$target];
|
||||||
if (!isset($return)) {
|
if (!isset($return)) {
|
||||||
$table_status = table_status($table);
|
$table_status = table_status($target);
|
||||||
$return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($table) . " ORDER BY 2"));
|
$return = ($table_status["Rows"] > 1000 ? "" : array("" => "") + get_key_vals("SELECT $id, $name FROM " . table($target) . " ORDER BY 2"));
|
||||||
}
|
}
|
||||||
if (!$return && isset($value)) {
|
if (!$return && isset($value)) {
|
||||||
return $connection->result("SELECT $name FROM " . table($table) . " WHERE $id = " . q($value));
|
return $connection->result("SELECT $name FROM " . table($target) . " WHERE $id = " . q($value));
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
30
plugins/edit-foreign.php
Normal file
30
plugins/edit-foreign.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** Select foreign key in edit form
|
||||||
|
* @author Jakub Vrana, http://www.vrana.cz/
|
||||||
|
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
|
||||||
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
|
||||||
|
*/
|
||||||
|
class AdminerEditForeign {
|
||||||
|
|
||||||
|
function editInput($table, $field, $attrs, $value) {
|
||||||
|
static $foreignTables = array();
|
||||||
|
static $values = array();
|
||||||
|
$foreignKeys = &$foreignTables[$table];
|
||||||
|
if (!isset($foreignKeys)) {
|
||||||
|
$foreignKeys = column_foreign_keys($table);
|
||||||
|
}
|
||||||
|
foreach ((array) $foreignKeys[$field["field"]] as $foreignKey) {
|
||||||
|
if (count($foreignKey["source"]) == 1) {
|
||||||
|
$target = $foreignKey["table"];
|
||||||
|
$id = $foreignKey["target"][0];
|
||||||
|
$options = &$values[$target][$id];
|
||||||
|
if (!$options) {
|
||||||
|
$options = array("" => "") + get_vals("SELECT " . idf_escape($id) . " FROM " . table($target) . " ORDER BY 1");
|
||||||
|
}
|
||||||
|
return "<select$attrs>" . optionlist($options, $value) . "</select>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue