diff --git a/adminer/call.inc.php b/adminer/call.inc.php index 8feb3293..09592544 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -28,8 +28,10 @@ if (!$error && $_POST) { } $call[] = (isset($out[$key]) ? "@" . idf_escape($field["field"]) : $val); } + $query = (isset($_GET["callf"]) ? "SELECT" : "CALL") . " " . idf_escape($PROCEDURE) . "(" . implode(", ", $call) . ")"; echo "

" . h($query) . " " . lang('Edit') . "\n"; + if (!$connection->multi_query($query)) { echo "

" . error() . "\n"; } else { @@ -37,6 +39,7 @@ if (!$error && $_POST) { if (is_object($connection2)) { $connection2->select_db(DB); } + do { $result = $connection->store_result(); if (is_object($result)) { @@ -45,6 +48,7 @@ if (!$error && $_POST) { echo "

" . lang('Routine has been called, %d row(s) affected.', $connection->affected_rows) . "\n"; } } while ($connection->next_result()); + if ($out) { select($connection->query("SELECT " . implode(", ", $out))); } diff --git a/adminer/create.inc.php b/adminer/create.inc.php index a88e9a82..94826183 100644 --- a/adminer/create.inc.php +++ b/adminer/create.inc.php @@ -29,6 +29,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] ksort($_POST["fields"]); $orig_field = reset($orig_fields); $after = " FIRST"; + foreach ($_POST["fields"] as $key => $field) { $foreign_key = $foreign_keys[$field["type"]]; $type_field = ($foreign_key !== null ? $referencable_primary[$foreign_key] : $field); //! can collide with user defined type @@ -62,6 +63,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] } } } + $partitioning = ""; if (in_array($_POST["partition_by"], $partition_by)) { $partitions = array(); @@ -78,12 +80,14 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["drop_col"] && !$_POST["up"] } elseif (support("partitioning") && ereg("partitioned", $orig_status["Create_options"])) { $partitioning .= "\nREMOVE PARTITIONING"; } + $message = lang('Table has been altered.'); if ($TABLE == "") { cookie("adminer_engine", $_POST["Engine"]); $message = lang('Table has been created.'); } $name = trim($_POST["name"]); + queries_redirect(ME . "table=" . urlencode($name), $message, alter_table( $TABLE, $name, @@ -105,12 +109,14 @@ $row = array( "fields" => array(array("field" => "", "type" => (isset($types["int"]) ? "int" : (isset($types["integer"]) ? "integer" : "")))), "partition_names" => array(""), ); + if ($_POST) { $row = $_POST; if ($row["auto_increment_col"]) { $row["fields"][$row["auto_increment_col"]]["auto_increment"] = true; } process_fields($row["fields"]); + } elseif ($TABLE != "") { $row = $orig_status; $row["name"] = $TABLE; @@ -122,6 +128,7 @@ if ($_POST) { $field["has_default"] = isset($field["default"]); $row["fields"][] = $field; } + if (support("partitioning")) { $from = "FROM information_schema.PARTITIONS WHERE TABLE_SCHEMA = " . q(DB) . " AND TABLE_NAME = " . q($TABLE); $result = $connection->query("SELECT PARTITION_METHOD, PARTITION_ORDINAL_POSITION, PARTITION_EXPRESSION $from ORDER BY PARTITION_ORDINAL_POSITION DESC LIMIT 1"); @@ -135,8 +142,8 @@ if ($_POST) { $row["partition_names"][] = ""; } } -$collations = collations(); +$collations = collations(); $engines = engines(); // case of engine may differ foreach ($engines as $engine) { diff --git a/adminer/db.inc.php b/adminer/db.inc.php index c1c9d3d9..9ec3f95f 100644 --- a/adminer/db.inc.php +++ b/adminer/db.inc.php @@ -7,6 +7,7 @@ if ($tables_views && !$error && !$_POST["search"]) { if ($jush == "sql" && count($_POST["tables"]) > 1 && ($_POST["drop"] || $_POST["truncate"] || $_POST["copy"])) { queries("SET foreign_key_checks = 0"); // allows to truncate or drop several tables at once } + if ($_POST["truncate"]) { if ($_POST["tables"]) { $result = truncate_tables($_POST["tables"]); @@ -39,6 +40,7 @@ if ($tables_views && !$error && !$_POST["search"]) { $message .= "" . h($row["Table"]) . ": " . h($row["Msg_text"]) . "
"; } } + queries_redirect(substr(ME, 0, -1), $message, $result); } @@ -57,6 +59,7 @@ if ($adminer->homepage()) { search_tables(); } echo "\n"; + echo '\n"; + foreach ($tables_list as $name => $type) { $view = ($type !== null && !eregi("table", $type)); echo '
'; echo '' . lang('Table'); echo '' . lang('Engine'); @@ -68,6 +71,7 @@ if ($adminer->homepage()) { echo '' . lang('Rows'); echo (support("comment") ? '' . lang('Comment') : ''); echo "
' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');"); @@ -90,12 +94,14 @@ if ($adminer->homepage()) { } echo (support("comment") ? " " : ""); } + echo "
 " . lang('%d in total', count($tables_list)); echo "" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : ""); echo "" . nbsp(db_collation(DB, collations())); foreach (array("Data_length", "Index_length", "Data_free") as $key) { echo " "; } + echo "
