mirror of
https://github.com/vrana/adminer.git
synced 2025-08-08 07:36:44 +02:00
Row descriptions in select
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@856 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
@@ -57,6 +57,15 @@ function adminer_select_query($query) {
|
||||
return call_adminer('select_query', "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n", $query);
|
||||
}
|
||||
|
||||
/** Descriptions of selected data
|
||||
* @param array all data to print
|
||||
* @param array foreign keys
|
||||
* @return array
|
||||
*/
|
||||
function adminer_row_descriptions($rows, $foreign_keys) {
|
||||
return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
|
||||
}
|
||||
|
||||
/** Value printed in select table
|
||||
* @param string escaped value to print
|
||||
* @param string link to foreign key
|
||||
|
@@ -282,6 +282,7 @@ if (!$columns) {
|
||||
$foreign_keys[$val][] = $foreign_key;
|
||||
}
|
||||
}
|
||||
$descriptions = adminer_row_descriptions($rows, $foreign_keys);
|
||||
|
||||
//! Editor only
|
||||
$backward_keys = array();
|
||||
@@ -306,7 +307,7 @@ if (!$columns) {
|
||||
echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . adminer_field_name($fields, $key) . '</a>';
|
||||
}
|
||||
echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
|
||||
foreach ($rows as $row) {
|
||||
foreach ($descriptions as $n => $row) {
|
||||
$unique_idf = implode('&', unique_idf($row, $indexes)); //! don't use aggregation functions
|
||||
echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');">' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . $unique_idf . '">' . lang('edit') . '</a>');
|
||||
foreach ($row as $key => $val) {
|
||||
@@ -334,7 +335,7 @@ if (!$columns) {
|
||||
foreach ((array) $foreign_keys[$key] as $foreign_key) {
|
||||
if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
|
||||
foreach ($foreign_key["source"] as $i => $source) {
|
||||
$link .= where_link($i, $foreign_key["target"][$i], $row[$source]);
|
||||
$link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
|
||||
}
|
||||
$link = htmlspecialchars((strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . urlencode($foreign_key["table"])) . $link; // InnoDB supports non-UNIQUE keys
|
||||
break;
|
||||
@@ -351,7 +352,7 @@ if (!$columns) {
|
||||
echo ' <a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($table);
|
||||
$i = 0;
|
||||
foreach ($columns as $column => $val) {
|
||||
echo where_link($i, $column, $row[$val]);
|
||||
echo where_link($i, $column, $rows[$n][$val]);
|
||||
$i++;
|
||||
}
|
||||
echo '">' . htmlspecialchars($table) . '</a>'; //! adminer_table_name()
|
||||
|
@@ -29,6 +29,44 @@ function adminer_select_query($query) {
|
||||
return call_adminer('select_query', "<!-- " . str_replace("--", "--><!--", $query) . " -->\n", $query);
|
||||
}
|
||||
|
||||
function adminer_row_descriptions($rows, $foreign_keys) {
|
||||
global $dbh;
|
||||
$return = $rows;
|
||||
foreach ($rows[0] as $key => $val) {
|
||||
foreach ((array) $foreign_keys[$key] as $foreign_key) {
|
||||
if (count($foreign_key["source"]) == 1) {
|
||||
$id = idf_escape($foreign_key["target"][0]);
|
||||
// find out the description column - first varchar
|
||||
$name = $id;
|
||||
foreach (fields($foreign_key["table"]) as $field) {
|
||||
if ($field["type"] == "varchar") {
|
||||
$name = idf_escape($field["field"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// find all used ids
|
||||
$ids = array();
|
||||
foreach ($rows as $row) {
|
||||
$ids[$row[$key]] = $dbh->quote($row[$key]);
|
||||
}
|
||||
// select all descriptions
|
||||
$descriptions = array();
|
||||
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
|
||||
while ($row = $result->fetch_row()) {
|
||||
$descriptions[$row[0]] = $row[1];
|
||||
}
|
||||
$result->free();
|
||||
// use the descriptions
|
||||
foreach ($rows as $n => $row) {
|
||||
$return[$n][$key] = $descriptions[$row[$key]];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return call_adminer('row_descriptions', $return, $rows, $foreign_keys);
|
||||
}
|
||||
|
||||
function adminer_select_val($val, $link) {
|
||||
return call_adminer('select_val', ($link ? '<a href="' . $link . '">' . $val . '</a>' : $val), $val, $link);
|
||||
}
|
||||
|
Reference in New Issue
Block a user