Permalink
Browse files

E-mail sending

Change Adminer class to adminer_ functions.inc.php
Unify includes
Unify adminer_credentials()
Don't use JUSH in Editor
Separate identifier and description in breadcrumb
Simplify where()

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@800 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
jakubvrana
jakubvrana committed Jul 11, 2009
1 parent 1ae22ac commit c16c57b1b115fefc82dd1d5f10c568b93fe2949c
View
@@ -1,5 +1,5 @@
<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . friendly_url("$_GET[download]-" . implode("_", $_GET["where"])) . "." . friendly_url($_GET["field"]));
-echo $dbh->result($dbh->query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($_GET["download"]) . " WHERE " . implode(" AND ", where($_GET)) . " LIMIT 1"));
+echo $dbh->result($dbh->query("SELECT " . idf_escape($_GET["field"]) . " FROM " . idf_escape($_GET["download"]) . " WHERE " . where($_GET) . " LIMIT 1"));
exit; // don't output footer
View
@@ -1,5 +1,5 @@
<?php
-$where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : array()) : where($_GET));
+$where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
$update = ($where && !$_POST["clone"]);
$fields = fields($_GET["edit"]);
foreach ($fields as $name => $field) {
@@ -10,7 +10,7 @@
if ($_POST && !$error && !isset($_GET["select"])) {
$location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); // "insert" to continue edit or insert
if (isset($_POST["delete"])) {
- query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been deleted.'));
+ query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1", $location, lang('Item has been deleted.'));
} else {
$set = array();
foreach ($fields as $name => $field) {
@@ -33,13 +33,20 @@
if (isset($_GET["default"])) {
query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values has been set.'));
} elseif ($update) {
- query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been updated.'));
+ query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE $where LIMIT 1", $location, lang('Item has been updated.'));
} else {
query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
}
}
}
-page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
+
+$table_name = adminer_table_name(table_status($_GET["edit"]));
+page_header(
+ (isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))),
+ $error,
+ array((isset($_GET["default"]) ? "table" : "select") => array($_GET["edit"], $table_name)),
+ $table_name
+);
unset($row);
if ($_POST["save"]) {
@@ -53,7 +60,7 @@
}
$row = array();
if ($select) {
- $result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1");
+ $result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1");
$row = $result->fetch_assoc();
$result->free();
}
@@ -66,7 +73,7 @@
unset($create);
echo "<table cellspacing='0'>\n";
foreach ($fields as $name => $field) {
- echo "<tr><th>" . $adminer->field_name($fields, $name) . "</th>";
+ echo "<tr><th>" . adminer_field_name($fields, $name) . "</th>";
$value = (isset($row)
? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
: ($_POST["clone"] && $field["auto_increment"] ? "" : ($where ? $field["default"] : false))
View
@@ -1,5 +1,23 @@
// Adminer specific functions
+function body_load() {
+ var script = document.createElement('script');
+ script.src = '../externals/jush/jush.js';
+ script.onload = function () {
+ jush.style('../externals/jush/jush.css');
+ jush.highlight_tag('pre');
+ jush.highlight_tag('code');
+ }
+ script.onreadystatechange = function () {
+ if (script.readyState == 'loaded' || script.readyState == 'complete') {
+ script.onload();
+ }
+ }
+ document.body.appendChild(script);
+}
+
+
+
var added = '.', row_count;
function re_escape(s) {
View
@@ -13,22 +13,6 @@ function verify_version(version) {
document.body.appendChild(script);
}
-function load_jush() {
- var script = document.createElement('script');
- script.src = '../externals/jush/jush.js';
- script.onload = function () {
- jush.style('../externals/jush/jush.css');
- jush.highlight_tag('pre');
- jush.highlight_tag('code');
- }
- script.onreadystatechange = function () {
- if (script.readyState == 'loaded' || script.readyState == 'complete') {
- script.onload();
- }
- }
- document.body.appendChild(script);
-}
-
function form_check(el, name) {
var elems = el.form.elements;
for (var i=0; i < elems.length; i++) {
@@ -1,35 +1,86 @@
<?php
-class AdminerBase {
-
- function name() {
- return lang('Adminer');
- }
-
- function server() {
- return $_GET["server"];
- }
-
- function username() {
- return $_SESSION["usernames"][$_GET["server"]];
- }
-
- function password() {
- return $_SESSION["passwords"][$_GET["server"]];
- }
-
- function table_name($row) {
- return htmlspecialchars($row["Name"]);
- }
-
- function field_name($fields, $key) {
- return htmlspecialchars($key);
+/** Name in title and navigation
+* @return string
+*/
+function adminer_name() {
+ return call_adminer('name', lang('Adminer'));
+}
+
+/** Connection parameters
+* @return array ($server, $username, $password)
+*/
+function adminer_credentials() {
+ return call_adminer('credentials', array($_GET["server"], $_SESSION["usernames"][$_GET["server"]], $_SESSION["passwords"][$_GET["server"]]));
+}
+
+/** Identifier of selected database
+* @return string
+*/
+function adminer_database() {
+ // should be used everywhere instead of $_GET["db"]
+ return call_adminer('database', $_GET["db"]);
+}
+
+/** Table caption used in navigation and headings
+* @param array result of SHOW TABLE STATUS
+* @return string
+*/
+function adminer_table_name($row) {
+ return call_adminer('table_name', htmlspecialchars($row["Name"]), $row);
+}
+
+/** Field caption used in select and edit
+* @param array all fields in table, result of fields()
+* @param string column identifier, function calls are not contained in $fields
+* @return string
+*/
+function adminer_field_name($fields, $key) {
+ return call_adminer('field_name', htmlspecialchars($key), $fields, $key);
+}
+
+/** Links after select heading
+* @param array result of SHOW TABLE STATUS
+* @return string
+*/
+function adminer_select_links($table_status) {
+ global $SELF;
+ return call_adminer('select_links', '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>', $table_status);
+}
+
+/** Process and print select query before execution
+* @param string query to be executed
+* @return string
+*/
+function adminer_select_query($query) {
+ 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
+ $return = call_adminer('select_query', "", $query);
+ if (!$return) {
+ echo "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n";
+ return $query;
}
-
- function navigation($missing) {
- global $SELF;
- if ($missing != "auth") {
- $databases = get_databases();
- ?>
+ return $return;
+}
+
+/** Query printed after execution in the message
+* @param string executed query
+* @return string
+*/
+function adminer_message_query($query) {
+ global $SELF;
+ $id = "sql-" . count($_SESSION["messages"]);
+ 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"]])) . '">' . lang('Edit') . '</a></div>', $query);
+}
+
+/** Prints navigation after Adminer title
+* @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
+*/
+function adminer_navigation($missing) {
+ global $SELF;
+ if (call_adminer('navigation', true, $missing) && $missing != "auth") {
+ $databases = get_databases();
+ ?>
<form action="" method="post">
<p>
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
@@ -52,22 +103,19 @@ function navigation($missing) {
</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";
+ 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"]) . '">' . adminer_table_name($row) . "</a><br />\n";
}
- echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\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);
@@ -24,6 +24,9 @@
} elseif ($_GET["file"] == "functions.js") {
header("Content-Type: text/javascript");
?>compile_file('functions.js', 'JSMin::minify')<?php
+ } elseif ($_GET["file"] == "editing.js") {
+ header("Content-Type: text/javascript");
+ ?>compile_file('editing.js', 'JSMin::minify')<?php
} else {
header("Content-Type: image/gif");
switch ($_GET["file"]) {
@@ -78,4 +81,20 @@ function save_coverage() {
set_magic_quotes_runtime(false);
$SELF = (isset($_SERVER["REQUEST_URI"]) ? preg_replace('~^[^?]*/([^?]*).*~', '\\1', $_SERVER["REQUEST_URI"]) : $_SERVER["ORIG_PATH_INFO"]) . '?' . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (strlen($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
-$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION");
+$on_actions = array("RESTRICT", "CASCADE", "SET NULL", "NO ACTION"); // used in foreign_keys()
+
+include "../adminer/include/version.inc.php";
+include "../adminer/include/functions.inc.php";
+include "../adminer/include/lang.inc.php";
+include "./lang/$LANG.inc.php";
+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 "./include/editing.inc.php";
+include "./include/export.inc.php";
@@ -1,6 +1,6 @@
<?php
function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
- global $SELF, $LANG, $VERSION, $adminer;
+ global $SELF, $LANG, $VERSION;
header("Content-Type: text/html; charset=utf-8");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -9,17 +9,17 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<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>
-<link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
+<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="stylesheet" type="text/css" href="../adminer/default.css<?php // Ondrej Valka, http://valka.info ?>" />
<?php if (file_exists("adminer.css")) { ?>
<link rel="stylesheet" type="text/css" href="adminer.css" />
<?php } ?>
</head>
-<body onload="load_jush();<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verify_version('$VERSION');"); ?>">
+<body onload="body_load();<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verify_version('$VERSION');"); ?>">
<script type="text/javascript" src="../adminer/functions.js"></script>
-<script type="text/javascript" src="./editing.js"></script>
+<script type="text/javascript" src="./editing.js<?php // "./" to distinguish from $_GET["file"] ?>"></script>
<div id="content">
<?php
@@ -31,8 +31,9 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
echo '<a href="' . htmlspecialchars(substr($SELF, 0, -1)) . '">' . htmlspecialchars($_GET["db"]) . '</a> &raquo; ';
}
foreach ($breadcrumb as $key => $val) {
- if (strlen($val)) {
- echo '<a href="' . htmlspecialchars("$SELF$key=") . ($key != "privileges" ? urlencode($val) : "") . '">' . htmlspecialchars($val) . '</a> &raquo; ';
+ $desc = (is_array($val) ? $val[1] : $val);
+ if (strlen($desc)) {
+ echo '<a href="' . htmlspecialchars("$SELF$key=") . urlencode(is_array($val) ? $val[0] : $val) . '">' . htmlspecialchars($desc) . '</a> &raquo; ';
}
}
}
@@ -57,16 +58,16 @@ function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
}
function page_footer($missing = false) {
- global $SELF, $VERSION, $dbh, $adminer;
+ global $SELF, $VERSION, $dbh;
?>
</div>
<?php switch_lang(); ?>
<div id="menu">
-<h1><a href="http://www.adminer.org/" class="h1"><?php echo $adminer->name(); ?></a> &nbsp; <?php echo $VERSION; ?> &nbsp;
+<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 $adminer->navigation($missing); ?>
+<?php adminer_navigation($missing); ?>
</div>
</body>
@@ -58,7 +58,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $allowed = 0, $forei
<td><input type="radio" name="auto_increment_col" value="" /><?php echo lang('Auto Increment'); ?></td>
<td<?php echo ($column_comments ? "" : " class='hidden'"); ?>><?php echo lang('Comment'); ?></td>
<?php } ?>
-<td><?php echo "<input type='image' name='add[0]' src='../adminer/plus.gif' alt='+' title='" . lang("Add next") . "' />"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script></td>
+<td><?php echo "<input type='image' name='add[0]' src='../adminer/plus.gif' alt='+' title='" . lang('Add next') . "' />"; ?><script type="text/javascript">row_count = <?php echo count($fields); ?>;</script></td>
</tr></thead>
<?php
foreach ($fields as $i => $field) {
Oops, something went wrong.

0 comments on commit c16c57b

Please sign in to comment.