Decomposition

New functions

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@2 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana 2007-07-02 05:51:26 +00:00
parent b4a429709f
commit 667bfec47d
14 changed files with 709 additions and 456 deletions

20
_compile.php Normal file
View file

@ -0,0 +1,20 @@
<?php
function put_file($match) {
//! exit on error with require, _once
$return = file_get_contents($match[4]);
$return = preg_replace("~\\?>?\n?\$~", '', $return);
if (substr_count($return, "<?php") - substr_count($return, "?>") <= 0 && !$match[5]) {
$return .= "<?php\n";
}
$return = preg_replace('~^<\\?php\\s+~', '', $return, 1, $count);
if (!$count && !$match[1]) {
$return = "?>\n$return";
}
return $return;
}
$file = file_get_contents("index.php");
$file = preg_replace_callback('~(<\\?php\\s*)?(include|require)(_once)? "([^"]*)";(\\s*\\?>)?~', 'put_file', $file);
//! remove spaces and comments
file_put_contents("phpMinAdmin.php", $file);
echo "phpMinAdmin.php created.\n";

46
auth.inc.php Normal file
View file

@ -0,0 +1,46 @@
<?php
if (isset($_POST["server"])) {
$_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $_POST["password"];
header("Location: " . ($_GET["server"] == $_POST["server"] ? $_SERVER["REQUEST_URI"] : preg_replace('~^[^?]*/([^?]*).*~', '\\1' . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : '') . (SID ? (strlen($_POST["server"]) ? "&" : "?") . SID : ""), $_SERVER["REQUEST_URI"])));
exit;
}
if (!@mysql_connect($_GET["server"], $_SESSION["username"], $_SESSION["password"])) {
page_header(lang('Login'), "auth");
?>
<h1><?php echo lang('phpMinAdmin'); ?></h1>
<?php
if (isset($_GET["server"])) {
echo "<p class='error'>" . lang('Invalid credentials.') . "</p>\n";
}
?>
<form action="" method="post">
<table border="0" cellspacing="0" cellpadding="2">
<tr><th><?php echo lang('Server'); ?>:</th><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" maxlength="60" /></td></tr>
<tr><th><?php echo lang('Login'); ?>:</th><td><input name="username" value="<?php echo htmlspecialchars($_SESSION["username"]); ?>" maxlength="16" /></td></tr>
<tr><th><?php echo lang('Password'); ?>:</th><td><input type="password" name="password" /></td></tr>
<tr><th><?php
foreach ($_POST as $key => $val) { // expired session
if (!is_array($val)) {
echo '<input type="hidden" name="' . htmlspecialchars($key) . '" value="' . htmlspecialchars($val) . '" />';
} else {
foreach ($val as $key2 => $val2) {
if (!is_array($val2)) {
echo '<input type="hidden" name="' . htmlspecialchars($key . "[$key2]") . ' value="' . htmlspecialchars($val2) . '" />';
} else {
foreach ($val2 as $key3 => $val3) {
echo '<input type="hidden" name="' . htmlspecialchars($key . "[$key2][$key3]") . ' value="' . htmlspecialchars($val3) . '" />';
}
}
}
}
}
?>
</th><td><input type="submit" value="<?php echo lang('Login'); ?>" /></td></tr>
</table>
</form>
<?php
page_footer("auth");
exit;
}

10
connect.inc.php Normal file
View file

@ -0,0 +1,10 @@
<?php
if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) || isset($_GET["dump"]))) {
page_header((isset($_GET["db"]) ? lang('Invalid database') : lang('Select database')), "db");
if (strlen($_GET["db"])) {
echo "<p class='error'>" . lang('Invalid database.') . "</p>\n";
}
page_footer();
exit;
}
mysql_query("SET CHARACTER SET utf8");

61
create.inc.php Normal file
View file