\n"; echo "\n"; if (!information_schema(DB)) { diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 4e0e0fe0..02b13dd4 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -12,6 +12,7 @@ if ($_POST && !$error) { (count($tables) == 1 ? key($tables) : DB), (DB == "" || count($tables) > 1)); $is_sql = ereg('sql', $_POST["format"]); + if ($is_sql) { echo "-- Adminer $VERSION " . $drivers[DRIVER] . " dump @@ -31,6 +32,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; $databases = explode("\n", rtrim(str_replace("\r", "", $databases), "\n")); } } + foreach ((array) $databases as $db) { $adminer->dumpDatabase($db); if ($connection->select_db($db)) { @@ -45,6 +47,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; echo use_sql($db) . ";\n\n"; } $out = ""; + if ($_POST["routines"]) { foreach (array("FUNCTION", "PROCEDURE") as $routine) { foreach (get_rows("SHOW $routine STATUS WHERE Db = " . q($db), null, "-- ") as $row) { @@ -53,12 +56,14 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; } } } + if ($_POST["events"]) { foreach (get_rows("SHOW EVENTS", null, "-- ") as $row) { $out .= ($style != 'DROP+CREATE' ? "DROP EVENT IF EXISTS " . idf_escape($row["Name"]) . ";;\n" : "") . remove_definer($connection->result("SHOW CREATE EVENT " . idf_escape($row["Name"]), 3)) . ";;\n\n"; } } + if ($out) { echo "DELIMITER ;;\n\n$out" . "DELIMITER ;\n\n"; } @@ -74,6 +79,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; $tmp_file = new TmpFile; ob_start(array($tmp_file, 'write'), 1e5); } + $adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0)); if (is_view($table_status)) { $views[] = $name; @@ -84,6 +90,7 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name, $_POST["table_style"]))) { echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n"; } + if ($ext == "tar") { ob_end_flush(); tar_file((DB != "" ? "" : "$db/") . "$name.csv", $tmp_file); @@ -92,15 +99,18 @@ SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO'; } } } + foreach ($views as $view) { $adminer->dumpTable($view, $_POST["table_style"], 1); } + if ($ext == "tar") { echo pack("x512"); } } } } + if ($is_sql) { echo "-- " . $connection->result("SELECT NOW()") . "\n"; } @@ -127,16 +137,21 @@ if (!isset($row["events"])) { // backwards compatibility $row["routines"] = $row["events"] = ($_GET["dump"] == ""); $row["triggers"] = $row["table_style"]; } + echo "" . lang('Output') . "" . html_select("output", $adminer->dumpOutput(), $row["output"], 0) . "\n"; // 0 - radio + echo "" . lang('Format') . "" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio + echo ($jush == "sqlite" ? "" : "" . lang('Database') . "" . html_select('db_style', $db_style, $row["db_style"]) . (support("routine") ? checkbox("routines", 1, $row["routines"], lang('Routines')) : "") . (support("event") ? checkbox("events", 1, $row["events"], lang('Events')) : "") ); + echo "" . lang('Tables') . "" . html_select('table_style', $table_style, $row["table_style"]) . checkbox("auto_increment", 1, $row["auto_increment"], lang('Auto Increment')) . (support("trigger") ? checkbox("triggers", 1, $row["triggers"], lang('Triggers')) : "") ; + echo "" . lang('Data') . "" . html_select('data_style', $data_style, $row["data_style"]); ?> @@ -152,6 +167,7 @@ if (DB != "") { echo ""; echo ""; echo "\n"; + $views = ""; //! defer number of rows to JavaScript foreach (table_status() as $name => $table_status) { @@ -166,6 +182,7 @@ if (DB != "") { $prefixes[$prefix]++; } echo $views; + } else { echo "\n"; $databases = $adminer->databases(); diff --git a/adminer/edit.inc.php b/adminer/edit.inc.php index 49849681..1c1fed63 100644 --- a/adminer/edit.inc.php +++ b/adminer/edit.inc.php @@ -8,6 +8,7 @@ foreach ($fields as $name => $field) { unset($fields[$name]); } } + if ($_POST && !$error && !isset($_GET["select"])) { $location = $_POST["referer"]; if ($_POST["insert"]) { // continue edit or insert @@ -15,6 +16,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { } elseif (!ereg('^.+&select=.+$', $location)) { $location = ME . "select=" . urlencode($TABLE); } + if (isset($_POST["delete"])) { query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE $where"), $location, lang('Item has been deleted.')); } else { @@ -25,6 +27,7 @@ if ($_POST && !$error && !isset($_GET["select"])) { $set[idf_escape($name)] = ($update ? "\n" . idf_escape($name) . " = $val" : $val); } } + if ($update) { if (!$set) { redirect($location); @@ -81,6 +84,7 @@ if (!$fields) { echo "

" . lang('You have no privileges to update this table.') . "\n"; } else { echo "\n"; + foreach ($fields as $name => $field) { echo "
" . $adminer->fieldName($field); $default = $_GET["set"][bracket_escape($name)]; @@ -105,6 +109,7 @@ if (!$fields) { input($field, $value, $function); echo "\n"; } + echo "
\n"; } ?> diff --git a/adminer/event.inc.php b/adminer/event.inc.php index 152568a6..ce38c5da 100644 --- a/adminer/event.inc.php +++ b/adminer/event.inc.php @@ -14,6 +14,7 @@ if ($_POST && !$error) { : "AT " . q($_POST["STARTS"]) ) . " ON COMPLETION" . ($_POST["ON_COMPLETION"] ? "" : " NOT") . " PRESERVE" ; + queries_redirect(substr(ME, 0, -1), ($EVENT != "" ? lang('Event has been altered.') : lang('Event has been created.')), queries(($EVENT != "" ? "ALTER EVENT " . idf_escape($EVENT) . $schedule . ($EVENT != $_POST["EVENT_NAME"] ? "\nRENAME TO " . idf_escape($_POST["EVENT_NAME"]) : "") diff --git a/adminer/foreign.inc.php b/adminer/foreign.inc.php index 95ca075b..e733f3b9 100644 --- a/adminer/foreign.inc.php +++ b/adminer/foreign.inc.php @@ -10,6 +10,7 @@ if ($_POST && !$error && !$_POST["add"] && !$_POST["change"] && !$_POST["change- foreach ($source as $key => $val) { $target[$key] = $_POST["target"][$key]; } + query_redirect("ALTER TABLE " . table($TABLE) . ($_GET["name"] != "" ? "\nDROP " . ($jush == "sql" ? "FOREIGN KEY " : "CONSTRAINT ") . idf_escape($_GET["name"]) . "," : "") . "\nADD FOREIGN KEY (" . implode(", ", array_map('idf_escape', $source)) . ") REFERENCES " . table($_POST["table"]) . " (" . implode(", ", array_map('idf_escape', $target)) . ")" //! reuse $_GET["name"] - check in older MySQL versions diff --git a/adminer/include/auth.inc.php b/adminer/include/auth.inc.php index 675bd346..c289b906 100644 --- a/adminer/include/auth.inc.php +++ b/adminer/include/auth.inc.php @@ -33,6 +33,7 @@ if ($auth) { ) { redirect(auth_url($auth["driver"], $auth["server"], $auth["username"], $auth["db"])); } + } elseif ($_POST["logout"]) { if ($token && $_POST["token"] != $token) { page_header(lang('Logout'), lang('Invalid CSRF token. Send the form again.')); @@ -45,6 +46,7 @@ if ($auth) { unset_permanent(); redirect(substr(preg_replace('~(username|db|ns)=[^&]*&~', '', ME), 0, -1), lang('Logout successful.')); } + } elseif ($permanent && !$_SESSION["pwds"]) { session_regenerate_id(); $private = $adminer->permanentLogin(); // try to decode even if not set @@ -105,6 +107,7 @@ if (isset($_GET["username"])) { } $connection = connect(); } + if (is_string($connection) || !$adminer->login($_GET["username"], get_session("pwds"))) { auth_error(); exit; @@ -134,6 +137,7 @@ if ($_POST) { : lang('Invalid CSRF token. Send the form again.') ); } + } elseif ($_SERVER["REQUEST_METHOD"] == "POST") { // posted form with no data means that post_max_size exceeded because Adminer always sends token at least $error = lang('Too big POST data. Reduce the data or increase the %s configuration directive.', "'post_max_size'"); diff --git a/adminer/include/connect.inc.php b/adminer/include/connect.inc.php index 0ecae00b..637abef9 100644 --- a/adminer/include/connect.inc.php +++ b/adminer/include/connect.inc.php @@ -31,6 +31,7 @@ function connect_error() { echo "

\n"; echo "\n"; echo "\n"; + foreach ($databases as $db) { $root = h(ME) . "db=" . urlencode($db); echo "
 " . lang('Database') . "" . lang('Collation') . "" . lang('Tables') . "
" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"])); @@ -39,6 +40,7 @@ function connect_error() { echo "?"; echo "\n"; } + echo "
\n"; echo "\n"; echo "

\n"; @@ -49,6 +51,7 @@ function connect_error() { echo "

$refresh"; } } + page_footer("db"); if ($databases) { echo "\n"; diff --git a/adminer/include/tmpfile.inc.php b/adminer/include/tmpfile.inc.php index 6fa58c19..2038868e 100644 --- a/adminer/include/tmpfile.inc.php +++ b/adminer/include/tmpfile.inc.php @@ -18,4 +18,5 @@ class TmpFile { fpassthru($this->handler); fclose($this->handler); } + } diff --git a/adminer/index.php b/adminer/index.php index a024aabd..523baf3c 100644 --- a/adminer/index.php +++ b/adminer/index.php @@ -22,6 +22,7 @@ if (isset($_GET["callf"])) { if (isset($_GET["function"])) { $_GET["procedure"] = $_GET["function"]; } + if (isset($_GET["download"])) { include "./download.inc.php"; } elseif (isset($_GET["table"])) { diff --git a/adminer/indexes.inc.php b/adminer/indexes.inc.php index 2dcb4d14..0b85acf4 100644 --- a/adminer/indexes.inc.php +++ b/adminer/indexes.inc.php @@ -10,6 +10,7 @@ if ($jush == "sqlite") { // doesn't support primary key unset($index_types[0]); unset($indexes[""]); } + if ($_POST && !$error && !$_POST["add"]) { $alter = array(); foreach ($_POST["indexes"] as $index) { @@ -27,6 +28,7 @@ if ($_POST && !$error && !$_POST["add"]) { $lengths[] = ($length ? $length : null); } } + if ($columns) { $existing = $indexes[$name]; if ($existing) { @@ -42,6 +44,7 @@ if ($_POST && !$error && !$_POST["add"]) { } } } + // drop removed indexes foreach ($indexes as $name => $existing) { $alter[] = array($existing["type"], $name, "DROP"); @@ -86,12 +89,14 @@ $j = 1; foreach ($row["indexes"] as $index) { echo "" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1)) . ""; ksort($index["columns"]); + $i = 1; foreach ($index["columns"] as $key => $column) { echo "" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');"); echo " "; //! hide for non-MySQL drivers, add ASC|DESC $i++; } + echo "\n"; $j++; } diff --git a/adminer/privileges.inc.php b/adminer/privileges.inc.php index 58e91174..d4b68ef8 100644 --- a/adminer/privileges.inc.php +++ b/adminer/privileges.inc.php @@ -7,18 +7,22 @@ if (!$result) { // list logged user, information_schema.USER_PRIVILEGES lists just the current user too $result = $connection->query("SELECT SUBSTRING_INDEX(CURRENT_USER, '@', 1) AS User, SUBSTRING_INDEX(CURRENT_USER, '@', -1) AS Host"); } + echo "

