Adminer class
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@913 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
parent
90a6bd8d4b
commit
c64c4fd14d
|
@ -3,7 +3,7 @@ $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_
|
||||||
$update = ($where && !$_POST["clone"]);
|
$update = ($where && !$_POST["clone"]);
|
||||||
$fields = fields($_GET["edit"]);
|
$fields = fields($_GET["edit"]);
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
if ((isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) || !strlen(adminer_field_name($field))) {
|
if ((isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) || !strlen($adminer->fieldName($field))) {
|
||||||
unset($fields[$name]);
|
unset($fields[$name]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ if ($_POST && !$error && !isset($_GET["select"])) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$table_name = adminer_table_name(table_status($_GET["edit"]));
|
$table_name = $adminer->tableName(table_status($_GET["edit"]));
|
||||||
page_header(
|
page_header(
|
||||||
(isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))),
|
(isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))),
|
||||||
$error,
|
$error,
|
||||||
|
@ -69,7 +69,7 @@ if ($fields) {
|
||||||
unset($create);
|
unset($create);
|
||||||
echo "<table cellspacing='0'>\n";
|
echo "<table cellspacing='0'>\n";
|
||||||
foreach ($fields as $name => $field) {
|
foreach ($fields as $name => $field) {
|
||||||
echo "<tr><th>" . adminer_field_name($field);
|
echo "<tr><th>" . $adminer->fieldName($field);
|
||||||
$value = (isset($row)
|
$value = (isset($row)
|
||||||
? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
|
? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
|
||||||
: ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $field["default"]))
|
: ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $field["default"]))
|
||||||
|
|
|
@ -1,32 +1,33 @@
|
||||||
<?php
|
<?php
|
||||||
|
class Adminer {
|
||||||
|
|
||||||
/** Name in title and navigation
|
/** Name in title and navigation
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_name() {
|
function name() {
|
||||||
return call_adminer('name', lang('Adminer'));
|
return lang('Adminer');
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Connection parameters
|
/** Connection parameters
|
||||||
* @return array ($server, $username, $password)
|
* @return array ($server, $username, $password)
|
||||||
*/
|
*/
|
||||||
function adminer_credentials() {
|
function credentials() {
|
||||||
return call_adminer('credentials', array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]));
|
return array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Identifier of selected database
|
/** Identifier of selected database
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_database() {
|
function database() {
|
||||||
// should be used everywhere instead of $_GET["db"]
|
// should be used everywhere instead of $_GET["db"]
|
||||||
return call_adminer('database', $_GET["db"]);
|
return $_GET["db"];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Print login form
|
/** Print login form
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool whether to display default login form
|
* @return null
|
||||||
*/
|
*/
|
||||||
function adminer_login_form($username) {
|
function loginForm($username) {
|
||||||
if (call_adminer('login_form', true, $username)) {
|
|
||||||
?>
|
?>
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
<tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>">
|
<tr><th><?php echo lang('Server'); ?><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>">
|
||||||
|
@ -35,66 +36,65 @@ function adminer_login_form($username) {
|
||||||
</table>
|
</table>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Authorize the user
|
/** Authorize the user
|
||||||
* @param string
|
* @param string
|
||||||
* @param string
|
* @param string
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
function adminer_login($login, $password) {
|
function login($login, $password) {
|
||||||
return call_adminer('login', true, $login, $password);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Table caption used in navigation and headings
|
/** Table caption used in navigation and headings
|
||||||
* @param array result of SHOW TABLE STATUS
|
* @param array result of SHOW TABLE STATUS
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_table_name($table_status) {
|
function tableName($tableStatus) {
|
||||||
return call_adminer('table_name', htmlspecialchars($table_status["Name"]), $table_status);
|
return htmlspecialchars($tableStatus["Name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Field caption used in select and edit
|
/** Field caption used in select and edit
|
||||||
* @param array single field returned from fields()
|
* @param array single field returned from fields()
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_field_name($field) {
|
function fieldName($field) {
|
||||||
return call_adminer('field_name', '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>', $field);
|
return '<span title="' . htmlspecialchars($field["full_type"]) . '">' . htmlspecialchars($field["field"]) . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Links after select heading
|
/** Links after select heading
|
||||||
* @param array result of SHOW TABLE STATUS
|
* @param array result of SHOW TABLE STATUS
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_select_links($table_status) {
|
function selectLinks($tableStatus) {
|
||||||
global $SELF;
|
global $SELF;
|
||||||
return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
|
return '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Find backward keys for table
|
/** Find backward keys for table
|
||||||
* @param string
|
* @param string
|
||||||
* @return array $return[$target_table][$key_name][$target_column] = $source_column;
|
* @return array $return[$target_table][$key_name][$target_column] = $source_column;
|
||||||
*/
|
*/
|
||||||
function adminer_backward_keys($table) {
|
function backwardKeys($table) {
|
||||||
return call_adminer('backward_keys', array(), $table);
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Query printed in select before execution
|
/** Query printed in select before execution
|
||||||
* @param string query to be executed
|
* @param string query to be executed
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_select_query($query) {
|
function selectQuery($query) {
|
||||||
global $SELF;
|
global $SELF;
|
||||||
// it would be nice if $query can be passed by reference and printed value would be returned but call_user() doesn't allow reference parameters
|
// it would be nice if $query can be passed by reference and printed value would be returned but call_user() doesn't allow reference parameters
|
||||||
return call_adminer('select_query', "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n", $query);
|
return "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Description of a row in a table
|
/** Description of a row in a table
|
||||||
* @param string
|
* @param string
|
||||||
* @return string SQL expression, empty string for no description
|
* @return string SQL expression, empty string for no description
|
||||||
*/
|
*/
|
||||||
function adminer_row_description($table) {
|
function rowDescription($table) {
|
||||||
return call_adminer('row_description', "", $table);
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get descriptions of selected data
|
/** Get descriptions of selected data
|
||||||
|
@ -102,8 +102,8 @@ function adminer_row_description($table) {
|
||||||
* @param array
|
* @param array
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function adminer_row_descriptions($rows, $foreign_keys) {
|
function rowDescriptions($rows, $foreignKeys) {
|
||||||
return call_adminer('row_descriptions', $rows, $rows, $foreign_keys);
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Value printed in select table
|
/** Value printed in select table
|
||||||
|
@ -112,46 +112,45 @@ function adminer_row_descriptions($rows, $foreign_keys) {
|
||||||
* @param array single field returned from fields()
|
* @param array single field returned from fields()
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_select_val($val, $link, $field) {
|
function selectVal($val, $link, $field) {
|
||||||
$return = ($field["type"] == "char" ? "<code>$val</code>" : $val);
|
$return = ($field["type"] == "char" ? "<code>$val</code>" : $val);
|
||||||
if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
|
if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
|
||||||
$return = lang('%d byte(s)', strlen($val));
|
$return = lang('%d byte(s)', strlen($val));
|
||||||
}
|
}
|
||||||
return call_adminer('select_val', ($link ? "<a href=\"$link\">$return</a>" : $return), $val, $link);
|
return ($link ? "<a href=\"$link\">$return</a>" : $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Print extra text in the end of a select form
|
/** Print extra text in the end of a select form
|
||||||
* @param array fields holding e-mails
|
* @param array fields holding e-mails
|
||||||
* @return bool whether to print default extra
|
* @return null
|
||||||
*/
|
*/
|
||||||
function adminer_select_extra_display($email_fields) {
|
function selectExtraDisplay($emailFields) {
|
||||||
call_adminer('select_extra_display', false, $email_fields);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process extras in select form
|
/** Process extras in select form
|
||||||
* @param array AND conditions
|
* @param array AND conditions
|
||||||
* @return bool true if processed, false to process other parts of form
|
* @return bool true if processed, false to process other parts of form
|
||||||
*/
|
*/
|
||||||
function adminer_select_extra_process($where) {
|
function selectExtraProcess($where) {
|
||||||
return call_adminer('select_extra_process', false, $where);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Query printed after execution in the message
|
/** Query printed after execution in the message
|
||||||
* @param string executed query
|
* @param string executed query
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function adminer_message_query($query) {
|
function messageQuery($query) {
|
||||||
global $SELF;
|
global $SELF;
|
||||||
$id = "sql-" . count($_SESSION["messages"]);
|
$id = "sql-" . count($_SESSION["messages"]);
|
||||||
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
|
$_SESSION["history"][$_GET["server"]][$_GET["db"]][] = $query;
|
||||||
return call_adminer('message_query', " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>', $query);
|
return " <a href='#$id' onclick=\"return !toggle('$id');\">" . lang('SQL command') . "</a><div id='$id' class='hidden'><pre class='jush-sql'>" . htmlspecialchars($query) . '</pre><a href="' . htmlspecialchars($SELF . 'sql=&history=' . (count($_SESSION["history"][$_GET["server"]][$_GET["db"]]) - 1)) . '">' . lang('Edit') . '</a></div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Functions displayed in edit form
|
/** Functions displayed in edit form
|
||||||
* @param array single field from fields()
|
* @param array single field from fields()
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function adminer_edit_functions($field) {
|
function editFunctions($field) {
|
||||||
$return = array("");
|
$return = array("");
|
||||||
if (!isset($_GET["default"])) {
|
if (!isset($_GET["default"])) {
|
||||||
if (ereg('char|date|time', $field["type"])) {
|
if (ereg('char|date|time', $field["type"])) {
|
||||||
|
@ -175,7 +174,7 @@ function adminer_edit_functions($field) {
|
||||||
if ($field["null"] || isset($_GET["default"])) {
|
if ($field["null"] || isset($_GET["default"])) {
|
||||||
array_unshift($return, "NULL");
|
array_unshift($return, "NULL");
|
||||||
}
|
}
|
||||||
return call_adminer('edit_functions', (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $return, $field);
|
return (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get options to display edit field
|
/** Get options to display edit field
|
||||||
|
@ -183,8 +182,8 @@ function adminer_edit_functions($field) {
|
||||||
* @param array single field from fields()
|
* @param array single field from fields()
|
||||||
* @return array options for <select> or empty to display <input>
|
* @return array options for <select> or empty to display <input>
|
||||||
*/
|
*/
|
||||||
function adminer_edit_input($table, $field) {
|
function editInput($table, $field) {
|
||||||
return call_adminer('edit_input', false, $table, $field);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process sent input
|
/** Process sent input
|
||||||
|
@ -192,7 +191,7 @@ function adminer_edit_input($table, $field) {
|
||||||
* @param array single field from fields()
|
* @param array single field from fields()
|
||||||
* @return string expression to use in a query
|
* @return string expression to use in a query
|
||||||
*/
|
*/
|
||||||
function adminer_process_input($name, $field) {
|
function processInput($name, $field) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
$idf = bracket_escape($name);
|
$idf = bracket_escape($name);
|
||||||
$function = $_POST["function"][$idf];
|
$function = $_POST["function"][$idf];
|
||||||
|
@ -211,16 +210,16 @@ function adminer_process_input($name, $field) {
|
||||||
} elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
|
} elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
|
||||||
$return = $value;
|
$return = $value;
|
||||||
}
|
}
|
||||||
return call_adminer('process_input', $return, $name, $field);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Prints navigation after Adminer title
|
/** Prints navigation after Adminer title
|
||||||
* @param string can be "auth" if there is no database connection or "db" if there is no database selected
|
* @param string can be "auth" if there is no database connection or "db" if there is no database selected
|
||||||
* @return bool true if default navigation should be printed
|
* @return null
|
||||||
*/
|
*/
|
||||||
function adminer_navigation($missing) {
|
function navigation($missing) {
|
||||||
global $SELF, $dbh;
|
global $SELF, $dbh;
|
||||||
if (call_adminer('navigation', true, $missing) && $missing != "auth") {
|
if ($missing != "auth") {
|
||||||
ob_flush();
|
ob_flush();
|
||||||
flush();
|
flush();
|
||||||
$databases = get_databases();
|
$databases = get_databases();
|
||||||
|
@ -255,7 +254,7 @@ function adminer_navigation($missing) {
|
||||||
echo "<p>\n";
|
echo "<p>\n";
|
||||||
while ($row = $result->fetch_row()) {
|
while ($row = $result->fetch_row()) {
|
||||||
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> ';
|
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> ';
|
||||||
echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row[0]) . '">' . adminer_table_name(array("Name" => $row[0])) . "</a><br>\n"; //! Adminer::table_name may work with full table status
|
echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row[0]) . '">' . $this->tableName(array("Name" => $row[0])) . "</a><br>\n"; //! Adminer::table_name may work with full table status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
|
@ -263,3 +262,5 @@ function adminer_navigation($missing) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -37,12 +37,12 @@ if (isset($_POST["server"])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function auth_error($exception = null) {
|
function auth_error($exception = null) {
|
||||||
global $ignore, $dbh;
|
global $ignore, $dbh, $adminer;
|
||||||
$username = $_SESSION["usernames"][$_GET["server"]];
|
$username = $_SESSION["usernames"][$_GET["server"]];
|
||||||
unset($_SESSION["usernames"][$_GET["server"]]);
|
unset($_SESSION["usernames"][$_GET["server"]]);
|
||||||
page_header(lang('Login'), (isset($username) ? htmlspecialchars($exception ? $exception->getMessage() : (is_string($dbh) ? $dbh : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Sessions must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
|
page_header(lang('Login'), (isset($username) ? htmlspecialchars($exception ? $exception->getMessage() : (is_string($dbh) ? $dbh : lang('Invalid credentials.'))) : (isset($_POST["server"]) ? lang('Sessions must be enabled.') : ($_POST ? lang('Session expired, please login again.') : ""))), null);
|
||||||
echo "<form action='' method='post'>\n";
|
echo "<form action='' method='post'>\n";
|
||||||
adminer_login_form($login);
|
$adminer->loginForm($login);
|
||||||
echo "<p>\n";
|
echo "<p>\n";
|
||||||
hidden_fields($_POST, $ignore); // expired session
|
hidden_fields($_POST, $ignore); // expired session
|
||||||
foreach ($_FILES as $key => $val) {
|
foreach ($_FILES as $key => $val) {
|
||||||
|
@ -57,7 +57,7 @@ if (!isset($username)) {
|
||||||
$username = $_GET["username"]; // default username can be passed in URL
|
$username = $_GET["username"]; // default username can be passed in URL
|
||||||
}
|
}
|
||||||
$dbh = (isset($username) ? connect() : '');
|
$dbh = (isset($username) ? connect() : '');
|
||||||
if (is_string($dbh) || !adminer_login($username, $_SESSION["passwords"][$_GET["server"]])) {
|
if (is_string($dbh) || !$adminer->login($username, $_SESSION["passwords"][$_GET["server"]])) {
|
||||||
auth_error();
|
auth_error();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,7 @@ include "../adminer/include/functions.inc.php";
|
||||||
include "../adminer/include/lang.inc.php";
|
include "../adminer/include/lang.inc.php";
|
||||||
include "../adminer/lang/$LANG.inc.php";
|
include "../adminer/lang/$LANG.inc.php";
|
||||||
include "./include/adminer.inc.php";
|
include "./include/adminer.inc.php";
|
||||||
|
$adminer = (function_exists('adminer_object') ? adminer_object() : new Adminer);
|
||||||
include "../adminer/include/design.inc.php";
|
include "../adminer/include/design.inc.php";
|
||||||
include "../adminer/include/pdo.inc.php";
|
include "../adminer/include/pdo.inc.php";
|
||||||
include "../adminer/include/mysql.inc.php";
|
include "../adminer/include/mysql.inc.php";
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
global $SELF, $LANG, $VERSION;
|
global $SELF, $LANG, $VERSION, $adminer;
|
||||||
header("Content-Type: text/html; charset=utf-8");
|
header("Content-Type: text/html; charset=utf-8");
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
|
||||||
|
@ -8,7 +8,7 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
<meta http-equiv="Content-Script-Type" content="text/javascript">
|
||||||
<meta name="robots" content="noindex">
|
<meta name="robots" content="noindex">
|
||||||
<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . (strlen($_GET["server"]) && $_GET["server"] != "localhost" ? htmlspecialchars("- $_GET[server]") : "") . " - " . adminer_name(); ?></title>
|
<title><?php echo $title . (strlen($title2) ? ": " . htmlspecialchars($title2) : "") . (strlen($_GET["server"]) && $_GET["server"] != "localhost" ? htmlspecialchars("- $_GET[server]") : "") . " - " . $adminer->name(); ?></title>
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="../adminer/favicon.ico">
|
<link rel="shortcut icon" type="image/x-icon" href="../adminer/favicon.ico">
|
||||||
<link rel="stylesheet" type="text/css" href="../adminer/default.css<?php // Ondrej Valka, http://valka.info ?>">
|
<link rel="stylesheet" type="text/css" href="../adminer/default.css<?php // Ondrej Valka, http://valka.info ?>">
|
||||||
<?php if (file_exists("adminer.css")) { ?>
|
<?php if (file_exists("adminer.css")) { ?>
|
||||||
|
@ -56,16 +56,16 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
|
||||||
}
|
}
|
||||||
|
|
||||||
function page_footer($missing = false) {
|
function page_footer($missing = false) {
|
||||||
global $VERSION;
|
global $VERSION, $adminer;
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php switch_lang(); ?>
|
<?php switch_lang(); ?>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<h1><a href="http://www.adminer.org/" class="h1"><?php echo adminer_name(); ?></a> <?php echo $VERSION; ?>
|
<h1><a href="http://www.adminer.org/" class="h1"><?php echo $adminer->name(); ?></a> <?php echo $VERSION; ?>
|
||||||
<a href='http://www.adminer.org/#download' id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? htmlspecialchars($_COOKIE["adminer_version"]) : ""); ?></a>
|
<a href='http://www.adminer.org/#download' id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? htmlspecialchars($_COOKIE["adminer_version"]) : ""); ?></a>
|
||||||
</h1>
|
</h1>
|
||||||
<?php adminer_navigation($missing); ?>
|
<?php $adminer->navigation($missing); ?>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
function get_dbh() {
|
||||||
|
// can be used in customization, $dbh is minified
|
||||||
|
global $dbh;
|
||||||
|
return $dbh;
|
||||||
|
}
|
||||||
|
|
||||||
function idf_escape($idf) {
|
function idf_escape($idf) {
|
||||||
return "`" . str_replace("`", "``", $idf) . "`";
|
return "`" . str_replace("`", "``", $idf) . "`";
|
||||||
}
|
}
|
||||||
|
@ -103,10 +109,10 @@ function redirect($location, $message = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
|
function query_redirect($query, $location, $message, $redirect = true, $execute = true, $failed = false) {
|
||||||
global $dbh, $error, $SELF;
|
global $dbh, $error, $SELF, $adminer;
|
||||||
$sql = "";
|
$sql = "";
|
||||||
if ($query) {
|
if ($query) {
|
||||||
$sql = adminer_message_query($query);
|
$sql = $adminer->messageQuery($query);
|
||||||
}
|
}
|
||||||
if ($execute) {
|
if ($execute) {
|
||||||
$failed = !$dbh->query($query);
|
$failed = !$dbh->query($query);
|
||||||
|
@ -276,7 +282,7 @@ function column_foreign_keys($table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function input($field, $value, $function) {
|
function input($field, $value, $function) {
|
||||||
global $types;
|
global $types, $adminer;
|
||||||
$name = htmlspecialchars(bracket_escape($field["field"]));
|
$name = htmlspecialchars(bracket_escape($field["field"]));
|
||||||
echo "<td class='function'>";
|
echo "<td class='function'>";
|
||||||
if ($field["type"] == "enum") {
|
if ($field["type"] == "enum") {
|
||||||
|
@ -294,11 +300,11 @@ function input($field, $value, $function) {
|
||||||
echo ' <label><input type="radio" name="fields[' . $name . ']" value="' . (isset($_GET["default"]) ? (strlen($val) ? htmlspecialchars($val) : " ") : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . '>' . htmlspecialchars($val) . '</label>';
|
echo ' <label><input type="radio" name="fields[' . $name . ']" value="' . (isset($_GET["default"]) ? (strlen($val) ? htmlspecialchars($val) : " ") : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . '>' . htmlspecialchars($val) . '</label>';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$functions = adminer_edit_functions($field);
|
$functions = $adminer->editFunctions($field);
|
||||||
$first = array_search("", $functions);
|
$first = array_search("", $functions);
|
||||||
$onchange = ($first ? ' onchange="var f = this.form[\'function[' . addcslashes($name, "\r\n'\\") . ']\']; if (' . $first . ' > f.selectedIndex) f.selectedIndex = ' . $first . ';"' : '');
|
$onchange = ($first ? ' onchange="var f = this.form[\'function[' . addcslashes($name, "\r\n'\\") . ']\']; if (' . $first . ' > f.selectedIndex) f.selectedIndex = ' . $first . ';"' : '');
|
||||||
echo (count($functions) > 1 ? '<select name="function[' . $name . ']">' . optionlist($functions, $function) . '</select>' : " ") . '<td>';
|
echo (count($functions) > 1 ? '<select name="function[' . $name . ']">' . optionlist($functions, $function) . '</select>' : " ") . '<td>';
|
||||||
$options = adminer_edit_input($_GET["edit"], $field); // usage in call is without a table
|
$options = $adminer->editInput($_GET["edit"], $field); // usage in call is without a table
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
echo '<select name="fields[' . $name . ']"' . $onchange . '>' . optionlist(($options ? $options : array("" => "")), $value, true) . '</select>';
|
echo '<select name="fields[' . $name . ']"' . $onchange . '>' . optionlist(($options ? $options : array("" => "")), $value, true) . '</select>';
|
||||||
} elseif ($field["type"] == "set") { //! 64 bits
|
} elseif ($field["type"] == "set") { //! 64 bits
|
||||||
|
@ -321,7 +327,7 @@ function input($field, $value, $function) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function process_input($name, $field) {
|
function process_input($name, $field) {
|
||||||
global $dbh;
|
global $dbh, $adminer;
|
||||||
$idf = bracket_escape($name);
|
$idf = bracket_escape($name);
|
||||||
$function = $_POST["function"][$idf];
|
$function = $_POST["function"][$idf];
|
||||||
$value = $_POST["fields"][$idf];
|
$value = $_POST["fields"][$idf];
|
||||||
|
@ -340,7 +346,7 @@ function process_input($name, $field) {
|
||||||
}
|
}
|
||||||
return "_binary" . $dbh->quote($file);
|
return "_binary" . $dbh->quote($file);
|
||||||
} else {
|
} else {
|
||||||
return adminer_process_input($name, $field);
|
return $adminer->processInput($name, $field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,11 +369,3 @@ function email_header($header) {
|
||||||
// iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
|
// iconv_mime_encode requires PHP 5, imap_8bit requires IMAP extension
|
||||||
return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
|
return "=?UTF-8?B?" . base64_encode($header) . "?="; //! split long lines
|
||||||
}
|
}
|
||||||
|
|
||||||
function call_adminer($method, $default, $arg1 = null, $arg2 = null, $arg3 = null) {
|
|
||||||
if (method_exists('Adminer', $method)) { // user defined class
|
|
||||||
// can use func_get_args() and call_user_func_array()
|
|
||||||
return Adminer::$method($arg1, $arg2, $arg3);
|
|
||||||
}
|
|
||||||
return $default; //! $default is evaluated even if not neccessary
|
|
||||||
}
|
|
||||||
|
|
|
@ -141,8 +141,9 @@ if (extension_loaded("mysqli")) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function connect() {
|
function connect() {
|
||||||
|
global $adminer;
|
||||||
$dbh = new Min_DB;
|
$dbh = new Min_DB;
|
||||||
$credentials = adminer_credentials();
|
$credentials = $adminer->credentials();
|
||||||
if ($dbh->connect($credentials[0], $credentials[1], $credentials[2])) {
|
if ($dbh->connect($credentials[0], $credentials[1], $credentials[2])) {
|
||||||
$dbh->query("SET SQL_QUOTE_SHOW_CREATE=1");
|
$dbh->query("SET SQL_QUOTE_SHOW_CREATE=1");
|
||||||
$dbh->query("SET NAMES utf8");
|
$dbh->query("SET NAMES utf8");
|
||||||
|
|
|
@ -18,7 +18,7 @@ $rights = array(); // privilege => 0
|
||||||
$columns = array(); // selectable columns
|
$columns = array(); // selectable columns
|
||||||
unset($text_length);
|
unset($text_length);
|
||||||
foreach ($fields as $key => $field) {
|
foreach ($fields as $key => $field) {
|
||||||
$name = adminer_field_name($field);
|
$name = $adminer->fieldName($field);
|
||||||
if (isset($field["privileges"]["select"]) && strlen($name)) {
|
if (isset($field["privileges"]["select"]) && strlen($name)) {
|
||||||
$columns[$key] = html_entity_decode(strip_tags($name));
|
$columns[$key] = html_entity_decode(strip_tags($name));
|
||||||
if (ereg('text|blob', $field["type"])) {
|
if (ereg('text|blob', $field["type"])) {
|
||||||
|
@ -109,7 +109,7 @@ if ($_POST && !$error) {
|
||||||
}
|
}
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
if (!adminer_select_extra_process($where)) {
|
if (!$adminer->selectExtraProcess($where)) {
|
||||||
if (!$_POST["import"]) { // edit
|
if (!$_POST["import"]) { // edit
|
||||||
$result = true;
|
$result = true;
|
||||||
$affected = 0;
|
$affected = 0;
|
||||||
|
@ -169,14 +169,14 @@ if ($_POST && !$error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
page_header(lang('Select') . ": " . adminer_table_name($table_status), $error);
|
page_header(lang('Select') . ": " . $adminer->tableName($table_status), $error);
|
||||||
|
|
||||||
echo "<p>";
|
echo "<p>";
|
||||||
if (isset($rights["insert"])) {
|
if (isset($rights["insert"])) {
|
||||||
//! pass search values forth and back
|
//! pass search values forth and back
|
||||||
echo '<a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . '</a> ';
|
echo '<a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . '</a> ';
|
||||||
}
|
}
|
||||||
echo adminer_select_links($table_status);
|
echo $adminer->selectLinks($table_status);
|
||||||
|
|
||||||
if (!$columns) {
|
if (!$columns) {
|
||||||
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".\n";
|
echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".\n";
|
||||||
|
@ -253,7 +253,7 @@ if (!$columns) {
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
|
|
||||||
$query = "SELECT " . (intval($limit) && count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
|
$query = "SELECT " . (intval($limit) && count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
|
||||||
echo adminer_select_query($query);
|
echo $adminer->selectQuery($query);
|
||||||
|
|
||||||
$result = $dbh->query($query);
|
$result = $dbh->query($query);
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
@ -276,12 +276,12 @@ if (!$columns) {
|
||||||
);
|
);
|
||||||
|
|
||||||
$foreign_keys = column_foreign_keys($_GET["select"]);
|
$foreign_keys = column_foreign_keys($_GET["select"]);
|
||||||
$descriptions = adminer_row_descriptions($rows, $foreign_keys);
|
$descriptions = $adminer->rowDescriptions($rows, $foreign_keys);
|
||||||
|
|
||||||
$backward_keys = adminer_backward_keys($_GET["select"]);
|
$backward_keys = $adminer->backwardKeys($_GET["select"]);
|
||||||
$table_names = array_keys($backward_keys);
|
$table_names = array_keys($backward_keys);
|
||||||
if ($table_names) {
|
if ($table_names) {
|
||||||
$table_names = array_combine($table_names, array_map('adminer_table_name', array_map('table_status', $table_names)));
|
$table_names = array_combine($table_names, array_map(array($adminer, 'tableName'), array_map('table_status', $table_names)));
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "<table cellspacing='0' class='nowrap'>\n";
|
echo "<table cellspacing='0' class='nowrap'>\n";
|
||||||
|
@ -291,7 +291,7 @@ if (!$columns) {
|
||||||
foreach ($rows[0] as $key => $val) {
|
foreach ($rows[0] as $key => $val) {
|
||||||
$val = $_GET["columns"][key($select)];
|
$val = $_GET["columns"][key($select)];
|
||||||
$field = $fields[$select ? $val["col"] : $key];
|
$field = $fields[$select ? $val["col"] : $key];
|
||||||
$name = ($field ? adminer_field_name($field) : "*");
|
$name = ($field ? $adminer->fieldName($field) : "*");
|
||||||
if (strlen($name)) {
|
if (strlen($name)) {
|
||||||
$names[$key] = $name;
|
$names[$key] = $name;
|
||||||
echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>";
|
echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>";
|
||||||
|
@ -336,7 +336,7 @@ if (!$columns) {
|
||||||
if (!$link && is_email($val)) {
|
if (!$link && is_email($val)) {
|
||||||
$link = "mailto:$val";
|
$link = "mailto:$val";
|
||||||
}
|
}
|
||||||
$val = adminer_select_val($val, $link, $fields[$key]);
|
$val = $adminer->selectVal($val, $link, $fields[$key]);
|
||||||
echo "<td>$val";
|
echo "<td>$val";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ if (!$columns) {
|
||||||
}
|
}
|
||||||
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
|
echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
|
||||||
|
|
||||||
adminer_select_extra_display(array_filter($email_fields, 'strlen'));
|
$adminer->selectExtraDisplay(array_filter($email_fields, 'strlen'));
|
||||||
|
|
||||||
echo "</form>\n";
|
echo "</form>\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
class Adminer {
|
function adminer_object() {
|
||||||
|
|
||||||
|
class AdminerCds extends Adminer {
|
||||||
|
|
||||||
function name() {
|
function name() {
|
||||||
// custom name in title and heading
|
// custom name in title and heading
|
||||||
|
@ -17,20 +19,23 @@ class Adminer {
|
||||||
}
|
}
|
||||||
|
|
||||||
function login($login, $password) {
|
function login($login, $password) {
|
||||||
// username: admin, password: anything
|
// username: 'admin', password: anything
|
||||||
return ($login == 'admin');
|
return ($login == 'admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
function table_name($row) {
|
function tableName($row) {
|
||||||
// tables without comments would return empty string and will be ignored by Adminer
|
// tables without comments would return empty string and will be ignored by Adminer
|
||||||
return htmlspecialchars($row["Comment"]);
|
return htmlspecialchars($row["Comment"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function field_name($field) {
|
function fieldName($field) {
|
||||||
// fields without comments will be ignored
|
// fields without comments will be ignored
|
||||||
return ($field ? htmlspecialchars($field["comment"]) : "*");
|
return ($field ? htmlspecialchars($field["comment"]) : "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new AdminerCds;
|
||||||
|
}
|
||||||
|
|
||||||
include "./index.php";
|
include "./index.php";
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
function adminer_name() {
|
class Adminer {
|
||||||
return call_adminer('name', lang('Editor'));
|
|
||||||
|
function name() {
|
||||||
|
return lang('Editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_credentials() {
|
function credentials() {
|
||||||
return call_adminer('credentials', array()); // default INI settings
|
return array(); // default INI settings
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_database() {
|
function database() {
|
||||||
$dbs = get_databases();
|
$dbs = get_databases();
|
||||||
return call_adminer('database', (count($dbs) == 1 ? $dbs[0] : (count($dbs) == 2 && information_schema($dbs[0]) ? $dbs[1] : 'test')));
|
return (count($dbs) == 1 ? $dbs[0] : (count($dbs) == 2 && information_schema($dbs[0]) ? $dbs[1] : 'test'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_login_form($username) {
|
function loginForm($username) {
|
||||||
if (call_adminer('login_form', true, $username)) {
|
|
||||||
?>
|
?>
|
||||||
<table cellspacing="0">
|
<table cellspacing="0">
|
||||||
<tr><th><?php echo lang('Username'); ?><td><input type="hidden" name="server" value="" /><input name="username" value="<?php echo htmlspecialchars($username); ?>">
|
<tr><th><?php echo lang('Username'); ?><td><input type="hidden" name="server" value="" /><input name="username" value="<?php echo htmlspecialchars($username); ?>">
|
||||||
|
@ -21,32 +22,31 @@ function adminer_login_form($username) {
|
||||||
</table>
|
</table>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function login($login, $password) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_login($login, $password) {
|
function tableName($tableStatus) {
|
||||||
return call_adminer('login', true, $login, $password);
|
table_comment($tableStatus);
|
||||||
|
return htmlspecialchars(strlen($tableStatus["Comment"]) ? $tableStatus["Comment"] : $tableStatus["Name"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_table_name($table_status) {
|
function fieldName($field) {
|
||||||
table_comment($table_status);
|
return htmlspecialchars(strlen($field["comment"]) ? $field["comment"] : $field["field"]);
|
||||||
return call_adminer('table_name', htmlspecialchars(strlen($table_status["Comment"]) ? $table_status["Comment"] : $table_status["Name"]), $table_status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_field_name($field) {
|
function selectLinks($tableStatus) {
|
||||||
return call_adminer('field_name', htmlspecialchars(strlen($field["comment"]) ? $field["comment"] : $field["field"]), $field);
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_links($table_status) {
|
function backwardKeys($table) {
|
||||||
return call_adminer('select_links', "", $table_status);
|
|
||||||
}
|
|
||||||
|
|
||||||
function adminer_backward_keys($table) {
|
|
||||||
global $dbh;
|
global $dbh;
|
||||||
$return = array();
|
$return = array();
|
||||||
$result = $dbh->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
$result = $dbh->query("SELECT TABLE_NAME, CONSTRAINT_NAME, COLUMN_NAME, REFERENCED_COLUMN_NAME
|
||||||
FROM information_schema.KEY_COLUMN_USAGE
|
FROM information_schema.KEY_COLUMN_USAGE
|
||||||
WHERE TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
WHERE TABLE_SCHEMA = " . $dbh->quote($this->database()) . "
|
||||||
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote(adminer_database()) . "
|
AND REFERENCED_TABLE_SCHEMA = " . $dbh->quote($this->database()) . "
|
||||||
AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . "
|
AND REFERENCED_TABLE_NAME = " . $dbh->quote($table) . "
|
||||||
ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
|
ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
|
||||||
if ($result) {
|
if ($result) {
|
||||||
|
@ -55,14 +55,14 @@ ORDER BY ORDINAL_POSITION"); //! requires MySQL 5
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
}
|
}
|
||||||
return call_adminer('backward_keys', $return, $table);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_query($query) {
|
function selectQuery($query) {
|
||||||
return call_adminer('select_query', "<!-- " . str_replace("--", "--><!--", $query) . " -->\n", $query);
|
return "<!-- " . str_replace("--", "--><!--", $query) . " -->\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_row_description($table) {
|
function rowDescription($table) {
|
||||||
$return = "";
|
$return = "";
|
||||||
// first varchar column
|
// first varchar column
|
||||||
foreach (fields($table) as $field) {
|
foreach (fields($table) as $field) {
|
||||||
|
@ -71,17 +71,17 @@ function adminer_row_description($table) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return call_adminer('row_description', $return, $table);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_row_descriptions($rows, $foreign_keys) {
|
function rowDescriptions($rows, $foreignKeys) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
$return = $rows;
|
$return = $rows;
|
||||||
foreach ($rows[0] as $key => $val) {
|
foreach ($rows[0] as $key => $val) {
|
||||||
foreach ((array) $foreign_keys[$key] as $foreign_key) {
|
foreach ((array) $foreignKeys[$key] as $foreignKey) {
|
||||||
if (count($foreign_key["source"]) == 1) {
|
if (count($foreignKey["source"]) == 1) {
|
||||||
$id = idf_escape($foreign_key["target"][0]);
|
$id = idf_escape($foreignKey["target"][0]);
|
||||||
$name = adminer_row_description($foreign_key["table"]);
|
$name = $this->rowDescription($foreignKey["table"]);
|
||||||
if (strlen($name)) {
|
if (strlen($name)) {
|
||||||
// find all used ids
|
// find all used ids
|
||||||
$ids = array();
|
$ids = array();
|
||||||
|
@ -90,7 +90,7 @@ function adminer_row_descriptions($rows, $foreign_keys) {
|
||||||
}
|
}
|
||||||
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
|
// uses constant number of queries to get the descriptions, join would be complex, multiple queries would be slow
|
||||||
$descriptions = array();
|
$descriptions = array();
|
||||||
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreign_key["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
|
$result = $dbh->query("SELECT $id, $name FROM " . idf_escape($foreignKey["table"]) . " WHERE $id IN (" . implode(", ", $ids) . ")");
|
||||||
while ($row = $result->fetch_row()) {
|
while ($row = $result->fetch_row()) {
|
||||||
$descriptions[$row[0]] = $row[1];
|
$descriptions[$row[0]] = $row[1];
|
||||||
}
|
}
|
||||||
|
@ -104,10 +104,10 @@ function adminer_row_descriptions($rows, $foreign_keys) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return call_adminer('row_descriptions', $return, $rows, $foreign_keys);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_val($val, $link, $field) {
|
function selectVal($val, $link, $field) {
|
||||||
$return = ($val == "<i>NULL</i>" ? " " : $val);
|
$return = ($val == "<i>NULL</i>" ? " " : $val);
|
||||||
if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
|
if (ereg('blob|binary', $field["type"]) && !is_utf8($val)) {
|
||||||
$return = lang('%d byte(s)', strlen($val));
|
$return = lang('%d byte(s)', strlen($val));
|
||||||
|
@ -115,23 +115,23 @@ function adminer_select_val($val, $link, $field) {
|
||||||
$return = "<img src=\"$link\" alt='$return'>";
|
$return = "<img src=\"$link\" alt='$return'>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return call_adminer('select_val', ($link ? "<a href=\"$link\">$return</a>" : $return), $val, $link);
|
return ($link ? "<a href=\"$link\">$return</a>" : $return);
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_extra_display($email_fields) {
|
function selectExtraDisplay($emailFields) {
|
||||||
global $confirm;
|
global $confirm;
|
||||||
if (call_adminer('select_extra_display', true, $email_fields) && $email_fields) {
|
if ($emailFields) {
|
||||||
echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email' class='hidden'>\n";
|
echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email' class='hidden'>\n";
|
||||||
echo "<p>" . lang('From') . ": <input name='email_from'>\n";
|
echo "<p>" . lang('From') . ": <input name='email_from'>\n";
|
||||||
echo lang('Subject') . ": <input name='email_subject'>\n";
|
echo lang('Subject') . ": <input name='email_subject'>\n";
|
||||||
echo "<p><textarea name='email_message' rows='15' cols='60'></textarea>\n";
|
echo "<p><textarea name='email_message' rows='15' cols='60'></textarea>\n";
|
||||||
echo "<p>" . (count($email_fields) == 1 ? '<input type="hidden" name="email_field" value="' . htmlspecialchars(key($email_fields)) . '">' : '<select name="email_field">' . optionlist($email_fields) . '</select> ');
|
echo "<p>" . (count($emailFields) == 1 ? '<input type="hidden" name="email_field" value="' . htmlspecialchars(key($emailFields)) . '">' : '<select name="email_field">' . optionlist($emailFields) . '</select> ');
|
||||||
echo "<input type='submit' name='email' value='" . lang('Send') . "'$confirm>\n";
|
echo "<input type='submit' name='email' value='" . lang('Send') . "'$confirm>\n";
|
||||||
echo "</div></fieldset>\n";
|
echo "</div></fieldset>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_select_extra_process($where) {
|
function selectExtraProcess($where) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
if ($_POST["email"]) {
|
if ($_POST["email"]) {
|
||||||
$sent = 0;
|
$sent = 0;
|
||||||
|
@ -154,25 +154,25 @@ function adminer_select_extra_process($where) {
|
||||||
}
|
}
|
||||||
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
|
redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
|
||||||
}
|
}
|
||||||
return call_adminer('select_extra_process', false, $where);
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_message_query($query) {
|
function messageQuery($query) {
|
||||||
return call_adminer('message_query', "<!--\n" . str_replace("--", "--><!--", $query) . "\n-->", $query);
|
return "<!--\n" . str_replace("--", "--><!--", $query) . "\n-->";
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_edit_functions($field) {
|
function editFunctions($field) {
|
||||||
return call_adminer('edit_functions', (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + array(""), $field);
|
return (isset($_GET["select"]) ? array("orig" => lang('original')) : array()) + array("");
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_edit_input($table, $field) {
|
function editInput($table, $field) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
$return = null;
|
$return = null;
|
||||||
$foreign_keys = column_foreign_keys($table);
|
$foreign_keys = column_foreign_keys($table);
|
||||||
foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) {
|
foreach ((array) $foreign_keys[$field["field"]] as $foreign_key) {
|
||||||
if (count($foreign_key["source"]) == 1) {
|
if (count($foreign_key["source"]) == 1) {
|
||||||
$id = idf_escape($foreign_key["target"][0]);
|
$id = idf_escape($foreign_key["target"][0]);
|
||||||
$name = adminer_row_description($foreign_key["table"]);
|
$name = $this->rowDescription($foreign_key["table"]);
|
||||||
if (strlen($name) && $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big
|
if (strlen($name) && $dbh->result($dbh->query("SELECT COUNT(*) FROM " . idf_escape($foreign_key["table"]))) <= 1000) { // optionlist with more than 1000 options would be too big
|
||||||
if ($field["null"]) {
|
if ($field["null"]) {
|
||||||
$return[""] = "";
|
$return[""] = "";
|
||||||
|
@ -186,7 +186,7 @@ function adminer_edit_input($table, $field) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return call_adminer('edit_input', $return, $table, $field);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Process sent input
|
/** Process sent input
|
||||||
|
@ -194,10 +194,9 @@ function adminer_edit_input($table, $field) {
|
||||||
* @param array single field from fields()
|
* @param array single field from fields()
|
||||||
* @return string expression to use in a query
|
* @return string expression to use in a query
|
||||||
*/
|
*/
|
||||||
function adminer_process_input($name, $field) {
|
function processInput($name, $field) {
|
||||||
global $dbh;
|
global $dbh;
|
||||||
$idf = bracket_escape($name);
|
$idf = bracket_escape($name);
|
||||||
$function = $_POST["function"][$idf];
|
|
||||||
$value = $_POST["fields"][$idf];
|
$value = $_POST["fields"][$idf];
|
||||||
$return = $dbh->quote($value);
|
$return = $dbh->quote($value);
|
||||||
if (!ereg('varchar|text', $field["type"]) && !strlen($value)) {
|
if (!ereg('varchar|text', $field["type"]) && !strlen($value)) {
|
||||||
|
@ -205,12 +204,12 @@ function adminer_process_input($name, $field) {
|
||||||
} elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
|
} elseif (ereg('date|time', $field["type"]) && $value == "CURRENT_TIMESTAMP") {
|
||||||
$return = $value;
|
$return = $value;
|
||||||
}
|
}
|
||||||
return call_adminer('process_input', $return, $name, $field);
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adminer_navigation($missing) {
|
function navigation($missing) {
|
||||||
global $SELF;
|
global $SELF;
|
||||||
if (call_adminer('navigation', true, $missing) && $missing != "auth") {
|
if ($missing != "auth") {
|
||||||
?>
|
?>
|
||||||
<form action="" method="post">
|
<form action="" method="post">
|
||||||
<p>
|
<p>
|
||||||
|
@ -226,7 +225,7 @@ function adminer_navigation($missing) {
|
||||||
} else {
|
} else {
|
||||||
echo "<p>\n";
|
echo "<p>\n";
|
||||||
foreach ($table_status as $row) {
|
foreach ($table_status as $row) {
|
||||||
$name = adminer_table_name($row);
|
$name = $this->tableName($row);
|
||||||
if (isset($row["Engine"]) && strlen($name)) { // ignore views and tables without name
|
if (isset($row["Engine"]) && strlen($name)) { // ignore views and tables without name
|
||||||
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . "\">$name</a><br>\n";
|
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . "\">$name</a><br>\n";
|
||||||
}
|
}
|
||||||
|
@ -235,3 +234,5 @@ function adminer_navigation($missing) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
<?php
|
<?php
|
||||||
$_GET["db"] = ""; // used here and there by Adminer
|
$_GET["db"] = ""; // used here and there by Adminer
|
||||||
$dbh->select_db(adminer_database());
|
$dbh->select_db($adminer->database());
|
||||||
|
|
Loading…
Reference in a new issue