Editor: User friendly data editor

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@787 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2009-07-03 06:26:01 +00:00
parent ef580994be
commit b95f24ea7a
11 changed files with 179 additions and 55 deletions

View file

@ -17,12 +17,6 @@ class AdminerBase {
return $_SESSION["passwords"][$_GET["server"]];
}
function table_list($row) {
global $SELF;
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . $this->table_name($row) . "</a><br />\n";
}
function table_name($row) {
return htmlspecialchars($row["Name"]);
}
@ -31,6 +25,49 @@ class AdminerBase {
return htmlspecialchars($key);
}
function navigation($missing) {
global $SELF;
if ($missing != "auth") {
$databases = get_databases();
?>
<form action="" method="post">
<p>
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
<a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>" />
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" />
</p>
</form>
<form action="">
<p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" /><?php } ?>
<?php if ($databases) { ?>
<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option><?php echo optionlist($databases, $_GET["db"]); ?></select>
<?php } else { ?>
<input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>" />
<?php } ?>
<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?>
<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value="" /><?php } ?>
<?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value="" /><?php } ?>
<input type="submit" value="<?php echo lang('Use'); ?>"<?php echo ($databases ? " class='hidden'" : ""); ?> />
</p>
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
foreach ($table_status as $row) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . lang('select') . '</a> ';
echo '<a href="' . htmlspecialchars($SELF) . (isset($row["Rows"]) ? 'table' : 'view') . '=' . urlencode($row["Name"]) . '">' . $this->table_name($row) . "</a><br />\n";
}
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
}
}
}
}
$adminer = (class_exists("Adminer") ? new Adminer : new AdminerBase);

View file

@ -74,4 +74,6 @@ if (get_magic_quotes_gpc()) {
unset($process);
}
set_magic_quotes_runtime(false);
$SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION");

View file

