]> git.joonet.de Git - adminer.git/commitdiff
Editor: User friendly data editor
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 3 Jul 2009 06:26:01 +0000 (06:26 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 3 Jul 2009 06:26:01 +0000 (06:26 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@787 7c3ca157-0c34-0410-bff1-cbf682f78f5c

adminer/include/adminer.inc.php
adminer/include/bootstrap.inc.php
adminer/include/design.inc.php
adminer/index.php
changes.txt
compile.php
editor/db.inc.php [new file with mode: 0644]
editor/include/adminer.inc.php [new file with mode: 0644]
editor/include/auth.inc.php [new file with mode: 0644]
editor/include/connect.inc.php [new file with mode: 0644]
editor/index.php [new file with mode: 0644]

index 640478d4b19dbcdb98f86a70a0c85b8507224b34..08100477188f51ec7273a8a7cddc45233cc8b6c3 100644 (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);
index 02689fe19b10738ce1ff72e57f476a68bb4ce9c5..684287d1c3169ac3d0d2b2046e32501a46aed7c0 100644 (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");
index a7ed615703d494b73966dd698ce6221be24d45e8..6970d37117c7e4944cdfff7a88878e89835308fe 100644 (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>
index 2614cd8c909a929497790695d29a3f748a800449..5c07c1906e49d5bc8a621abf53361705876d6702 100644 (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?') . "');\"";
index f703bfb7f0b1ddb43b432c578031d65c8d310b66..93082285b186abd2c617efab8d40679dc6b136fd 100644 (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):
index 5ded8a8c414dc5c471f803c38dec01322b5246aa..5b77d4ddd006e638341241e17ef75fb2dfae2258 100644 (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);
diff --git a/editor/db.inc.php b/editor/db.inc.php
new file mode 100644 (file)
index 0000000..8e61d31
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+page_header(lang('Database') . ": " . htmlspecialchars($_GET["db"]), $error, false);
diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php
new file mode 100644 (file)
index 0000000..2a4377d
--- /dev/null
@@ -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);
diff --git a/editor/include/auth.inc.php b/editor/include/auth.inc.php
new file mode 100644 (file)
index 0000000..4e231dc
--- /dev/null
@@ -0,0 +1,2 @@
+<?php
+$dbh = connect(); //! process errors
diff --git a/editor/include/connect.inc.php b/editor/include/connect.inc.php
new file mode 100644 (file)
index 0000000..d542a14
--- /dev/null
@@ -0,0 +1,3 @@
+<?php
+$_GET["db"] = "test";
+$dbh->select_db($_GET["db"]);
diff --git a/editor/index.php b/editor/index.php
new file mode 100644 (file)
index 0000000..dcc5809
--- /dev/null
@@ -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();