adminerevo/adminer/db.inc.php

201 lines
9.6 KiB
PHP
Raw Normal View History

<?php
$tables_views = array_merge((array) $_POST["tables"], (array) $_POST["views"]);
if ($tables_views && !$error && !$_POST["search"]) {
$result = true;
$message = "";
2011-02-01 13:12:22 +00:00
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"]);
}
$message = lang('Tables have been truncated.');
} elseif ($_POST["move"]) {
2010-05-05 20:11:24 +00:00
$result = move_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
$message = lang('Tables have been moved.');
2011-02-01 13:12:22 +00:00
} elseif ($_POST["copy"]) {
$result = copy_tables((array) $_POST["tables"], (array) $_POST["views"], $_POST["target"]);
$message = lang('Tables have been copied.');
} elseif ($_POST["drop"]) {
if ($_POST["views"]) {
$result = drop_views($_POST["views"]);
}
if ($result && $_POST["tables"]) {
$result = drop_tables($_POST["tables"]);
}
$message = lang('Tables have been dropped.');
2012-03-01 09:14:55 +00:00
} elseif ($jush != "sql") {
$result = ($jush == "sqlite"
? queries("VACUUM")
: apply_queries("VACUUM" . ($_POST["optimize"] ? "" : " ANALYZE"), $_POST["tables"])
);
2012-02-29 18:49:17 +00:00
$message = lang('Tables have been optimized.');
} elseif (!$_POST["tables"]) {
$message = lang('No tables.');
} elseif ($result = queries(($_POST["optimize"] ? "OPTIMIZE" : ($_POST["check"] ? "CHECK" : ($_POST["repair"] ? "REPAIR" : "ANALYZE"))) . " TABLE " . implode(", ", array_map('idf_escape', $_POST["tables"])))) {
while ($row = $result->fetch_assoc()) {
$message .= "<b>" . h($row["Table"]) . "</b>: " . h($row["Msg_text"]) . "<br>";
}
}
queries_redirect(substr(ME, 0, -1), $message, $result);
}
page_header(($_GET["ns"] == "" ? lang('Database') . ": " . h(DB) : lang('Schema') . ": " . h($_GET["ns"])), $error, true);
2011-01-06 08:30:07 +00:00
if ($adminer->homepage()) {
if ($_GET["ns"] !== "") {
echo "<h3>" . lang('Tables and views') . "</h3>\n";
$tables_list = tables_list();
if (!$tables_list) {
echo "<p class='message'>" . lang('No tables.') . "\n";
} else {
echo "<form action='' method='post'>\n";
2012-12-05 21:11:36 +00:00
echo "<p>" . lang('Search data in tables') . ": <input type='search' name='query' value='" . h($_POST["query"]) . "'> <input type='submit' name='search' value='" . lang('Search') . "'>\n";
2011-01-06 08:30:07 +00:00
if ($_POST["search"] && $_POST["query"] != "") {
search_tables();
}
2012-10-04 07:42:56 +00:00
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');
echo '<td>' . lang('Collation');
echo '<td>' . lang('Data Length');
echo '<td>' . lang('Index Length');
echo '<td>' . lang('Data Free');
echo '<td>' . lang('Auto Increment');
echo '<td>' . lang('Rows');
echo (support("comment") ? '<td>' . lang('Comment') : '');
echo "</thead>\n";
2011-01-06 08:30:07 +00:00
foreach ($tables_list as $name => $type) {
2012-05-14 06:54:07 +00:00
$view = ($type !== null && !eregi("table", $type));
2011-01-06 08:30:07 +00:00
echo '<tr' . odd() . '><td>' . checkbox(($view ? "views[]" : "tables[]"), $name, in_array($name, $tables_views, true), "", "formUncheck('check-all');");
echo '<th><a href="' . h(ME) . 'table=' . urlencode($name) . '" title="' . lang('Show structure') . '">' . h($name) . '</a>';
2011-01-06 08:30:07 +00:00
if ($view) {
echo '<td colspan="6"><a href="' . h(ME) . "view=" . urlencode($name) . '" title="' . lang('Alter view') . '">' . lang('View') . '</a>';
echo '<td align="right"><a href="' . h(ME) . "select=" . urlencode($name) . '" title="' . lang('Select data') . '">?</a>';
2011-01-06 08:30:07 +00:00
} else {
foreach (array(
"Engine" => array(),
"Collation" => array(),
"Data_length" => array("create", lang('Alter table')),
"Index_length" => array("indexes", lang('Alter indexes')),
"Data_free" => array("edit", lang('New item')),
"Auto_increment" => array("auto_increment=1&create", lang('Alter table')),
"Rows" => array("select", lang('Select data')),
) as $key => $link) {
echo ($link ? "<td align='right'><a href='" . h(ME . "$link[0]=") . urlencode($name) . "' id='$key-" . h($name) . "' title='$link[1]'>?</a>" : "<td id='$key-" . h($name) . "'>&nbsp;");
2011-01-06 08:30:07 +00:00
}
}
2011-01-06 08:30:07 +00:00
echo (support("comment") ? "<td id='Comment-" . h($name) . "'>&nbsp;" : "");
}
2011-01-06 08:30:07 +00:00
echo "<tr><td>&nbsp;<th>" . lang('%d in total', count($tables_list));
echo "<td>" . nbsp($jush == "sql" ? $connection->result("SELECT @@storage_engine") : "");
2011-01-06 08:30:07 +00:00
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;";
}
2011-01-06 08:30:07 +00:00
echo "</table>\n";
2011-08-11 11:48:27 +00:00
echo "<script type='text/javascript'>tableCheck();</script>\n";
2011-01-06 08:30:07 +00:00
if (!information_schema(DB)) {
2012-03-01 09:14:55 +00:00
echo "<p>" . (ereg('^(sql|sqlite|pgsql)$', $jush)
2012-02-29 18:49:17 +00:00
? ($jush != "sqlite" ? "<input type='submit' value='" . lang('Analyze') . "'> " : "")
. "<input type='submit' name='optimize' value='" . lang('Optimize') . "'> " : ""
) . ($jush == "sql" ? "<input type='submit' name='check' value='" . lang('Check') . "'> <input type='submit' name='repair' value='" . lang('Repair') . "'> " : "") . "<input type='submit' name='truncate' value='" . lang('Truncate') . "'" . confirm("formChecked(this, /tables/)") . "> <input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm("formChecked(this, /tables|views/)") . ">\n";
2012-02-24 06:54:48 +00:00
$databases = (support("scheme") ? schemas() : $adminer->databases());
2011-01-06 08:30:07 +00:00
if (count($databases) != 1 && $jush != "sqlite") {
$db = (isset($_POST["target"]) ? $_POST["target"] : (support("scheme") ? $_GET["ns"] : DB));
2011-02-01 09:16:31 +00:00
echo "<p>" . lang('Move to other database') . ": ";
2013-01-31 05:35:51 +00:00
echo ($databases ? html_select("target", $databases, $db) : '<input name="target" value="' . h($db) . '" autocapitalize="off">');
echo " <input type='submit' name='move' value='" . lang('Move') . "'>";
echo (support("copy") ? " <input type='submit' name='copy' value='" . lang('Copy') . "'>" : "");
2011-02-01 13:12:22 +00:00
echo "\n";
2011-01-06 08:30:07 +00:00
}
2011-03-08 12:43:05 +00:00
echo "<input type='hidden' name='token' value='$token'>\n";
2011-01-06 08:30:07 +00:00
}
echo "</form>\n";
}
echo '<p><a href="' . h(ME) . 'create=">' . lang('Create table') . "</a>\n";
if (support("view")) {
echo '<a href="' . h(ME) . 'view=">' . lang('Create view') . "</a>\n";
}
2011-01-06 08:30:07 +00:00
if (support("routine")) {
echo "<h3>" . lang('Routines') . "</h3>\n";
$routines = routines();
if ($routines) {
echo "<table cellspacing='0'>\n";
echo '<thead><tr><th>' . lang('Name') . '<td>' . lang('Type') . '<td>' . lang('Return type') . "<td>&nbsp;</thead>\n";
odd('');
foreach ($routines as $row) {
echo '<tr' . odd() . '>';
2011-06-04 02:19:14 +00:00
echo '<th><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'callf=' : 'call=') . urlencode($row["ROUTINE_NAME"]) . '">' . h($row["ROUTINE_NAME"]) . '</a>';
2011-01-06 08:30:07 +00:00
echo '<td>' . h($row["ROUTINE_TYPE"]);
echo '<td>' . h($row["DTD_IDENTIFIER"]);
2011-06-04 02:19:14 +00:00
echo '<td><a href="' . h(ME) . ($row["ROUTINE_TYPE"] != "PROCEDURE" ? 'function=' : 'procedure=') . urlencode($row["ROUTINE_NAME"]) . '">' . lang('Alter') . "</a>";
2011-01-06 08:30:07 +00:00
}
echo "</table>\n";
}
2011-06-04 02:19:14 +00:00
echo '<p>' . (support("procedure") ? '<a href="' . h(ME) . 'procedure=">' . lang('Create procedure') . '</a> ' : '') . '<a href="' . h(ME) . 'function=">' . lang('Create function') . "</a>\n";
}
2011-01-06 08:30:07 +00:00
if (support("sequence")) {
echo "<h3>" . lang('Sequences') . "</h3>\n";
$sequences = get_vals("SELECT sequence_name FROM information_schema.sequences WHERE sequence_schema = current_schema()");
if ($sequences) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Name') . "</thead>\n";
odd('');
foreach ($sequences as $val) {
echo "<tr" . odd() . "><th><a href='" . h(ME) . "sequence=" . urlencode($val) . "'>" . h($val) . "</a>\n";
}
echo "</table>\n";
2010-05-05 21:01:57 +00:00
}
2011-01-06 08:30:07 +00:00
echo "<p><a href='" . h(ME) . "sequence='>" . lang('Create sequence') . "</a>\n";
2010-05-05 21:01:57 +00:00
}
2011-01-06 08:30:07 +00:00
if (support("type")) {
echo "<h3>" . lang('User types') . "</h3>\n";
$types = types();
if ($types) {
echo "<table cellspacing='0'>\n";
echo "<thead><tr><th>" . lang('Name') . "</thead>\n";
odd('');
foreach ($types as $val) {
echo "<tr" . odd() . "><th><a href='" . h(ME) . "type=" . urlencode($val) . "'>" . h($val) . "</a>\n";
}
echo "</table>\n";
2010-05-21 14:07:22 +00:00
}
2011-01-06 08:30:07 +00:00
echo "<p><a href='" . h(ME) . "type='>" . lang('Create type') . "</a>\n";
2010-05-21 14:07:22 +00:00
}
2011-01-06 08:30:07 +00:00
if (support("event")) {
echo "<h3>" . lang('Events') . "</h3>\n";
$rows = get_rows("SHOW EVENTS");
if ($rows) {
echo "<table cellspacing='0'>\n";
2013-01-31 07:46:55 +00:00
echo "<thead><tr><th>" . lang('Name') . "<td>" . lang('Schedule') . "<td>" . lang('Start') . "<td>" . lang('End') . "<td></thead>\n";
2011-01-06 08:30:07 +00:00
foreach ($rows as $row) {
echo "<tr>";
2013-01-31 07:46:55 +00:00
echo "<th>" . h($row["Name"]);
2011-01-06 08:30:07 +00:00
echo "<td>" . ($row["Execute at"] ? lang('At given time') . "<td>" . $row["Execute at"] : lang('Every') . " " . $row["Interval value"] . " " . $row["Interval field"] . "<td>$row[Starts]");
echo "<td>$row[Ends]";
2013-01-31 07:46:55 +00:00
echo '<td><a href="' . h(ME) . 'event=' . urlencode($row["Name"]) . '">' . lang('Alter') . '</a>';
2011-01-06 08:30:07 +00:00
}
echo "</table>\n";
$event_scheduler = $connection->result("SELECT @@event_scheduler");
if ($event_scheduler && $event_scheduler != "ON") {
echo "<p class='error'><code class='jush-sqlset'>event_scheduler</code>: " . h($event_scheduler) . "\n";
}
}
2011-01-06 08:30:07 +00:00
echo '<p><a href="' . h(ME) . 'event=">' . lang('Create event') . "</a>\n";
}
if ($tables_list) {
echo "<script type='text/javascript'>ajaxSetHtml('" . js_escape(ME) . "script=db');</script>\n";
}
2010-10-18 00:15:13 +00:00
}
}