adminerevo/adminer/include/connect.inc.php

101 lines
4.2 KiB
PHP
Raw Normal View History

<?php
function connect_error() {
2012-02-24 06:54:48 +00:00
global $adminer, $connection, $token, $error, $drivers;
if (DB != "") {
header("HTTP/1.1 404 Not Found");
page_header(lang('Database') . ": " . h(DB), lang('Invalid database.'), true);
} else {
if ($_POST["db"] && !$error) {
queries_redirect(substr(ME, 0, -1), lang('Databases have been dropped.'), drop_databases($_POST["db"]));
}
page_header(lang('Select database'), $error, false);
2013-07-06 17:31:21 +00:00
echo "<p class='links'>\n";
foreach (array(
2013-07-06 17:31:21 +00:00
'database' => lang('Create new database'),
'privileges' => lang('Privileges'),
'processlist' => lang('Process list'),
'variables' => lang('Variables'),
'status' => lang('Status'),
'replication' => lang('Replication'),
) as $key => $val) {
if (support($key)) {
echo "<a href='" . h(ME) . "$key='>$val</a>\n";
}
}
2014-03-01 18:33:17 +00:00
echo "<p>" . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
2012-02-24 06:54:48 +00:00
$databases = $adminer->databases();
if ($databases) {
2010-10-17 23:53:31 +00:00
$scheme = support("scheme");
$collations = collations();
echo "<form action='' method='post'>\n";
2012-10-04 07:42:56 +00:00
echo "<table cellspacing='0' class='checkable' onclick='tableClick(event);' ondblclick='tableClick(event, true);'>\n";
echo "<thead><tr>"
. (support("database") ? "<td>&nbsp;" : "")
2014-03-05 20:17:15 +00:00
. "<th>" . lang('Database') . " - <a href='" . h(ME) . "refresh=1'>" . lang('Refresh') . "</a>"
. "<td>" . lang('Collation')
. "<td>" . lang('Tables')
2015-11-08 20:15:45 +00:00
. "<td>" . lang('Size') . " - <a href='" . h(ME) . "dbsize=1' onclick=\"return !ajaxSetHtml('" . h(js_escape(ME)) . "script=connect');\">" . lang('Compute') . "</a>"
. "</thead>\n"
;
2013-05-02 01:28:04 +00:00
$databases = ($_GET["dbsize"] ? count_tables($databases) : array_flip($databases));
foreach ($databases as $db => $tables) {
$root = h(ME) . "db=" . urlencode($db);
$id = h("Db-" . $db);
echo "<tr" . odd() . ">" . (support("database") ? "<td>" . checkbox("db[]", $db, in_array($db, (array) $_POST["db"]), "", "", "", $id) : "");
echo "<th><a href='$root' id='$db'>" . h($db) . "</a>";
2013-07-06 17:31:21 +00:00
$collation = nbsp(db_collation($db, $collations));
echo "<td>" . (support("database") ? "<a href='$root" . ($scheme ? "&amp;ns=" : "") . "&amp;database=' title='" . lang('Alter database') . "'>$collation</a>" : $collation);
echo "<td align='right'><a href='$root&amp;schema=' id='tables-" . h($db) . "' title='" . lang('Database schema') . "'>" . ($_GET["dbsize"] ? $tables : "?") . "</a>";
echo "<td align='right' id='size-" . h($db) . "'>" . ($_GET["dbsize"] ? db_size($db) : "?");
echo "\n";
}
2013-05-02 01:28:04 +00:00
echo "</table>\n";
2013-07-11 23:57:16 +00:00
echo (support("database")
? "<fieldset><legend>" . lang('Selected') . " <span id='selected'></span></legend><div>\n"
. "<input type='hidden' name='all' value='' onclick=\"selectCount('selected', formChecked(this, /^db/));\">\n" // used by trCheck()
. "<input type='submit' name='drop' value='" . lang('Drop') . "'" . confirm() . ">\n"
2013-07-11 23:57:16 +00:00
. "</div></fieldset>\n"
: ""
);
2011-08-11 11:48:27 +00:00
echo "<script type='text/javascript'>tableCheck();</script>\n";
2011-03-08 12:43:05 +00:00
echo "<input type='hidden' name='token' value='$token'>\n";
echo "</form>\n";
}
}
2013-05-02 01:28:04 +00:00
page_footer("db");
}
if (isset($_GET["status"])) {
$_GET["variables"] = $_GET["status"];
}
2013-08-02 18:45:55 +00:00
if (isset($_GET["import"])) {
$_GET["sql"] = $_GET["import"];
}
if (!(DB != "" ? $connection->select_db(DB) : isset($_GET["sql"]) || isset($_GET["dump"]) || isset($_GET["database"]) || isset($_GET["processlist"]) || isset($_GET["privileges"]) || isset($_GET["user"]) || isset($_GET["replication"]) || isset($_GET["variables"]) || $_GET["script"] == "connect" || $_GET["script"] == "kill")) {
2012-08-20 00:12:19 +00:00
if (DB != "" || $_GET["refresh"]) {
restart_session();
set_session("dbs", null);
}
connect_error(); // separate function to catch SQLite error
exit;
}
2010-10-18 00:15:58 +00:00
if (support("scheme") && DB != "" && $_GET["ns"] !== "") {
if (!isset($_GET["ns"])) {
redirect(preg_replace('~ns=[^&]*&~', '', ME) . "ns=" . get_schema());
}
if (!set_schema($_GET["ns"])) {
header("HTTP/1.1 404 Not Found");
2010-10-18 00:15:58 +00:00
page_header(lang('Schema') . ": " . h($_GET["ns"]), lang('Invalid schema.'), true);
page_footer("ns");
exit;
}
}