@ -0,0 +1,61 @@
<?php
$types = array("int"); //!
if ($_POST["drop"]) {
if (mysql_query("DROP TABLE " . idf_escape($_GET["create"]))) {
$_SESSION["message"] = lang('Table has been dropped.');
header("Location: " . substr($SELF, 0, -1));
exit;
}
} elseif ($_POST) {
$fields = array();
ksort($_POST["fields"]);
foreach ($_POST["fields"] as $key => $field) {
if (strlen($field["name"]) && in_array($field["type"], $types)) {
$length = ($field["length"] ? "(" . intval($field["length"]) . ")" : ""); //! decimal, enum and set lengths
$fields[] = idf_escape($field["name"]) . " " . $field["type"] . $length . ($field["not_null"] ? " NOT NULL" : "") . ($field["auto_increment"] ? " AUTO_INCREMENT" : "");
}
}
//! alter table
if ($fields && mysql_query("CREATE TABLE " . idf_escape($_POST["name"]) . " (" . implode(", ", $fields) . ")" . ($_POST["engine"] ? " ENGINE='" . mysql_real_escape_string($_POST["engine"]) . "'" : "") . ($_POST["collate"] ? " COLLATE '" . mysql_real_escape_string($_POST["collate"]) . "'" : ""))) {
$_SESSION["message"] = lang('Table has been created.');
header("Location: $SELF" . "table=" . urlencode($_POST["name"]));
exit;
}
}
page_header(lang('Create table'));
echo "<h2>" . lang('Create table') . "</h2>\n";
if ($_POST) {
echo "<p class='error'>" . lang('Unable to operate table.') . "</p>\n";
$collate = $_POST["collate"];
//! prefill fields
} elseif (strlen($_GET["create"])) {
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'"));
$collate = $row["Collation"];
$engine = $row["Engine"];
//! prefill fields
}
//! collate columns, references, indexes, unsigned
?>
<form action="" method="post">
<p>
<?php echo lang('Table name'); ?>: <input name="name" maxlength="64" value="<?php echo htmlspecialchars($_GET["create"]); ?>" />
<select name="engine"><option value="">(<?php echo lang('engine'); ?>)</option><?php echo optionlist(engines(), $engine, "not_vals"); ?></select>
<select name="collate"><option value="">(<?php echo lang('collate'); ?>)</option><?php echo optionlist(collations(), $collate, "not_vals"); ?></select>
</p>
<table border="0" cellspacing="0" cellpadding="2">
<thead><tr><th><?php echo lang('Name'); ?></th><td><?php echo lang('Type'); ?></td><td><?php echo lang('Length'); ?></td><td><?php echo lang('NOT NULL'); ?></td><td><?php echo lang('AUTO_INCREMENT'); ?></td></tr></thead>
<tr>
<th><input name="fields[0][name]" maxlength="64" /></th>
<td><select name="fields[0][type]"><?php echo optionlist($types, array(), "not_vals"); ?></select></td>
<td><input name="fields[0][length]" size="3" /></td>
<td><input type="checkbox" name="fields[0][not_null]" value="1" /></td>
<td><input type="checkbox" name="fields[0][auto_increment]" value="1" /></td>
</tr>
<?php //! JavaScript for next rows ?>
</table>
<p>
<input type="submit" value="<?php echo lang('Create'); ?>" />
<?php if (strlen($_GET["create"])) { ?><input type="submit" name="drop" value="<?php echo lang('Drop'); ?>" /><?php } ?>
</p>
</form>

83
design.inc.php Normal file
View file

@ -0,0 +1,83 @@
<?php
function page_header($title, $missing = false) {
global $SELF;
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">
<html xmlns="http://www.w3.org/1999/xhtml" lang="cs">
<head>
<title><?php echo lang('phpMinAdmin') . ($title ? " - $title" : ""); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
BODY { color: Black; background-color: White; }
A { color: Blue; }
A:visited { color: Navy; }
H2 { font-size: 150%; margin-top: 0; }
.error { color: Red; }
.message { color: Green; }
#menu { float: left; width: 15em; overflow: auto; white-space: nowrap; }
#menu H1 { font-size: 150%; margin: 0; }
#menu H1 A { color: Black; }
#content { margin-left: 16em; }
</style>
</head>
<body>
<?php
if ($missing != "auth") {
?>
<div id="menu">
<h1><a href="<?php echo htmlspecialchars(substr($SELF, 0, -1)); ?>"><?php echo lang('phpMinAdmin'); ?></a></h1>
<p>
<a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a>
<a href="<?php echo htmlspecialchars($SELF); ?>dump="><?php echo lang('Dump'); ?></a>
</p>
<form action="" method="get">
<p><select name="db" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option>
<?php
//! logout, create database
$result = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_row($result)) {
echo "<option" . ($row[0] == $_GET["db"] ? " selected='selected'" : "") . ">" . htmlspecialchars($row[0]) . "</option>\n";
}
mysql_free_result($result);
?>
</select><?php if (isset($_GET["sql"])) { ?><input type="hidden" name="sql" value="" /><?php } ?></p>
<noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
</form>
<?php
if ($missing != "db") {
$result = mysql_query("SHOW TABLES");
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
while ($row = mysql_fetch_row($result)) {
echo '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($row[0]) . '">' . lang('select') . '</a> '; //! inline image through style
echo '<a href="' . htmlspecialchars($SELF) . 'table=' . urlencode($row[0]) . '">' . htmlspecialchars($row[0]) . "</a><br />\n"; //! views
}
echo "</p>\n";
}
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=">' . lang('Create new table') . "</a></p>\n"; //! rights
mysql_free_result($result);
}
?>
</div>
<div id="content">
<?php
}
if ($_SESSION["message"]) {
echo "<p class='message'>$_SESSION[message]</p>\n";
$_SESSION["message"] = "";
}
}
function page_footer($missing = false) {
echo "\n" . ($missing ? "" : "</div>\n");
?>
</body>
</html>
<?php
}

47
dump.inc.php Normal file
View file

@ -0,0 +1,47 @@
<?php
header("Content-Type: text/plain; charset=utf-8"); //! Content-Disposition
function dump($db) {
static $routines;
if (!isset($routines)) {
$routines = array();
foreach (array("FUNCTION", "PROCEDURE") as $routine) {
$result = mysql_query("SHOW $routine STATUS");
while ($row = mysql_fetch_assoc($result)) {
if (!strlen($_GET["db"]) || $row["Db"] === $_GET["db"]) {
$routines[$row["Db"]][] = mysql_result(mysql_query("SHOW CREATE $routine " . idf_escape($row["Db"]) . "." . idf_escape($row["Name"])), 0, 2) . ";\n\n";
}
}
mysql_free_result($result);
}
}
//! CREATE DATABASE
echo "USE $db;\n";
echo "SET CHARACTER SET utf8;\n\n";
$result = mysql_query("SHOW TABLES");
while ($row = mysql_fetch_row($result)) {
echo mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($row[0])), 0, 1) . ";\n\n";
//! data except views
}
mysql_free_result($result);
echo implode("", (array) $routines[$db]); //! delimiter
}
if (strlen($_GET["db"])) {
dump($_GET["db"]);
} else {
$result = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_assoc($result)) {
if ($row["Database"] != "information_schema") {
if (mysql_select_db($row["Database"])) {
dump($row["Database"]);
}
}
}
mysql_free_result($result);
}
exit;