@ -65,44 +65,7 @@ function page_footer($missing = false) {
<h1><a href="http://www.adminer.org/" class="h1"><?php echo $adminer->name(); ?></a> &nbsp; <?php echo $VERSION; ?> &nbsp;
<a href='http://www.adminer.org/#download' id="version"><?php echo (version_compare($VERSION, $_COOKIE["adminer_version"]) < 0 ? htmlspecialchars($_COOKIE["adminer_version"]) : ""); ?></a>
</h1>
<?php if ($missing != "auth") { ?>
<form action="" method="post">
<p>
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
<a href="<?php echo htmlspecialchars($SELF); ?>dump=<?php echo urlencode(isset($_GET["table"]) ? $_GET["table"] : $_GET["select"]); ?>"><?php echo lang('Dump'); ?></a>
<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>" />
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" />
</p>
</form>
<form action="">
<p><?php if (strlen($_GET["server"])) { ?><input type="hidden" name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" /><?php } ?>
<?php if (get_databases()) { ?>
<select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option><?php echo optionlist(get_databases(), $_GET["db"]); ?></select>
<?php } else { ?>
<input name="db" value="<?php echo htmlspecialchars($_GET["db"]); ?>" />
<?php } ?>
<?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?>
<?php if (isset($_GET["schema"])) { ?><input type="hidden" name="schema" value="" /><?php } ?>
<?php if (isset($_GET["dump"])) { ?><input type="hidden" name="dump" value="" /><?php } ?>
<input type="submit" value="<?php echo lang('Use'); ?>"<?php echo (get_databases() ? " class='hidden'" : ""); ?> />
</p>
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
foreach ($table_status as $row) {
$adminer->table_list($row);
}
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n";
}
}
?>
<?php $adminer->navigation($missing); ?>
</div>
</body>

View file

@ -23,7 +23,6 @@ include "./include/connect.inc.php";
include "./include/editing.inc.php";
include "./include/export.inc.php";
$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION");
$enum_length = '\'(?:\'\'|[^\'\\\\]+|\\\\.)*\'|"(?:""|[^"\\\\]+|\\\\.)*"';
$inout = array("IN", "OUT", "INOUT");
$confirm = " onclick=\"return confirm('" . lang('Are you sure?') . "');\"";

View file

@ -1,4 +1,5 @@
Adminer 1.12.0:
Editor: User friendly data editor
Create single column foreign key in table structure
Adminer 1.11.0 (released 2009-07-02):

View file

@ -23,8 +23,8 @@ function lang_ids($match) {
}
function put_file($match) {
global $lang_ids;
if ($match[2] == './lang/$LANG.inc.php') {
global $lang_ids, $project;
if (basename($match[2]) == '$LANG.inc.php') {
if ($_COOKIE["adminer_lang"]) {
return "";
}
@ -52,7 +52,7 @@ function put_file($match) {
}
return "switch (\$LANG) {\n$return}\n";
}
$return = file_get_contents(dirname(__FILE__) . "/adminer/$match[2]");
$return = file_get_contents(dirname(__FILE__) . "/$project/$match[2]");
if ($match[2] != "./include/lang.inc.php" || !$_COOKIE["adminer_lang"]) {
$tokens = token_get_all($return); // to find out the last token
return "?>\n$return" . (in_array($tokens[count($tokens) - 1][0], array(T_CLOSE_TAG, T_INLINE_HTML), true) ? "<?php" : "");
@ -167,18 +167,23 @@ function compile_file($match) {
}
error_reporting(E_ALL & ~E_NOTICE);
$project = "adminer";
if ($_SERVER["argc"] > 1) {
if (file_exists($_SERVER["argv"][1] . "/index.php")) {
$project = $_SERVER["argv"][1];
array_shift($_SERVER["argv"]);
}
$_COOKIE["adminer_lang"] = $_SERVER["argv"][1]; // Adminer functions read language from cookie
include dirname(__FILE__) . "/adminer/include/lang.inc.php";
if ($_SERVER["argc"] != 2 || !isset($langs[$_COOKIE["adminer_lang"]])) {
echo "Usage: php compile.php [lang]\nPurpose: Compile adminer[-lang].php from index.php.\n";
if (isset($_SERVER["argv"][2]) || !isset($langs[$_COOKIE["adminer_lang"]])) {
echo "Usage: php compile.php [project] [lang]\nPurpose: Compile adminer[-lang].php from index.php.\n";
exit(1);
}
include dirname(__FILE__) . "/adminer/lang/$_COOKIE[adminer_lang].inc.php";
}
$filename = "adminer" . ($_COOKIE["adminer_lang"] ? "-$_COOKIE[adminer_lang]" : "") . ".php";
$file = file_get_contents(dirname(__FILE__) . "/adminer/index.php");
$filename = $project . ($_COOKIE["adminer_lang"] ? "-$_COOKIE[adminer_lang]" : "") . ".php";
$file = file_get_contents(dirname(__FILE__) . "/$project/index.php");
$file = preg_replace('(' . str_replace(' ', '\\s*', preg_quote(' if (isset($_GET["coverage"])) { include "./coverage.inc.php"; }')) . ')', '', $file);
$file = preg_replace_callback('~\\b(include|require) "([^"]*)";~', 'put_file', $file);
$file = preg_replace("~if \\(isset\\(\\\$_SESSION\\[\"coverage.*\n}\n| && !isset\\(\\\$_SESSION\\[\"coverage\"\\]\\)~sU", '', $file);
@ -191,9 +196,9 @@ if ($_COOKIE["adminer_lang"]) {
$file = preg_replace_callback("~lang\\('((?:[^\\\\']+|\\\\.)*)'([,)])~s", 'lang_ids', $file);
}
$file = preg_replace_callback("~compile_file\\('([^']+)', '([^']+)'\\)~", 'compile_file', $file); // integrate static files
$replace = 'htmlspecialchars(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\0&amp;version=' . $VERSION;
$file = preg_replace('~(?<!== ")(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~(?<!case ")(plus|cross|up|down|arrow)\\.gif~', '" . ' . $replace, $file);
$replace = 'htmlspecialchars(preg_replace("~\\\\\\\\?.*~", "", $_SERVER["REQUEST_URI"])) . "?file=\\1&amp;version=' . $VERSION;
$file = preg_replace('~\\.\\./adminer/(default\\.css|functions\\.js|favicon\\.ico)~', '<?php echo ' . $replace . '"; ?>', $file);
$file = preg_replace('~\\.\\./adminer/((plus|cross|up|down|arrow)\\.gif)~', '" . ' . $replace, $file);
$file = str_replace("../externals/jush/", "http://jush.sourceforge.net/", $file);
$file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
$file = php_shrink($file);

2
editor/db.inc.php Normal file
View file

@ -0,0 +1,2 @@
<?php
page_header(lang('Database') . ": " . htmlspecialchars($_GET["db"]), $error, false);

View file

@ -0,0 +1,55 @@
<?php
class AdminerBase {
function name() {
return lang('Editor');
}
function server() {
return "";
}
function username() {
return "";
}
function password() {
return "";
}
function table_name($row) {
return htmlspecialchars(strlen($row["Comment"]) ? $row["Comment"] : $row["Name"]);
}
function field_name($fields, $key) {
return htmlspecialchars(strlen($fields[$key]["comment"]) ? $fields[$key]["comment"] : $key);
}
function navigation($missing) {
global $SELF;
if ($missing != "auth") {
?>
<form action="" method="post">
<p>
<input type="hidden" name="token" value="<?php echo $_SESSION["tokens"][$_GET["server"]]; ?>" />
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" />
</p>
</form>
<?php
if ($missing != "db" && strlen($_GET["db"])) {
$table_status = table_status();
if (!$table_status) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
foreach ($table_status as $row) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row["Name"]) . '">' . $this->table_name($row) . "</a><br />\n";
}
echo "</p>\n";
}
}
}
}
}
$adminer = (class_exists("Adminer") ? new Adminer : new AdminerBase);

View file

@ -0,0 +1,2 @@
<?php
$dbh = connect(); //! process errors

View file

@ -0,0 +1,3 @@
<?php
$_GET["db"] = "test";
$dbh->select_db($_GET["db"]);

55
editor/index.php Normal file
View file

@ -0,0 +1,55 @@
<?php
/** Adminer Editor - Compact MySQL editor
* @link http://www.adminer.org/
* @author Jakub Vrana, http://php.vrana.cz/
* @copyright 2009 Jakub Vrana
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
*/
include "../adminer/include/bootstrap.inc.php";
include "../adminer/include/version.inc.php";
include "../adminer/include/functions.inc.php";
include "../adminer/include/lang.inc.php";
include "../adminer/lang/$LANG.inc.php"; //! subset and superset
include "./include/adminer.inc.php";
include "../adminer/include/design.inc.php";
if (isset($_GET["coverage"])) {
include "../adminer/coverage.inc.php";
}
include "../adminer/include/pdo.inc.php";
include "../adminer/include/mysql.inc.php";
include "./include/auth.inc.php";
include "./include/connect.inc.php";
include "../adminer/include/editing.inc.php";
include "../adminer/include/export.inc.php";
$confirm = " onclick=\"return confirm('" . lang('Are you sure?') . "');\"";
$error = "";
if (isset($_GET["download"])) {
include "../adminer/download.inc.php";
} else { // uses CSRF token
$token = $_SESSION["tokens"][$_GET["server"]];
if ($_POST) {
if ($_POST["token"] != $token) {
$error = lang('Invalid CSRF token. Send the form again.');
}
} elseif ($_SERVER["REQUEST_METHOD"] == "POST") {
// posted form with no data means exceeded post_max_size because Adminer always sends token at least
$error = lang('Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.');
}
if (isset($_GET["select"]) && $_POST && (!$_POST["delete"] && !$_POST["export"] && !$_POST["import"] && !$_POST["save"])) {
// POST form on select page is used to edit or clone data
$_GET["edit"] = $_GET["select"];
}
if (isset($_GET["edit"])) {
include "../adminer/edit.inc.php";
} elseif (isset($_GET["select"])) {
include "../adminer/select.inc.php";
} else {
include "./db.inc.php";
}
}
// each page calls its own page_header(), if the footer should not be called then the page exits
page_footer();