Add empty lines to source code

This commit is contained in:
Jakub Vrana 2013-05-01 18:28:04 -07:00
parent 0e6003e833
commit 9c78b3bb34
21 changed files with 119 additions and 2 deletions

View file

@ -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 "<p><code class='jush-$jush'>" . h($query) . "</code> <a href='" . h(ME) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
if (!$connection->multi_query($query)) {
echo "<p class='error'>" . 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 "<p class='message'>" . 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)));
}

View file

@ -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) {

View file

@ -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 .= "<b>" . h($row["Table"]) . "</b>: " . h($row["Msg_text"]) . "<br>";
}
}
queries_redirect(substr(ME, 0, -1), $message, $result);
}
@ -57,6 +59,7 @@ if ($adminer->homepage()) {
search_tables();
}
echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^(tables|views)\[/);">';
echo '<th>' . lang('Table');
echo '<td>' . lang('Engine');
@ -68,6 +71,7 @@ if ($adminer->homepage()) {
echo '<td>' . lang('Rows');
echo (support("comment") ? '<td>' . lang('Comment') : '');
echo "</thead>\n";
foreach ($tables_list as $name => $type) {
$view = ($type !== null && !eregi("table", $type));
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
@ -90,12 +94,14 @@ if ($adminer->homepage()) {
}
echo (support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "");
}
echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
echo "<td>" . nbsp(db_collation(DB, collations()));
foreach (array("Data_length", "Index_length", "Data_free") as $key) {
echo "<td align='right' id='sum-$key'>&nbsp;";
}
echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
if (!information_schema(DB)) {

View file

@ -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 "<tr><th>" . lang('Output') . "<td>" . html_select("output", $adminer->dumpOutput(), $row["output"], 0) . "\n"; // 0 - radio
echo "<tr><th>" . lang('Format') . "<td>" . html_select("format", $adminer->dumpFormat(), $row["format"], 0) . "\n"; // 0 - radio
echo ($jush == "sqlite" ? "" : "<tr><th>" . lang('Database') . "<td>" . 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 "<tr><th>" . lang('Tables') . "<td>" . 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 "<tr><th>" . lang('Data') . "<td>" . html_select('data_style', $data_style, $row["data_style"]);
?>
</table>
@ -152,6 +167,7 @@ if (DB != "") {
echo "<th style='text-align: left;'><label><input type='checkbox' id='check-tables'$checked onclick='formCheck(this, /^tables\\[/);'>" . lang('Tables') . "</label>";
echo "<th style='text-align: right;'><label>" . lang('Data') . "<input type='checkbox' id='check-data'$checked onclick='formCheck(this, /^data\\[/);'></label>";
echo "</thead>\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 "<thead><tr><th style='text-align: left;'><label><input type='checkbox' id='check-databases'" . ($TABLE == "" ? " checked" : "") . " onclick='formCheck(this, /^databases\\[/);'>" . lang('Database') . "</label></thead>\n";
$databases = $adminer->databases();

View file

@ -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 "<p class='error'>" . lang('You have no privileges to update this table.') . "\n";
} else {
echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
foreach ($fields as $name => $field) {
echo "<tr><th>" . $adminer->fieldName($field);
$default = $_GET["set"][bracket_escape($name)];
@ -105,6 +109,7 @@ if (!$fields) {
input($field, $value, $function);
echo "\n";
}
echo "</table>\n";
}
?>

View file

@ -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"]) : "")

View file

@ -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

View file

@ -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'");

View file

@ -31,6 +31,7 @@ function connect_error() {
echo "<form action='' method='post'>\n";
echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
echo "<thead><tr><td>&nbsp;<th>" . lang('Database') . "<td>" . lang('Collation') . "<td>" . lang('Tables') . "</thead>\n";
foreach ($databases as $db) {
$root = h(ME) . "db=" . urlencode($db);
echo "<tr" . odd() . "><td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"]));
@ -39,6 +40,7 @@ function connect_error() {
echo "<td align='right'><a href='$root&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>?</a>";
echo "\n";
}
echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
echo "<p><input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /db/)") . ">\n";
@ -49,6 +51,7 @@ function connect_error() {
echo "<p>$refresh";
}
}
page_footer("db");
if ($databases) {
echo "<script type='text/javascript'>ajaxSetHtml('" . js_escape(ME) . "script=connect');</script>\n";

View file

@ -18,4 +18,5 @@ class TmpFile {
fpassthru($this->handler);
fclose($this->handler);
}
}

View file

@ -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"])) {

View file

@ -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 "<tr><td>" . html_select("indexes[$j][type]", array(-1 => "") + $index_types, $index["type"], ($j == count($row["indexes"]) ? "indexesAddRow(this);" : 1)) . "<td>";
ksort($index["columns"]);
$i = 1;
foreach ($index["columns"] as $key => $column) {
echo "<span>" . html_select("indexes[$j][columns][$i]", array(-1 => "") + $fields, $column, ($i == count($index["columns"]) ? "indexesAddColumn" : "indexesChangeColumn") . "(this, '" . js_escape($jush == "sql" ? "" : $_GET["indexes"] . "_") . "');");
echo "<input type='number' name='indexes[$j][lengths][$i]' class='size' value='" . h($index["lengths"][$key]) . "'> </span>"; //! hide for non-MySQL drivers, add ASC|DESC
$i++;
}
echo "<td><input name='indexes[$j][name]' value='" . h($index["name"]) . "' autocapitalize='off'>\n";
$j++;
}