104
edit.inc.php Normal file
View file

@ -0,0 +1,104 @@
<?php
$fields = fields($_GET["edit"]);
if ($_POST) {
if (isset($_POST["delete"])) {
$query = "DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been deleted.');
} else {
$set = array();
foreach ($fields as $key => $field) {
if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($_POST["fields"][$key])) {
$value = "NULL";
} elseif ($field["type"] == "enum") {
$value = intval($_POST["fields"][$key]);
} elseif ($field["type"] == "set") {
$value = array_sum((array) $_POST["fields"][$key]);
} else {
$value = "'" . mysql_real_escape_string($_POST["fields"][$key]) . "'";
}
$set[] = idf_escape(bracket_escape($key, "back")) . " = $value";
}
if ($where) {
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been updated.');
} else {
$query = "INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set);
$message = lang('Item has been inserted.');
}
}
if (mysql_query($query)) {
$_SESSION["message"] = $message; //! warnings
header("Location: " . $SELF . "select=" . urlencode($_GET["edit"]) . (SID ? "&" . SID : ""));
exit;
}
}
page_header(($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecialchars($_GET["edit"]));
echo "<h2>" . ($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecialchars($_GET["edit"]) . "</h2>\n";
$where = array();
if (is_array($_GET["where"])) {
foreach ($_GET["where"] as $key => $val) {
$where[] = idf_escape($key) . " = BINARY '" . mysql_real_escape_string($val) . "'";
}
}
if (is_array($_GET["null"])) {
foreach ($_GET["null"] as $key) {
$where[] = idf_escape($key) . " IS NULL";
}
}
if ($_POST) {
echo "<p class='error'>" . lang('Error during saving') . ": " . htmlspecialchars(mysql_error()) . "</p>\n";
$data = $_POST["fields"];
foreach ($_POST["fields"] as $key => $val) {
$data[$key] = null;
}
} elseif ($where) {
$select = array("*");
foreach ($fields as $name => $field) {
if ($field["type"] == "enum" || $field["type"] == "set") {
$select[] = "1*" . idf_escape($name) . " AS " . idf_escape($name);
}
}
$data = mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"));
} else {
$data = array();
}
?>
<form action="" method="post">
<table border='1' cellspacing='0' cellpadding='2'>
<?php
foreach ($fields as $name => $field) {
echo "<tr><th>" . htmlspecialchars($name) . "</th><td>";
$value = ($data ? $data[$name] : $field["default"]);
$name = htmlspecialchars(bracket_escape($name));
if ($field["type"] == "enum") {
echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value == "0" ? ' checked="checked"' : '') . ' />';
preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) {
$id = "field-$name-" . ($i+1);
echo ' <input type="radio" name="fields[' . $name . ']" id="' . $id . '" value="' . ($i+1) . '"' . ($value == $i+1 ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars(str_replace("''", "'", $val)) . '</label>';
}
if ($field["null"]) {
$id = "field-$name-";
echo '<input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (strlen($value) ? '' : ' checked="checked"') . ' /><label for="' . $id . '">' . lang('NULL') . '</label> ';
}
} elseif ($field["type"] == "set") { //! 64 bits
preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) {
$id = "$name-" . ($i+1);
echo ' <input type="checkbox" name="fields[' . $name . '][]" id="' . $id . '" value="' . pow(2, $i) . '"' . ($value & pow(2, $i) ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars(str_replace("''", "'", $val)) . '</label>';
}
} elseif (strpos($field["type"], "text") !== false) {
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
} else { //! numbers, date, binary
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (strlen($field["length"]) ? " maxlength='$field[length]'" : '') . ' />';
}
if ($field["null"] && preg_match('~char|text|set~', $field["type"])) {
echo '<input type="checkbox" name="null[' . $name . ']" value="1" id="null-' . $name . '"' . (isset($value) ? '' : ' checked="checked"') . ' /><label for="null-' . $name . '">' . lang('NULL') . '</label>';
}
echo "</td></tr>\n";
}
echo "<tr><th></th><td><input type='submit' value='" . lang('Save') . "' />" . ($where ? " <input type='submit' name='delete' value='" . lang('Delete') . "' />" : "") . "</td></tr>\n";
?>
</table>
</form>

137
functions.inc.php Normal file
View file

@ -0,0 +1,137 @@
<?php
function lang($idf) {
return $idf;
}
function idf_escape($idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
function idf_unescape($idf) {
return str_replace("``", "`", $idf);
}
function bracket_escape($idf, $back = false) {
static $trans = array(':' => ':1', ']' => ':2');
return strtr($idf, ($back ? array_flip($trans) : $trans));
}
function optionlist($options, $selected = array(), $not_vals = false) {
$return = "";
foreach ($options as $k => $v) {
if (is_array($v)) {
$return .= '<optgroup label="' . htmlspecialchars($k) . '">';
}
foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) {
$checked = in_array(($not_vals ? $val : $key), (array) $selected);
$return .= '<option' . ($not_vals ? '' : ' value="' . htmlspecialchars($key) . '"') . ($checked ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
}
if (is_array($v)) {
$return .= '</optgroup>';
}
}
return $return;
}
function fields($table) {
$return = array();
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) {
preg_match('~^(.*?)(?:\\((.+)\\))?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
"type" => $match[1],
"length" => $match[2],
"default" => $row["Default"],
"null" => ($row["Null"] != "NO"),
);
}
mysql_free_result($result);
return $return;
}
function indexes($table) {
$return = array();
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) {
$type = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
$return[$type][$row["Key_name"]][$row["Seq_in_index"]] = $row["Column_name"];
}
mysql_free_result($result);
return $return;
}
function foreign_keys($table) {
//! make over to information_schema.key_column_usage
static $pattern = '~`((?:[^`]*|``)+)`~';
$return = array();
$create_table = mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($table)), 0, 1);
preg_match_all('~FOREIGN KEY \\((.*)\\) REFERENCES (.*) \\((.*)\\)~', $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
preg_match_all($pattern, $match[1], $source);
preg_match_all($pattern, $match[3], $target);
foreach ($source[1] as $val) {
$return[idf_unescape($val)][] = array(idf_unescape(substr($match[2], 1, -1)), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
}
}
return $return;
}
function unique_idf($row, $indexes) {
foreach ($indexes as $type => $index) {
if ($type == "PRIMARY" || $type == "UNIQUE") {
foreach ($index as $columns) {
$return = array();
foreach ($columns as $key) {
if (!isset($row[$key])) {
continue 2;
}
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
}
return $return;
}
}
}
$return = array();
foreach ($row as $key => $val) {
$return[] = (isset($val) ? urlencode("where[$key]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
}
return $return;
}
function collations() {
$return = array();
$result = mysql_query("SHOW COLLATION");
while ($row = mysql_fetch_assoc($result)) {
$return[$row["Charset"]][] = $row["Collation"];
}
mysql_free_result($result);
return $return;
}
function engines() {
$return = array();
$result = mysql_query("SHOW ENGINES");
while ($row = mysql_fetch_assoc($result)) {
if ($row["Support"] == "YES" || $row["Support"] == "DEFAULT") {
$return[] = $row["Engine"];
}
}
mysql_free_result($result);
return $return;
}
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}

43
index.php Normal file
View file

@ -0,0 +1,43 @@
<?php
session_start();
error_reporting(E_ALL & ~E_NOTICE);
$SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (isset($_GET["db"]) ? 'db=' . urlencode($_GET["db"]) . '&' : '');
include "./functions.inc.php";
include "./design.inc.php";
include "./auth.inc.php";
include "./connect.inc.php";
if (isset($_GET["sql"])) {
include "./sql.inc.php";
} elseif (isset($_GET["table"])) {
include "./table.inc.php";
} elseif (isset($_GET["select"])) {
include "./select.inc.php";
} elseif (isset($_GET["edit"])) {
include "./edit.inc.php";
} elseif (isset($_GET["create"])) {
include "./create.inc.php";
} elseif (isset($_GET["dump"])) {
include "./dump.inc.php";
} elseif (isset($_GET["view"])) {
include "./view.inc.php";
} else {
page_header(htmlspecialchars($_GET["db"]));
$result = mysql_query("SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "'");
if (mysql_num_rows($result)) {
echo "<h2>" . lang('Routines') . "</h2>\n";
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . htmlspecialchars($row["ROUTINE_TYPE"]) . "</td>";
echo "<th>" . htmlspecialchars($row["ROUTINE_NAME"]) . "</th>"; //! parameters from SHOW CREATE {PROCEDURE|FUNCTION}
echo "<td>" . nl2br(htmlspecialchars($row["ROUTINE_DEFINITION"])) . "</td>";
echo "</tr>\n";
//! drop
}
echo "</table>\n";
}
mysql_free_result($result);
}
page_footer();

View file

@ -1,456 +0,0 @@
<?php
session_start();
header("Content-Type: text/html; charset=utf-8");
error_reporting(E_ALL & ~E_NOTICE);
ob_start();
function lang($idf) {
return $idf;
}
function idf_escape($idf) {
return "`" . str_replace("`", "``", $idf) . "`";
}
function idf_unescape($idf) {
return str_replace("``", "`", $idf);
}
function bracket_escape($idf, $back = false) {
static $trans = array(':' => ':1', ']' => ':2');
return strtr($idf, ($back ? array_flip($trans) : $trans));
}
function optionlist($options, $selected = array(), $not_vals = false) {
$return = "";
foreach ($options as $key => $val) {
$checked = in_array(($not_vals ? $val : $key), (array) $selected);
$return .= '<option' . ($not_vals ? '' : ' value="' . htmlspecialchars($key) . '"') . ($checked ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
}
return $return;
}
function fields($table) {
$return = array();
$result = mysql_query("SHOW COLUMNS FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) {
preg_match('~^(.*?)(?:\\((.+)\\))?$~', $row["Type"], $match);
$return[$row["Field"]] = array(
"type" => $match[1],
"length" => $match[2],
"default" => $row["Default"],
"null" => ($row["Null"] != "NO"),
);
}
mysql_free_result($result);
return $return;
}
function indexes($table) {
$return = array();
$result = mysql_query("SHOW INDEX FROM " . idf_escape($table));
while ($row = mysql_fetch_assoc($result)) {
$type = ($row["Key_name"] == "PRIMARY" ? "PRIMARY" : ($row["Index_type"] == "FULLTEXT" ? "FULLTEXT" : ($row["Non_unique"] ? "INDEX" : "UNIQUE")));
$return[$type][$row["Key_name"]][$row["Seq_in_index"]] = $row["Column_name"];
}
mysql_free_result($result);
return $return;
}
function foreign_keys($table) {
static $pattern = '~`((?:[^`]*|``)+)`~';
$return = array();
$create_table = mysql_result(mysql_query("SHOW CREATE TABLE " . idf_escape($table)), 0, 1);
preg_match_all('~FOREIGN KEY \\((.*)\\) REFERENCES (.*) \\((.*)\\)~', $create_table, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
preg_match_all($pattern, $match[1], $source);
preg_match_all($pattern, $match[3], $target);
foreach ($source[1] as $val) {
$return[idf_unescape($val)][] = array(idf_unescape(substr($match[2], 1, -1)), array_map('idf_unescape', $source[1]), array_map('idf_unescape', $target[1]));
}
}
return $return;
}
function unique_idf($row, $indexes) {
foreach ($indexes as $type => $index) {
if ($type == "PRIMARY" || $type == "UNIQUE") {
foreach ($index as $columns) {
$return = array();
foreach ($columns as $key) {
if (!isset($row[$key])) {
continue 2;
}
$return[] = urlencode("where[$key]") . "=" . urlencode($row[$key]);
}
return $return;
}
}
}
$return = array();
foreach ($row as $key => $val) {
$return[] = (isset($val) ? urlencode("where[$key]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
}
return $return;
}
if (get_magic_quotes_gpc()) {
$process = array(&$_GET, &$_POST);
while (list($key, $val) = each($process)) {
foreach ($val as $k => $v) {
unset($process[$key][$k]);
if (is_array($v)) {
$process[$key][stripslashes($k)] = $v;
$process[] = &$process[$key][stripslashes($k)];
} else {
$process[$key][stripslashes($k)] = stripslashes($v);
}
}
}
unset($process);
}
if (isset($_POST["server"])) {
$_SESSION["username"] = $_POST["username"];
$_SESSION["password"] = $_POST["password"];
header("Location: " . ($_GET["server"] == $_POST["server"] ? $_SERVER["REQUEST_URI"] : preg_replace('~^[^?]*/([^?]*).*~', '\\1' . (strlen($_POST["server"]) ? '?server=' . urlencode($_POST["server"]) : ''), $_SERVER["REQUEST_URI"])));
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="cs">
<head>
<title><?php echo lang('phpMinAdmin'); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
BODY { color: Black; background-color: White; }
A { color: Blue; }
A:visited { color: Navy; }
.error { color: Red; }
.message { color: Green; }
</style>
</head>
<body>
<?php
if (!@mysql_connect($_GET["server"], $_SESSION["username"], $_SESSION["password"])) {
?>
<h1><?php echo lang('phpMinAdmin'); ?></h1>
<?php
if (isset($_GET["server"])) {
echo "<p class='error'>" . lang('Invalid credentials.') . "</p>\n";
}
?>
<form action="" method="post">
<table border="0" cellspacing="0" cellpadding="2">
<tr><th><?php echo lang('Server'); ?>:</th><td><input name="server" value="<?php echo htmlspecialchars($_GET["server"]); ?>" maxlength="60" /></td></tr>
<tr><th><?php echo lang('Login'); ?>:</th><td><input name="username" value="<?php echo htmlspecialchars($_SESSION["username"]); ?>" maxlength="16" /></td></tr>
<tr><th><?php echo lang('Password'); ?>:</th><td><input type="password" name="password" /></td></tr>
<tr><th><?php
foreach ((array) $_POST["fields"] as $key => $val) { // expired session
echo '<input type="hidden" name="fields[' . htmlspecialchars($key) . ']" value="' . htmlspecialchars($val) . '" />';
}
?>
</th><td><input type="submit" value="<?php echo lang('Login'); ?>" /></td></tr>
</table>
</form>
<?php
} else {
$SELF = preg_replace('~^[^?]*/([^?]*).*~', '\\1?', $_SERVER["REQUEST_URI"]) . (strlen($_GET["server"]) ? 'server=' . urlencode($_GET["server"]) . '&' : '') . (isset($_GET["database"]) ? 'database=' . urlencode($_GET["database"]) . '&' : '');
?>
<div style="float: left; width: 15em;">
<h1 style="font-size: 150%; margin: 0;"><?php echo lang('phpMinAdmin'); ?></h1>
<p><a href="<?php echo htmlspecialchars($SELF); ?>sql="><?php echo lang('SQL command'); ?></a></p>
<form action="" method="get">
<p><select name="database" onchange="this.form.submit();"><option value="">(<?php echo lang('database'); ?>)</option>
<?php
//! logout
$result = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_row($result)) {
echo "<option" . ($row[0] == $_GET["database"] ? " selected='selected'" : "") . ">" . htmlspecialchars($row[0]) . "</option>\n";
}
mysql_free_result($result);
?>
</select></p>
<noscript><p><input type="submit" value="<?php echo lang('Use'); ?>" /></p></noscript>
</form>
<?php
if (isset($_GET["database"]) && !mysql_select_db($_GET["database"])) {
echo "<p class='error'>" . lang('Invalid database.') . "</p>\n";
} else {
mysql_query("SET CHARACTER SET utf8");
if (isset($_GET["database"])) {
$result = mysql_query("SHOW TABLES");
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No tables.') . "</p>\n";
} else {
echo "<p>\n";
while ($row = mysql_fetch_row($result)) {
echo "<a href='" . htmlspecialchars($SELF) . "select=" . urlencode($row[0]) . "'>" . lang('select') . "</a> <a href='" . htmlspecialchars($SELF) . "table=" . urlencode($row[0]) . "'>" . htmlspecialchars($row[0]) . "</a><br />\n";
}
echo "</p>\n";
}
mysql_free_result($result);
}
?>
</div>
<div style="margin-left: 16em;">
<?php
if (isset($_GET["sql"])) {
echo "<h2>" . lang('SQL command') . "</h2>\n";
if ($_SESSION["message"]) {
echo "<p class='message'>$_SESSION[message]</p>\n";
$_SESSION["message"] = "";
}
if ($_POST) {
$result = mysql_query($_POST["query"]);
if (!$result) {
echo "<p class='error'>" . lang('Error in query') . ": " . mysql_error() . "</p>\n";
} elseif (mysql_num_rows($result)) {
while ($row = mysql_fetch_assoc($result)) {
//! select
}
mysql_free_result($result);
} else {
mysql_free_result($result);
$_SESSION["message"] = sprintf(lang('Query executed OK, %d row(s) affected.'), mysql_affected_rows());
header("Location: " . $SELF . "sql=");
exit;
}
}
?>
<form action="" method="post">
<p><textarea name="query" rows="20" cols="80"><?php echo htmlspecialchars($_POST["query"]); ?></textarea></p>
<p><input type="submit" value="<?php echo lang('Execute'); ?>" /></p>
</form>
<?php
} elseif (isset($_GET["table"])) {
echo "<h2>" . lang('Table') . ": " . htmlspecialchars($_GET["table"]) . "</h2>\n";
$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($_GET["table"]));
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "NO" ? " NOT NULL" : "") . "</td></tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
$indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<h3>" . lang('Indexes') . "</h3>\n";
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
foreach ($indexes as $type => $index) {
foreach ($index as $columns) {
sort($columns);
echo "<tr><td>$type</td><td><i>" . implode("</i>, <i>", $columns) . "</i></td></tr>\n";
}
}
echo "</table>\n";
}
} elseif (isset($_GET["select"])) {
ob_end_flush();
echo "<h2>" . lang('Select') . ": " . htmlspecialchars($_GET["select"]) . "</h2>\n";
if ($_SESSION["message"]) {
echo "<p class='message'>$_SESSION[message]</p>\n";
$_SESSION["message"] = "";
}
echo "<p><a href='" . htmlspecialchars($SELF) . "edit=" . urlencode($_GET["select"]) . "'>" . lang('New item') . "</a></p>\n";
$limit = 30;
echo "<form action=''><div>\n";
if (strlen($_GET["server"])) {
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
}
echo '<input type="hidden" name="database" value="' . htmlspecialchars($_GET["database"]) . '" />';
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
$where = array();
$columns = array();
foreach (fields($_GET["select"]) as $name => $field) {
$columns[] = $name;
}
$operators = array("=", "<", ">", "<=", ">=", "!=", "IS NULL"); //! IS NULL - hide input
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if ($val["col"] && in_array($val["op"], $operators)) {
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
echo "<select name='where[$i][op]'>" . optionlist($operators, $val["op"], "not_vals") . "</select>";
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /><br />\n";
$i++;
}
}
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<select name='where[$i][op]'>" . optionlist($operators, array(), "not_vals") . "</select>";
echo "<input name='where[$i][val]' /><br />\n"; //! JavaScript for adding next
//! sort, limit
echo "<input type='submit' value='" . lang('Search') . "' />\n";
echo "</div></form>\n";
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " LIMIT $limit OFFSET " . ($limit * $_GET["page"]));
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0);
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else {
$indexes = indexes($_GET["select"]);
$foreign_keys = foreign_keys($_GET["select"]);
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
$first = true;
while ($row = mysql_fetch_assoc($result)) {
if ($first) {
echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th><th>" . lang('Action') . "</th></tr></thead>\n";
$first = false;
}
echo "<tr>";
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "<i>NULL</i>";
} else {
$val = htmlspecialchars($val);
if (count($foreign_keys[$key]) == 1) {
$foreign_key = $foreign_keys[$key][0];
$val = '">' . "$val</a>";
foreach ($foreign_key[1] as $i => $source) {
$val = "&amp;where[$i][col]=" . urlencode($foreign_key[2][$i]) . "&amp;where[$i][op]=%3D&amp;where[$i][val]=" . urlencode($row[$source]) . $val;
}
$val = '<a href="' . htmlspecialchars($SELF) . 'select=' . htmlspecialchars($foreign_key[0]) . $val; // InnoDB support non-UNIQUE keys //! other database
}
}
echo "<td>$val</td>";
}
echo "<td><a href='" . htmlspecialchars($SELF) . "edit=" . urlencode($_GET["select"]) . "&amp;" . implode("&amp;", unique_idf($row, $indexes)) . "'>edit</a></td>"; //! links to referencing tables
echo "</tr>\n";
}
echo "</table>\n";
if ($found_rows > $limit) {
echo "<p>" . lang('Page') . ":\n";
for ($i=0; $i < $found_rows / $limit; $i++) {
echo ($i == $_GET["page"] ? $i + 1 : "<a href='" . htmlspecialchars($SELF) . "select=" . urlencode($_GET["select"]) . ($i ? "&amp;page=$i" : "") . "'>" . ($i + 1) . "</a>") . "\n";
}
echo "</p>\n";
}
}
mysql_free_result($result);
} elseif (isset($_GET["edit"])) {
echo "<h2>" . lang('Edit') . ": " . htmlspecialchars($_GET["edit"]) . "</h2>\n";
$where = array();
if (is_array($_GET["where"])) {
foreach ($_GET["where"] as $key => $val) {
$where[] = idf_escape($key) . " = BINARY '" . mysql_real_escape_string($val) . "'";
}
}
if (is_array($_GET["null"])) {
foreach ($_GET["null"] as $key) {
$where[] = idf_escape($key) . " IS NULL";
}
}
$fields = fields($_GET["edit"]);
if ($_POST) {
if (isset($_POST["delete"])) {
$query = "DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been deleted.');
} else {
$set = array();
foreach ($fields as $key => $field) {
if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($_POST["fields"][$key])) {
$value = "NULL";
} elseif ($field["type"] == "enum") {
$value = intval($_POST["fields"][$key]);
} elseif ($field["type"] == "set") {
$value = array_sum((array) $_POST["fields"][$key]);
} else {
$value = "'" . mysql_real_escape_string($_POST["fields"][$key]) . "'";
}
$set[] = idf_escape(bracket_escape($key, "back")) . " = $value";
}
if ($where) {
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been updated.');
} else {
$query = "INSERT INTO " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set);
$message = lang('Item has been inserted.');
}
}
if (mysql_query($query)) {
$_SESSION["message"] = $message;
header("Location: " . $SELF . "select=" . urlencode($_GET["edit"]));
exit;
} else {
echo "<p class='error'>" . lang('Error during saving') . ": " . htmlspecialchars(mysql_error()) . "</p>\n";
}
}
if ($_POST) {
$data = $_POST["fields"];
} elseif ($where) {
$select = array("*");
foreach ($fields as $name => $field) {
if ($field["type"] == "enum" || $field["type"] == "set") {
$select[] = "1*" . idf_escape($name) . " AS " . idf_escape($name);
}
}
$data = mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"));
} else {
$data = array();
}
?>
<form action="" method="post">
<table border='1' cellspacing='0' cellpadding='2'>
<?php
foreach ($fields as $name => $field) {
echo "<tr><th>" . htmlspecialchars($name) . "</th><td>";
$value = ($data ? $data[$name] : $field["default"]);
$name = htmlspecialchars(bracket_escape($name));
if ($field["type"] == "enum") {
echo '<input type="radio" name="fields[' . $name . ']" value="0"' . ($value == "0" ? ' checked="checked"' : '') . ' />';
preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) {
$id = "field-$name-" . ($i+1);
echo ' <input type="radio" name="fields[' . $name . ']" id="' . $id . '" value="' . ($i+1) . '"' . ($value == $i+1 ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars(str_replace("''", "'", $val)) . '</label>';
}
if ($field["null"]) {
$id = "field-$name-";
echo '<input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (isset($value) ? '' : ' checked="checked"') . ' /><label for="' . $id . '">' . lang('NULL') . '</label> ';
}
} elseif ($field["type"] == "set") { //! 64 bits
preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
foreach ($matches[1] as $i => $val) {
$id = "$name-" . ($i+1);
echo ' <input type="checkbox" name="fields[' . $name . '][]" id="' . $id . '" value="' . pow(2, $i) . '"' . ($value & pow(2, $i) ? ' checked="checked"' : '') . ' /><label for="' . $id . '">' . htmlspecialchars(str_replace("''", "'", $val)) . '</label>';
}
} elseif (strpos($field["type"], "text") !== false) {
echo '<textarea name="fields[' . $name . ']" cols="50" rows="12">' . htmlspecialchars($value) . '</textarea>';
} else { //! numbers, date, binary
echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (strlen($field["length"]) ? " maxlength='$field[length]'" : '') . ' />';
}
if ($field["null"] && preg_match('~char|text|set~', $field["type"])) {
echo '<input type="checkbox" name="null[' . $name . ']" value="1" id="null-' . $name . '"' . (isset($value) ? '' : ' checked="checked"') . ' /><label for="null-' . $name . '">' . lang('NULL') . '</label>';
}
echo "</td></tr>\n";
}
echo "<tr><th></th><td><input type='submit' value='" . lang('Save') . "' />" . ($where ? " <input type='submit' name='delete' value='" . lang('Delete') . "' />" : "") . "</td></tr>\n";
?>
</table>
</form>
<?php
}
}
?>
</div>
<?php
}
?>
</body>
</html>