\n"; hidden_fields_get(); echo "\n"; echo ($grant ? "" : "\n"); echo "\n"; echo "\n"; + while ($row = $result->fetch_assoc()) { echo '
" . lang('Username') . "" . lang('Server') . " 
' . h($row["User"]) . "" . h($row["Host"]) . '' . lang('Edit') . "\n"; } + if (!$grant || DB != "") { echo "\n"; } + echo "
\n"; echo "

\n"; diff --git a/adminer/processlist.inc.php b/adminer/processlist.inc.php index dca53d61..5938ec55 100644 --- a/adminer/processlist.inc.php +++ b/adminer/processlist.inc.php @@ -18,6 +18,7 @@ page_header(lang('Process list'), $error); // HTML valid because there is always at least one process $i = -1; foreach (process_list() as $i => $row) { + if (!$i) { echo "" . (support("kill") ? " " : ""); foreach ($row as $key => $val) { @@ -28,6 +29,7 @@ foreach (process_list() as $i => $row) { } echo "\n"; } + echo "" . (support("kill") ? "" . checkbox("kill[]", $row["Id"], 0) : ""); foreach ($row as $key => $val) { echo "" . ( diff --git a/adminer/schema.inc.php b/adminer/schema.inc.php index 2c07bfe9..6383c86d 100644 --- a/adminer/schema.inc.php +++ b/adminer/schema.inc.php @@ -62,10 +62,12 @@ document.onmouseup = function (ev) { foreach ($schema as $name => $table) { echo "
"; echo '' . h($name) . ""; + foreach ($table["fields"] as $field) { $val = '' . h($field["field"]) . ''; echo "
" . ($field["primary"] ? "$val" : $val); } + foreach ((array) $table["references"] as $target_name => $refs) { foreach ($refs as $left => $ref) { $left1 = $left - $table_pos[$name][1]; @@ -75,6 +77,7 @@ foreach ($schema as $name => $table) { } } } + foreach ((array) $referenced[$name] as $target_name => $refs) { foreach ($refs as $left => $columns) { $left1 = $left - $table_pos[$name][1]; @@ -84,8 +87,10 @@ foreach ($schema as $name => $table) { } } } + echo "\n
\n"; } + foreach ($schema as $name => $table) { foreach ((array) $table["references"] as $target_name => $refs) { foreach ($refs as $left => $ref) { diff --git a/adminer/select.inc.php b/adminer/select.inc.php index fc005485..07c2fbef 100644 --- a/adminer/select.inc.php +++ b/adminer/select.inc.php @@ -59,6 +59,7 @@ if ($_POST && !$error) { unset($unselected[$key]); } } + if ($_POST["export"]) { cookie("adminer_import", "output=" . urlencode($_POST["output"]) . "&format=" . urlencode($_POST["format"])); dump_headers($TABLE); @@ -80,6 +81,7 @@ if ($_POST && !$error) { $adminer->dumpData($TABLE, "table", $query); exit; } + if (!$adminer->selectEmailProcess($where, $foreign_keys)) { if ($_POST["save"] || $_POST["delete"]) { // edit $result = true; @@ -132,6 +134,7 @@ if ($_POST && !$error) { } queries_redirect(remove_from_uri($_POST["all"] && $_POST["delete"] ? "page" : ""), $message, $result); //! display edit page in case of an error + } elseif (!$_POST["import"]) { // modify if (!$_POST["val"]) { $error = lang('Ctrl+click on a value to modify it.'); @@ -154,6 +157,7 @@ if ($_POST && !$error) { } queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result); } + } elseif (is_string($file = get_file("csv_file", true))) { //! character set cookie("adminer_import", "output=" . urlencode($adminer_import["output"]) . "&format=" . urlencode($_POST["separator"])); @@ -185,6 +189,7 @@ if ($_POST && !$error) { } queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result); queries("ROLLBACK"); // after queries_redirect() to not overwrite error + } else { $error = upload_error($file); } @@ -306,6 +311,7 @@ if (!$columns) { next($select); } } + $lengths = array(); if ($_GET["modify"]) { foreach ($rows as $row) { @@ -314,13 +320,16 @@ if (!$columns) { } } } + echo ($backward_keys ? "" . lang('Relations') : "") . "\n"; + if (is_ajax()) { if ($limit % 2 == 1 && $page % 2 == 1) { odd(); } ob_end_clean(); } + foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) { $unique_array = unique_array($rows[$n], $indexes); $unique_idf = ""; @@ -332,12 +341,14 @@ if (!$columns) { $unique_idf .= "&" . ($val !== null ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key)); } echo "" . (!$group && $select ? "" : "" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . ($is_group || information_schema(DB) ? "" : " " . lang('edit') . "")); + foreach ($row as $key => $val) { if (isset($names[$key])) { $field = $fields[$key]; if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) { $email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages } + $link = ""; $val = $adminer->editVal($val, $field); if ($val !== null) { @@ -366,6 +377,7 @@ if (!$columns) { } } } + if ($key == "COUNT(*)") { //! columns looking like functions $link = ME . "select=" . urlencode($TABLE); $i = 0; @@ -378,7 +390,9 @@ if (!$columns) { $link .= where_link($i++, $k, $v); } } + } + if (!$link && ($link = $adminer->selectLink($row[$key], $field)) === null) { if (is_mail($row[$key])) { $link = "mailto:$row[$key]"; @@ -390,6 +404,7 @@ if (!$columns) { ); } } + $id = h("val[$unique_idf][" . bracket_escape($key) . "]"); $value = $_POST["val"][$unique_idf][bracket_escape($key)]; $h_value = h($value !== null ? $value : $row[$key]); @@ -402,12 +417,14 @@ if (!$columns) { ); } } + if ($backward_keys) { echo ""; } $adminer->backwardKeysPrint($backward_keys, $rows[$n]); echo "\n"; // close to allow white-space: pre } + if (is_ajax()) { exit; } @@ -426,6 +443,7 @@ if (!$columns) { $exact_count = false; } } + if (+$limit && ($found_rows === false || $found_rows > $limit || $page)) { echo "

