]> git.joonet.de Git - adminer.git/commitdiff
Row descriptions in select
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 20 Jul 2009 15:34:05 +0000 (15:34 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Mon, 20 Jul 2009 15:34:05 +0000 (15:34 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@856 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/adminer.inc.php
adminer/select.inc.php
editor/include/adminer.inc.php

index 3e16210fb259920776a00e9a316ae6e08a2fb0bb..ad8c1be2bbbb1320565b1f54beab3cde2b10092b 100644 (file)
@@ -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
index ac5ba0e1e0e22cb9e17591ce53dd1e565fc2c27a..fab31791cf361eeb33dcc19bfd93216ea3af9c4f 100644 (file)
@@ -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('&amp;', 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']) . '&amp;' . $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()
index a5a113d8d9ed5b7385cca79e0841e87184d55eee..0f6f4507590e78198d3ae3a8858d05b615448bd6 100644 (file)
@@ -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);
 }