84
select.inc.php Normal file
View file

@ -0,0 +1,84 @@
<?php
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
echo "<h2>" . lang('Select') . ": " . htmlspecialchars($_GET["select"]) . "</h2>\n";
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
$indexes = indexes($_GET["select"]);
echo "<form action=''><div>\n";
if (strlen($_GET["server"])) {
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
}
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
$where = array();
$columns = array();
foreach (fields($_GET["select"]) as $name => $field) {
$columns[] = $name;
}
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL"); //! IS NULL - hide input by JavaScript
$i = 0;
foreach ((array) $_GET["where"] as $val) {
if ($val["col"] && in_array($val["op"], $operators)) {
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
echo "<select name='where[$i][op]'>" . optionlist($operators, $val["op"], "not_vals") . "</select>";
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /><br />\n";
$i++;
}
}
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
echo "<select name='where[$i][op]'>" . optionlist($operators, array(), "not_vals") . "</select>";
echo "<input name='where[$i][val]' /><br />\n"; //! JavaScript for adding next
//! fulltext search
//! sort, limit
$limit = 30;
echo "<input type='submit' value='" . lang('Search') . "' />\n";
echo "</div></form>\n";
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " LIMIT $limit OFFSET " . ($limit * $_GET["page"]));
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0);
if (!mysql_num_rows($result)) {
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
} else {
$foreign_keys = foreign_keys($_GET["select"]);
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
for ($j=0; $row = mysql_fetch_assoc($result); $j++) {
if (!$j) {
echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th><th>" . lang('Action') . "</th></tr></thead>\n";
}
echo "<tr>";
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "<i>NULL</i>";
} else {
$val = htmlspecialchars($val);
if (count($foreign_keys[$key]) == 1) {
$foreign_key = $foreign_keys[$key][0];
$val = '">' . "$val</a>";
foreach ($foreign_key[1] as $i => $source) {
$val = "&amp;where[$i][col]=" . urlencode($foreign_key[2][$i]) . "&amp;where[$i][op]=%3D&amp;where[$i][val]=" . urlencode($row[$source]) . $val;
}
$val = '<a href="' . htmlspecialchars($SELF) . 'select=' . htmlspecialchars($foreign_key[0]) . $val; // InnoDB support non-UNIQUE keys //! reference to other database
}
}
echo "<td>$val</td>";
}
echo '<td><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . implode('&amp;', unique_idf($row, $indexes)) . '">edit</a>'; //! views can be unupdatable
//! links to referencing tables - information_schema.key_column_usage - REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME
echo "</td>";
echo "</tr>\n";
}
echo "</table>\n";
if ($found_rows > $limit) {
echo "<p>" . lang('Page') . ":\n";
for ($i=0; $i < $found_rows / $limit; $i++) {
echo ($i == $_GET["page"] ? $i + 1 : '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($_GET['select']) . ($i ? "&amp;page=$i" : "") . '">' . ($i + 1) . "</a>") . "\n";
}
echo "</p>\n";
}
}
mysql_free_result($result);

