]> git.joonet.de Git - adminer.git/commitdiff
SQL command by AJAX
authorJakub Vrana <jakub@vrana.cz>
Mon, 18 Oct 2010 21:44:00 +0000 (23:44 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 18 Oct 2010 21:44:00 +0000 (23:44 +0200)
adminer/sql.inc.php
adminer/static/functions.js

index 69f9a1d965411d416459590c4f16148e24a72dd9..fa88156cb3d490a8ddbe05570c4a40ef206215c9 100644 (file)
@@ -18,7 +18,7 @@ if (!$error && $_POST) {
                        : "compress.bzip2://adminer.sql.bz2"
                )), "rb");
                $query = ($fp ? fread($fp, 1e6) : false);
-       } elseif ($_FILES["sql_file"]["error"] != 4) { // 4 - UPLOAD_ERR_NO_FILE
+       } elseif ($_FILES["sql_file"] && $_FILES["sql_file"]["error"] != 4) { // 4 - UPLOAD_ERR_NO_FILE
                $query = get_file("sql_file", true);
        }
        if (is_string($query)) { // get_file() returns error as number, fread() as false
@@ -126,9 +126,11 @@ if (!$error && $_POST) {
                echo "<p class='error'>" . upload_error($query) . "\n";
        }
 }
+
+$uploads = ini_bool("file_uploads");
 ?>
 
-<form action="" method="post" enctype="multipart/form-data">
+<form action="" method="post" enctype="multipart/form-data" onsubmit="return <?php echo ($uploads ? "this['sql_file'].value || " : ""); ?>!ajaxForm(this);">
 <p><?php
 $q = $_GET["sql"]; // overwrite $q from if ($_POST) to save memory
 if ($_POST) {
@@ -138,7 +140,7 @@ if ($_POST) {
 }
 textarea("query", $q, 20);
 echo ($_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n");
-echo "<p>" . (ini_bool("file_uploads") ? lang('File upload') . ': <input type="file" name="sql_file">' : lang('File uploads are disabled.'));
+echo "<p>" . ($uploads ? lang('File upload') . ': <input type="file" name="sql_file">' : lang('File uploads are disabled.'));
 
 ?>
 <p>
@@ -155,7 +157,7 @@ foreach (array("gz" => "zlib", "bz2" => "bz2") as $key => $val) {
        }
 }
 echo lang('Webserver file %s', "<code>adminer.sql" . ($compress ? "[" . implode("|", $compress) . "]" : "") . "</code>");
-echo ' <input type="submit" name="webfile" value="' . lang('Run file') . '">';
+echo ' <input type="submit" name="webfile" value="' . lang('Run file') . '" onclick="return !ajaxForm(this.form, \'webfile=1\');">';
 echo "</div></fieldset>\n";
 
 if ($history) {
index 30869daa586eaee504595d398cac0c6a3ae22ddf..f1439bf4b2ac6fae9d359f8e38326c30c842cd1d 100644 (file)
@@ -154,7 +154,7 @@ function textareaKeydown(target, event, tab, button) {
        if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey) { // shiftKey allowed
                if (button) {
                        button.click();
-               } else {
+               } else if (!target.form.onsubmit || target.form.onsubmit() !== false) {
                        target.form.submit();
                }
        }