"; // display first, previous 4, next 4 and last page @@ -447,6 +465,7 @@ if (!$columns) { } echo (($found_rows === false ? count($rows) + 1 : $found_rows - $page * $limit) > $limit ? ' ' . lang('Load more data') . '' : ''); } + echo "

\n"; echo ($found_rows !== false ? "(" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " : ""); echo checkbox("all", 1, 0, lang('whole result')) . "\n"; @@ -461,6 +480,7 @@ if (!$columns) { dumpFormat(); foreach ((array) $_GET["columns"] as $column) { if ($column["fun"]) { @@ -477,6 +497,7 @@ if (!$columns) { echo "\n"; } } + if ($adminer->selectImportPrint()) { print_fieldset("import", lang('Import'), !$rows); echo " "; diff --git a/adminer/sql.inc.php b/adminer/sql.inc.php index 7ad14ef5..97dbd43a 100644 --- a/adminer/sql.inc.php +++ b/adminer/sql.inc.php @@ -28,10 +28,12 @@ if (!$error && $_POST) { } elseif ($_FILES && $_FILES["sql_file"]["error"][0] != 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 if (function_exists('memory_get_usage')) { @ini_set("memory_limit", max(ini_bytes("memory_limit"), 2 * strlen($query) + memory_get_usage() + 8e6)); // @ - may be disabled, 2 - substr and trim, 8e6 - other variables } + if ($query != "" && strlen($query) < 1e6) { // don't add big queries $q = $query . (ereg(";[ \t\r\n]*\$", $query) ? "" : ";"); //! doesn't work with DELIMITER | if (!$history || reset(end($history)) != $q) { // no repeated queries @@ -41,6 +43,7 @@ if (!$error && $_POST) { stop_session(); } } + $space = "(?:\\s|/\\*.*\\*/|(?:#|-- )[^\n]*\n|--\n)"; $delimiter = ";"; $offset = 0; @@ -57,6 +60,7 @@ if (!$error && $_POST) { parse_str($_COOKIE["adminer_export"], $adminer_export); $dump_format = $adminer->dumpFormat(); unset($dump_format["sql"]); + while ($query != "") { if (!$offset && preg_match("~^$space*DELIMITER\\s+(\\S+)~i", $query, $match)) { $delimiter = $match[1]; @@ -71,6 +75,7 @@ if (!$error && $_POST) { break; } $offset = $pos + strlen($found); + if ($found && rtrim($found) != $delimiter) { // find matching quote or comment end while (preg_match('(' . ($found == '/*' ? '\\*/' : ($found == '[' ? ']' : (ereg('^-- |^#', $found) ? "\n" : preg_quote($found) . "|\\\\."))) . '|$)s', $query, $match, PREG_OFFSET_CAPTURE, $offset)) { //! respect sql_mode NO_BACKSLASH_ESCAPES $s = $match[0][0]; @@ -83,6 +88,7 @@ if (!$error && $_POST) { } } } + } else { // end of a query $empty = false; $q = substr($query, 0, $pos); @@ -98,11 +104,14 @@ if (!$error && $_POST) { if ($connection->multi_query($q) && is_object($connection2) && preg_match("~^$space*USE\\b~isU", $q)) { $connection2->query($q); } + do { $result = $connection->store_result(); $end = microtime(); $time = " (" . format_time($start, $end) . ")" - . (strlen($q) < 1000 ? " " . lang('Edit') . "" : ""); // 1000 - maximum length of encoded URL in IE is 2083 characters + . (strlen($q) < 1000 ? " " . lang('Edit') . "" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters + ; + if ($connection->error) { echo ($_POST["only_errors"] ? $print : ""); echo "

" . lang('Error in query') . ($connection->errno ? " ($connection->errno)" : "") . ": " . error() . "\n"; @@ -110,6 +119,7 @@ if (!$error && $_POST) { if ($_POST["error_stops"]) { break 2; } + } elseif (is_object($result)) { $orgtables = select($result, $connection2); if (!$_POST["only_errors"]) { @@ -133,6 +143,7 @@ if (!$error && $_POST) { } echo "\n"; } + } else { if (preg_match("~^$space*(CREATE|DROP|ALTER)$space+(DATABASE|SCHEMA)\\b~isU", $q)) { restart_session(); @@ -143,15 +154,19 @@ if (!$error && $_POST) { echo "

" . lang('Query executed OK, %d row(s) affected.', $connection->affected_rows) . "$time\n"; } } + $start = $end; } while ($connection->next_result()); + $line += substr_count($q.$found, "\n"); $query = substr($query, $offset); $offset = 0; } + } } } + if ($empty) { echo "

" . lang('No commands to execute.') . "\n"; } elseif ($_POST["only_errors"]) { @@ -161,6 +176,7 @@ if (!$error && $_POST) { echo "

" . lang('Error in query') . ": " . implode("", $errors) . "\n"; } //! MS SQL - SET SHOWPLAN_ALL OFF + } else { echo "

" . upload_error($query) . "\n"; } @@ -178,6 +194,7 @@ if ($_POST) { $q = $history[$_GET["history"]][0]; } textarea("query", $q, 20); + echo ($_POST ? "" : "\n"); echo "

" . (ini_bool("file_uploads") ? lang('File upload') . ': selectLinks($table_status); $comment = $table_status["Comment"]; if ($comment != "") { @@ -79,5 +80,6 @@ if ($fields) { } echo '

' . lang('Add trigger') . "\n"; } + } } diff --git a/adminer/user.inc.php b/adminer/user.inc.php index 873bf427..ec4663b7 100644 --- a/adminer/user.inc.php +++ b/adminer/user.inc.php @@ -26,6 +26,7 @@ if ($_POST) { } $grants = array(); $old_pass = ""; + if (isset($_GET["host"]) && ($result = $connection->query("SHOW GRANTS FOR " . q($USER) . "@" . q($_GET["host"])))) { //! use information_schema for MySQL 5 - column names in column privileges are not escaped while ($row = $result->fetch_row()) { if (preg_match('~GRANT (.*) ON (.*) TO ~', $row[0], $match) && preg_match_all('~ *([^(,]*[^ ,(])( *\\([^)]+\\))?~', $match[1], $matches, PREG_SET_ORDER)) { //! escape the part between ON and TO @@ -56,6 +57,7 @@ if ($_POST && !$error) { $pass = $connection->result("SELECT PASSWORD(" . q($pass) . ")"); $error = !$pass; } + $created = false; if (!$error) { if ($old_user != $new_user) { @@ -65,6 +67,7 @@ if ($_POST && !$error) { queries("SET PASSWORD FOR $new_user = " . q($pass)); } } + if (!$error) { $revoke = array(); foreach ($new_grants as $object => $grant) { @@ -90,6 +93,7 @@ if ($_POST && !$error) { } } } + if (!$error && isset($_GET["host"])) { if ($old_user != $new_user) { queries("DROP USER $old_user"); @@ -101,7 +105,9 @@ if ($_POST && !$error) { } } } + queries_redirect(ME . "privileges=", (isset($_GET["host"]) ? lang('User has been altered.') : lang('User has been created.')), !$error); + if ($created) { // delete new user in case of an error $connection->query("DROP USER $new_user"); @@ -143,6 +149,7 @@ foreach ($grants as $object => $grant) { $i++; } echo "\n"; + foreach (array( "" => "", "Server Admin" => lang('Server'), @@ -168,6 +175,7 @@ foreach (array( } } } + echo "\n"; ?>

diff --git a/editor/db.inc.php b/editor/db.inc.php index 3eaac332..d3625f5a 100644 --- a/editor/db.inc.php +++ b/editor/db.inc.php @@ -9,6 +9,7 @@ if ($adminer->homepage()) { } echo "\n"; echo '\n"; + foreach (table_status() as $table => $row) { $name = $adminer->tableName($row); if (isset($row["Engine"]) && $name != "") { @@ -18,6 +19,7 @@ if ($adminer->homepage()) { echo "
' . lang('Table') . '' . lang('Rows') . "
" . ($row["Engine"] == "InnoDB" && $val ? "~ $val" : $val) . ""; } } + echo "
\n"; echo "\n"; echo "\n"; diff --git a/editor/index.php b/editor/index.php index 00008550..dcc72397 100644 --- a/editor/index.php +++ b/editor/index.php @@ -13,6 +13,7 @@ $drivers[DRIVER] = lang('Login'); if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) { $_GET["edit"] = $_GET["select"]; } + if (isset($_GET["download"])) { include "../adminer/download.inc.php"; } elseif (isset($_GET["edit"])) {