38
sql.inc.php Normal file
View file

@ -0,0 +1,38 @@
<?php
if ($_POST) {
$result = mysql_query($_POST["query"]); //! multiple commands
if ($result === true) {
$_SESSION["message"] = sprintf(lang('Query executed OK, %d row(s) affected.'), mysql_affected_rows());
header("Location: " . $SELF . "sql=" . (SID ? "&" . SID : ""));
exit;
}
$error = mysql_error();
}
page_header(lang('SQL command'), (strlen($_GET["db"]) ? "" : "db"));
echo "<h2>" . lang('SQL command') . "</h2>\n";
if ($_POST) {
if (!$result) {
echo "<p class='error'>" . lang('Error in query') . ": $error</p>\n";
} else {
//! no rows
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
for ($i=0; $row = mysql_fetch_assoc($result); $i++) {
if (!$i) {
echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th></tr></thead>\n";
}
echo "<tr>";
foreach ($row as $val) {
echo "<td>" . (isset($val) ? htmlspecialchars($val) : "<i>NULL</i>") . "</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
}
}
?>
<form action="" method="post">
<p><textarea name="query" rows="20" cols="80"><?php echo htmlspecialchars($_POST["query"]); ?></textarea></p>
<p><input type="submit" value="<?php echo lang('Execute'); ?>" /></p>
</form>

36
table.inc.php Normal file
View file

@ -0,0 +1,36 @@
<?php
page_header(lang('Table') . ": " . htmlspecialchars($_GET["table"]));
echo "<h2>" . lang('Table') . ": " . htmlspecialchars($_GET["table"]) . "</h2>\n";
$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($_GET["table"]));
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><th>" . htmlspecialchars($row["Field"]) . "</th><td>$row[Type]" . ($row["Null"] == "NO" ? " NOT NULL" : "") . "</td></tr>\n";
}
echo "</table>\n";
mysql_free_result($result);
echo '<p><a href="' . htmlspecialchars($SELF) . 'create=' . urlencode($_GET["table"]) . '">' . lang('Alter table') . "</a></p>\n";
$indexes = indexes($_GET["table"]);
if ($indexes) {
echo "<h3>" . lang('Indexes') . "</h3>\n";
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
foreach ($indexes as $type => $index) {
foreach ($index as $columns) {
sort($columns);
echo "<tr><td>$type</td><td><i>" . implode("</i>, <i>", $columns) . "</i></td></tr>\n";
}
}
echo "</table>\n";
}
$result = mysql_query("SHOW TRIGGERS LIKE '" . mysql_real_escape_string($_GET["table"]) . "'");
if (mysql_num_rows($result)) {
echo "<h3>" . lang('Triggers') . "</h3>\n";
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr><th>$row[Timing]</th><th>$row[Event]</th><td>" . htmlspecialchars($row["Statement"]) . "</td></tr>\n";
}
echo "</table>\n";
}
mysql_free_result($result);

0
view.inc.php Normal file
View file