View file

@ -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 "<form action=''><p>\n";
hidden_fields_get();
echo "<input type='hidden' name='db' value='" . h(DB) . "'>\n";
echo ($grant ? "" : "<input type='hidden' name='grant' value=''>\n");
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Username') . "<th>" . lang('Server') . "<th>&nbsp;</thead>\n";
while ($row = $result->fetch_assoc()) {
echo '<tr' . odd() . '><td>' . h($row["User"]) . "<td>" . h($row["Host"]) . '<td><a href="' . h(ME . 'user=' . urlencode($row["User"]) . '&host=' . urlencode($row["Host"])) . '">' . lang('Edit') . "</a>\n";
}
if (!$grant || DB != "") {
echo "<tr" . odd() . "><td><input name='user' autocapitalize='off'><td><input name='host' value='localhost' autocapitalize='off'><td><input type='submit' value='" . lang('Edit') . "'>\n";
}
echo "</table>\n";
echo "</form>\n";

View file

@ -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 "<thead><tr lang='en'>" . (support("kill") ? "<th>&nbsp;" : "");
foreach ($row as $key => $val) {
@ -28,6 +29,7 @@ foreach (process_list() as $i => $row) {
}
echo "</thead>\n";
}
echo "<tr" . odd() . ">" . (support("kill") ? "<td>" . checkbox("kill[]", $row["Id"], 0) : "");
foreach ($row as $key => $val) {
echo "<td>" . (

View file

@ -62,10 +62,12 @@ document.onmouseup = function (ev) {
foreach ($schema as $name => $table) {
echo "<div class='table' style='top: " . $table["pos"][0] . "em; left: " . $table["pos"][1] . "em;' onmousedown='schemaMousedown(this, event);'>";
echo '<a href="' . h(ME) . 'table=' . urlencode($name) . '"><b>' . h($name) . "</b></a>";
foreach ($table["fields"] as $field) {
$val = '<span' . type_class($field["type"]) . ' title="' . h($field["full_type"] . ($field["null"] ? " NULL" : '')) . '">' . h($field["field"]) . '</span>';
echo "<br>" . ($field["primary"] ? "<i>$val</i>" : $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</div>\n";
}
foreach ($schema as $name => $table) {
foreach ((array) $table["references"] as $target_name => $refs) {
foreach ($refs as $left => $ref) {

View file

@ -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 ? "<th>" . lang('Relations') : "") . "</thead>\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 "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" . 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) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>"));
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 "<td>";
}
$adminer->backwardKeysPrint($backward_keys, $rows[$n]);
echo "</tr>\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 "<p class='pages'>";
// 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 ? ' <a href="' . h(remove_from_uri("page") . "&page=" . ($page + 1)) . '" onclick="return !selectLoadMore(this, ' . (+$limit) . ', \'' . lang('Loading') . '\');">' . lang('Load more data') . '</a>' : '');
}
echo "<p>\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) {
</div></fieldset>
<?php
}
$format = $adminer->dumpFormat();
foreach ((array) $_GET["columns"] as $column) {
if ($column["fun"]) {
@ -477,6 +497,7 @@ if (!$columns) {
echo "</div></fieldset>\n";
}
}
if ($adminer->selectImportPrint()) {
print_fieldset("import", lang('Import'), !$rows);
echo "<input type='file' name='csv_file'> ";

View file

@ -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 = " <span class='time'>(" . format_time($start, $end) . ")</span>"
. (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : ""); // 1000 - maximum length of encoded URL in IE is 2083 characters
. (strlen($q) < 1000 ? " <a href='" . h(ME) . "sql=" . urlencode(trim($q)) . "'>" . lang('Edit') . "</a>" : "") // 1000 - maximum length of encoded URL in IE is 2083 characters
;
if ($connection->error) {
echo ($_POST["only_errors"] ? $print : "");
echo "<p class='error'>" . 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 "</form>\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 "<p class='message' title='" . h($connection->info) . "'>" . 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 "<p class='message'>" . lang('No commands to execute.') . "\n";
} elseif ($_POST["only_errors"]) {
@ -161,6 +176,7 @@ if (!$error && $_POST) {
echo "<p class='error'>" . lang('Error in query') . ": " . implode("", $errors) . "\n";
}
//! MS SQL - SET SHOWPLAN_ALL OFF
} else {
echo "<p class='error'>" . upload_error($query) . "\n";
}
@ -178,6 +194,7 @@ if ($_POST) {
$q = $history[$_GET["history"]][0];
}
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[]" multiple'

View file

@ -7,6 +7,7 @@ if (!$fields) {
$table_status = ($fields ? table_status($TABLE, true) : array());
page_header(($fields && is_view($table_status) ? lang('View') : lang('Table')) . ": " . h($TABLE), $error);
$adminer->selectLinks($table_status);
$comment = $table_status["Comment"];
if ($comment != "") {
@ -79,5 +80,6 @@ if ($fields) {
}
echo '<p><a href="' . h(ME) . 'trigger=' . urlencode($TABLE) . '">' . lang('Add trigger') . "</a>\n";
}
}
}

View file

@ -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 "</thead>\n";
foreach (array(
"" => "",
"Server Admin" => lang('Server'),
@ -168,6 +175,7 @@ foreach (array(
}
}
}
echo "</table>\n";
?>
<p>

View file

@ -9,6 +9,7 @@ if ($adminer->homepage()) {
}
echo "<table cellspacing='0' class='nowrap checkable' onclick='tableClick(event);'>\n";
echo '<thead><tr class="wrap"><td><input id="check-all" type="checkbox" onclick="formCheck(this, /^tables\[/);"><th>' . lang('Table') . '<td>' . lang('Rows') . "</thead>\n";
foreach (table_status() as $table => $row) {
$name = $adminer->tableName($row);
if (isset($row["Engine"]) && $name != "") {
@ -18,6 +19,7 @@ if ($adminer->homepage()) {
echo "<td align='right'><a href='" . h(ME . "edit=") . urlencode($table) . "'>" . ($row["Engine"] == "InnoDB" && $val ? "~ $val" : $val) . "</a>";
}
}
echo "</table>\n";
echo "<script type='text/javascript'>tableCheck();</script>\n";
echo "</form>\n";

View file

@ -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"])) {