diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php
index 76103f89..fc148c7e 100644
--- a/adminer/include/adminer.inc.php
+++ b/adminer/include/adminer.inc.php
@@ -214,7 +214,7 @@ username.form['auth[driver]'].onchange();
foreach ($select as $key => $val) {
$val = $_GET["columns"][$key];
echo "
" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, $val["fun"]);
- echo "()
\n";
+ echo "()\n";
$i++;
}
echo "" . html_select("columns[$i][fun]", array(-1 => "") + $fun_group, "", "this.nextSibling.nextSibling.onchange();");
diff --git a/adminer/static/functions.js b/adminer/static/functions.js
index d2b8b7f7..3bd79eb2 100644
--- a/adminer/static/functions.js
+++ b/adminer/static/functions.js
@@ -233,6 +233,8 @@ function selectFieldChange(form) {
}
var ok = true;
var selects = form.getElementsByTagName('select');
+ var group = false;
+ var columns = {};
for (var i=0; i < selects.length; i++) {
var select = selects[i];
var col = selectValue(select);
@@ -246,7 +248,15 @@ function selectFieldChange(form) {
ok = false;
}
}
- //! take grouping in select into account
+ if ((match = /^(columns.+)fun\]/.exec(select.name))) {
+ if (/^(avg|count|count distinct|group_concat|max|min|sum)$/.test(col)) {
+ group = true;
+ }
+ var val = selectValue(form[match[1] + 'col]']);
+ if (val) {
+ columns[col && col != 'count' ? '' : val] = 1;
+ }
+ }
if (col && /^order/.test(select.name)) {
if (!(col in indexColumns)) {
ok = false;
@@ -254,6 +264,13 @@ function selectFieldChange(form) {
break;
}
}
+ if (group) {
+ for (var col in columns) {
+ if (!(col in indexColumns)) {
+ ok = false;
+ }
+ }
+ }
return ok;
})();
setHtml('noindex', (ok ? '' : '!'));