From 29b0898715763deb093ad3cca005c5998f79f45b Mon Sep 17 00:00:00 2001 From: Lionel Laffineur Date: Sun, 24 Dec 2023 16:21:45 +0100 Subject: [PATCH] Plugin to move position of the SQL Edit textarea above or bellow resultset --- adminer/include/functions.inc.php | 62 ++++++++++++++++++++++++++++++ adminer/index.php | 3 ++ adminer/sql.inc.php | 64 ++++--------------------------- plugins/sql-edit-position.php | 13 +++++++ 4 files changed, 85 insertions(+), 57 deletions(-) create mode 100644 plugins/sql-edit-position.php diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 6565375a..c3462a1d 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -1564,3 +1564,65 @@ function edit_form($table, $fields, $row, $update) { "; + $execute = ""; + if (!isset($_GET["import"])) { + $q = $_GET["sql"]; // overwrite $q from if ($_POST) to save memory + if ($_POST) { + $q = $_POST["query"]; + } elseif ($_GET["history"] == "all") { + $q = $history; + } elseif ($_GET["history"] != "") { + $q = $history[$_GET["history"]][0]; + } + echo "

"; + textarea("query", $q, 20); + echo script(($_POST ? "" : "qs('textarea').focus();\n") . "qs('#form').onsubmit = partial(sqlSubmit, qs('#form'), '" . js_escape(remove_from_uri("sql|limit|error_stops|only_errors|history")) . "');"); + echo "

$execute\n"; + echo lang('Limit rows') . ": \n"; + + } else { + echo "

" . lang('File upload') . "
"; + $gz = (extension_loaded("zlib") ? "[.gz]" : ""); + echo (ini_bool("file_uploads") + ? "SQL$gz (< " . ini_get("upload_max_filesize") . "B): \n$execute" // ignore post_max_size because it is for all form fields together and bytes computing would be necessary + : lang('File uploads are disabled.') + ); + echo "
\n"; + $importServerPath = $adminer->importServerPath(); + if ($importServerPath) { + echo "
" . lang('From server') . "
"; + echo lang('Webserver file %s', "" . h($importServerPath) . "$gz"); + echo ' '; + echo "
\n"; + } + echo "

"; + } + + echo checkbox("error_stops", 1, ($_POST ? $_POST["error_stops"] : isset($_GET["import"]) || $_GET["error_stops"]), lang('Stop on error')) . "\n"; + echo checkbox("only_errors", 1, ($_POST ? $_POST["only_errors"] : isset($_GET["import"]) || $_GET["only_errors"]), lang('Show only errors')) . "\n"; + echo "\n"; + + if (!isset($_GET["import"]) && $history) { + print_fieldset("history", lang('History'), $_GET["history"] != ""); + for ($val = end($history); $val; $val = prev($history)) { // not array_reverse() to save memory + $key = key($history); + list($q, $time, $elapsed) = $val; + echo '' . lang('Edit') . "" + . " " . @date("H:i:s", $time) . "" // @ - time zone may be not set + . " " . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $q)))), 80, "") + . ($elapsed ? " ($elapsed)" : "") + . "
\n" + ; + } + echo "\n"; + echo "" . lang('Edit all') . "\n"; + echo "\n"; + } + echo ""; +} + diff --git a/adminer/index.php b/adminer/index.php index 38ef5538..a67c67b6 100644 --- a/adminer/index.php +++ b/adminer/index.php @@ -8,6 +8,9 @@ */ $GLOBALS['project'] = basename(dirname(__FILE__)); +$GLOBALS['config'] = [ + 'sql_edit_position' => 'below', +]; include "./include/bootstrap.inc.php"; include "./include/tmpfile.inc.php"; diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index c5747392..c542a28a 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -1,4 +1,5 @@ dumpTable("", ""); @@ -16,6 +17,10 @@ if (!$error && $_POST["clear"]) { page_header((isset($_GET["import"]) ? lang('Import') : lang('SQL command')), $error); +if (isset($GLOBALS['config']['sql_edit_position']) && ($GLOBALS['config']['sql_edit_position'] === 'above' || $GLOBALS['config']['sql_edit_position'] === 'both')) { + display_sql_edit($token); +} + if (!$error && $_POST) { $fp = false; if (!isset($_GET["import"])) { @@ -207,63 +212,8 @@ if (!$error && $_POST) { echo "

" . upload_error($query) . "\n"; } } -?> -

-"; -if (!isset($_GET["import"])) { - $q = $_GET["sql"]; // overwrite $q from if ($_POST) to save memory - if ($_POST) { - $q = $_POST["query"]; - } elseif ($_GET["history"] == "all") { - $q = $history; - } elseif ($_GET["history"] != "") { - $q = $history[$_GET["history"]][0]; - } - echo "

"; - textarea("query", $q, 20); - echo script(($_POST ? "" : "qs('textarea').focus();\n") . "qs('#form').onsubmit = partial(sqlSubmit, qs('#form'), '" . js_escape(remove_from_uri("sql|limit|error_stops|only_errors|history")) . "');"); - echo "

$execute\n"; - echo lang('Limit rows') . ": \n"; - -} else { - echo "

" . lang('File upload') . "
"; - $gz = (extension_loaded("zlib") ? "[.gz]" : ""); - echo (ini_bool("file_uploads") - ? "SQL$gz (< " . ini_get("upload_max_filesize") . "B): \n$execute" // ignore post_max_size because it is for all form fields together and bytes computing would be necessary - : lang('File uploads are disabled.') - ); - echo "
\n"; - $importServerPath = $adminer->importServerPath(); - if ($importServerPath) { - echo "
" . lang('From server') . "
"; - echo lang('Webserver file %s', "" . h($importServerPath) . "$gz"); - echo ' '; - echo "
\n"; - } - echo "

"; -} - -echo checkbox("error_stops", 1, ($_POST ? $_POST["error_stops"] : isset($_GET["import"]) || $_GET["error_stops"]), lang('Stop on error')) . "\n"; -echo checkbox("only_errors", 1, ($_POST ? $_POST["only_errors"] : isset($_GET["import"]) || $_GET["only_errors"]), lang('Show only errors')) . "\n"; -echo "\n"; - -if (!isset($_GET["import"]) && $history) { - print_fieldset("history", lang('History'), $_GET["history"] != ""); - for ($val = end($history); $val; $val = prev($history)) { // not array_reverse() to save memory - $key = key($history); - list($q, $time, $elapsed) = $val; - echo '' . lang('Edit') . "" - . " " . @date("H:i:s", $time) . "" // @ - time zone may be not set - . " " . shorten_utf8(ltrim(str_replace("\n", " ", str_replace("\r", "", preg_replace('~^(#|-- ).*~m', '', $q)))), 80, "") - . ($elapsed ? " ($elapsed)" : "") - . "
\n" - ; - } - echo "\n"; - echo "" . lang('Edit all') . "\n"; - echo "\n"; +if (isset($GLOBALS['config']['sql_edit_position']) === false || $GLOBALS['config']['sql_edit_position'] === 'below' || $GLOBALS['config']['sql_edit_position'] === 'both') { + display_sql_edit($token); } ?> -

diff --git a/plugins/sql-edit-position.php b/plugins/sql-edit-position.php new file mode 100644 index 00000000..146c73e7 --- /dev/null +++ b/plugins/sql-edit-position.php @@ -0,0 +1,13 @@ + +* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 +* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) +*/ +class AdminerSqlEditPosition { + function __construct($position = 'above') { + $GLOBALS['config']['sql_edit_position'] = $position; + } +}