From 667bfec47d60d488a08cb64e1d3b9a7a4a06e76a Mon Sep 17 00:00:00 2001 From: jakubvrana Date: Mon, 2 Jul 2007 05:51:26 +0000 Subject: [PATCH] Decomposition New functions git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@2 7c3ca157-0c34-0410-bff1-cbf682f78f5c --- _compile.php | 20 ++ auth.inc.php | 46 +++++ connect.inc.php | 10 + create.inc.php | 61 +++++++ design.inc.php | 83 +++++++++ dump.inc.php | 47 +++++ edit.inc.php | 104 +++++++++++ functions.inc.php | 137 ++++++++++++++ index.php | 43 +++++ phpMinAdmin.php | 456 ---------------------------------------------- select.inc.php | 84 +++++++++ sql.inc.php | 38 ++++ table.inc.php | 36 ++++ view.inc.php | 0 14 files changed, 709 insertions(+), 456 deletions(-) create mode 100644 _compile.php create mode 100644 auth.inc.php create mode 100644 connect.inc.php create mode 100644 create.inc.php create mode 100644 design.inc.php create mode 100644 dump.inc.php create mode 100644 edit.inc.php create mode 100644 functions.inc.php create mode 100644 index.php delete mode 100644 phpMinAdmin.php create mode 100644 select.inc.php create mode 100644 sql.inc.php create mode 100644 table.inc.php create mode 100644 view.inc.php diff --git a/_compile.php b/_compile.php new file mode 100644 index 00000000..aa73f4e9 --- /dev/null +++ b/_compile.php @@ -0,0 +1,20 @@ +?\n?\$~", '', $return); + if (substr_count($return, "") <= 0 && !$match[5]) { + $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"; diff --git a/auth.inc.php b/auth.inc.php new file mode 100644 index 00000000..70069b94 --- /dev/null +++ b/auth.inc.php @@ -0,0 +1,46 @@ + +

+ " . lang('Invalid credentials.') . "

\n"; + } + ?> +
+ + + + + +
:" maxlength="60" />
:" maxlength="16" />
:
$val) { // expired session + if (!is_array($val)) { + echo ''; + } else { + foreach ($val as $key2 => $val2) { + if (!is_array($val2)) { + echo ''; + } else { + foreach ($val2 as $key3 => $val3) { + echo ''; + } + } + } + } + } + ?> +
+
+ " . lang('Invalid database.') . "

\n"; + } + page_footer(); + exit; +} +mysql_query("SET CHARACTER SET utf8"); diff --git a/create.inc.php b/create.inc.php new file mode 100644 index 00000000..fcacce62 --- /dev/null +++ b/create.inc.php @@ -0,0 +1,61 @@ + $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 "

" . lang('Create table') . "

\n"; + +if ($_POST) { + echo "

" . lang('Unable to operate table.') . "

\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 +?> +
+

+: " /> + + +

+ + + + + + + + + + +
+

+ + +

+
diff --git a/design.inc.php b/design.inc.php new file mode 100644 index 00000000..2ce9e0f6 --- /dev/null +++ b/design.inc.php @@ -0,0 +1,83 @@ + + + + +<?php echo lang('phpMinAdmin') . ($title ? " - $title" : ""); ?> + + + + + + + + + +
+$_SESSION[message]

\n"; + $_SESSION["message"] = ""; + } +} + +function page_footer($missing = false) { + echo "\n" . ($missing ? "" : "
\n"); +?> + + + $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 "

" . ($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecialchars($_GET["edit"]) . "

\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 "

" . lang('Error during saving') . ": " . htmlspecialchars(mysql_error()) . "

\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(); +} +?> +
+ + $field) { + echo "\n"; +} +echo "\n"; +?> +
" . htmlspecialchars($name) . ""; + $value = ($data ? $data[$name] : $field["default"]); + $name = htmlspecialchars(bracket_escape($name)); + if ($field["type"] == "enum") { + echo ''; + preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches); + foreach ($matches[1] as $i => $val) { + $id = "field-$name-" . ($i+1); + echo ' '; + } + if ($field["null"]) { + $id = "field-$name-"; + echo ' '; + } + } elseif ($field["type"] == "set") { //! 64 bits + preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches); + foreach ($matches[1] as $i => $val) { + $id = "$name-" . ($i+1); + echo ' '; + } + } elseif (strpos($field["type"], "text") !== false) { + echo ''; + } else { //! numbers, date, binary + echo ''; + } + if ($field["null"] && preg_match('~char|text|set~', $field["type"])) { + echo ''; + } + echo "
" . ($where ? " " : "") . "
+
diff --git a/functions.inc.php b/functions.inc.php new file mode 100644 index 00000000..e885511d --- /dev/null +++ b/functions.inc.php @@ -0,0 +1,137 @@ + ':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 .= ''; + } + foreach ((is_array($v) ? $v : array($k => $v)) as $key => $val) { + $checked = in_array(($not_vals ? $val : $key), (array) $selected); + $return .= '' . htmlspecialchars($val) . ''; + } + if (is_array($v)) { + $return .= ''; + } + } + 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); +} diff --git a/index.php b/index.php new file mode 100644 index 00000000..fb4739c5 --- /dev/null +++ b/index.php @@ -0,0 +1,43 @@ +" . lang('Routines') . "\n"; + echo "\n"; + while ($row = mysql_fetch_assoc($result)) { + echo ""; + echo ""; + echo ""; //! parameters from SHOW CREATE {PROCEDURE|FUNCTION} + echo ""; + echo "\n"; + //! drop + } + echo "
" . htmlspecialchars($row["ROUTINE_TYPE"]) . "" . htmlspecialchars($row["ROUTINE_NAME"]) . "" . nl2br(htmlspecialchars($row["ROUTINE_DEFINITION"])) . "
\n"; + } + mysql_free_result($result); +} + +page_footer(); diff --git a/phpMinAdmin.php b/phpMinAdmin.php deleted file mode 100644 index 1206c0b6..00000000 --- a/phpMinAdmin.php +++ /dev/null @@ -1,456 +0,0 @@ - ':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 .= '' . htmlspecialchars($val) . ''; - } - 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; -} -?> - - - -<?php echo lang('phpMinAdmin'); ?> - - - - - - - -

- " . lang('Invalid credentials.') . "

\n"; - } -?> - -
- - - - - -
:" maxlength="60" />
:" maxlength="16" />
:
$val) { // expired session - echo ''; -} -?> -
-
- -
-

-

- -
-

- -
- " . lang('Invalid database.') . "

\n"; - } else { - mysql_query("SET CHARACTER SET utf8"); - - if (isset($_GET["database"])) { - $result = mysql_query("SHOW TABLES"); - if (!mysql_num_rows($result)) { - echo "

" . lang('No tables.') . "

\n"; - } else { - echo "

\n"; - while ($row = mysql_fetch_row($result)) { - echo "" . lang('select') . " " . htmlspecialchars($row[0]) . "
\n"; - } - echo "

\n"; - } - mysql_free_result($result); - } - ?> -
- -
- " . lang('SQL command') . "\n"; - if ($_SESSION["message"]) { - echo "

$_SESSION[message]

\n"; - $_SESSION["message"] = ""; - } - if ($_POST) { - $result = mysql_query($_POST["query"]); - if (!$result) { - echo "

" . lang('Error in query') . ": " . mysql_error() . "

\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; - } - } - ?> -
-

-

-
- " . lang('Table') . ": " . htmlspecialchars($_GET["table"]) . "\n"; - $result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($_GET["table"])); - echo "\n"; - while ($row = mysql_fetch_assoc($result)) { - echo "\n"; - } - echo "
" . htmlspecialchars($row["Field"]) . "$row[Type]" . ($row["Null"] == "NO" ? " NOT NULL" : "") . "
\n"; - mysql_free_result($result); - - $indexes = indexes($_GET["table"]); - if ($indexes) { - echo "

" . lang('Indexes') . "

\n"; - echo "\n"; - foreach ($indexes as $type => $index) { - foreach ($index as $columns) { - sort($columns); - echo "\n"; - } - } - echo "
$type" . implode(", ", $columns) . "
\n"; - } - - } elseif (isset($_GET["select"])) { - ob_end_flush(); - echo "

" . lang('Select') . ": " . htmlspecialchars($_GET["select"]) . "

\n"; - if ($_SESSION["message"]) { - echo "

$_SESSION[message]

\n"; - $_SESSION["message"] = ""; - } - echo "

" . lang('New item') . "

\n"; - $limit = 30; - - echo "
\n"; - if (strlen($_GET["server"])) { - echo ''; - } - echo ''; - echo ''; - - $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 ""; - echo ""; - echo "
\n"; - $i++; - } - } - echo ""; - echo ""; - echo "
\n"; //! JavaScript for adding next - - //! sort, limit - - echo "\n"; - echo "
\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 "

" . lang('No rows.') . "

\n"; - } else { - $indexes = indexes($_GET["select"]); - $foreign_keys = foreign_keys($_GET["select"]); - - echo "\n"; - $first = true; - while ($row = mysql_fetch_assoc($result)) { - if ($first) { - echo "\n"; - $first = false; - } - echo ""; - foreach ($row as $key => $val) { - if (!isset($val)) { - $val = "NULL"; - } else { - $val = htmlspecialchars($val); - if (count($foreign_keys[$key]) == 1) { - $foreign_key = $foreign_keys[$key][0]; - $val = '">' . "$val"; - foreach ($foreign_key[1] as $i => $source) { - $val = "&where[$i][col]=" . urlencode($foreign_key[2][$i]) . "&where[$i][op]=%3D&where[$i][val]=" . urlencode($row[$source]) . $val; - } - $val = '$val"; - } - echo ""; //! links to referencing tables - echo "\n"; - } - echo "
" . implode("", array_map('htmlspecialchars', array_keys($row))) . "" . lang('Action') . "
edit
\n"; - if ($found_rows > $limit) { - echo "

" . lang('Page') . ":\n"; - for ($i=0; $i < $found_rows / $limit; $i++) { - echo ($i == $_GET["page"] ? $i + 1 : "" . ($i + 1) . "") . "\n"; - } - echo "

\n"; - } - } - mysql_free_result($result); - - } elseif (isset($_GET["edit"])) { - echo "

" . lang('Edit') . ": " . htmlspecialchars($_GET["edit"]) . "

\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 "

" . lang('Error during saving') . ": " . htmlspecialchars(mysql_error()) . "

\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(); - } - ?> -
- - $field) { - echo "\n"; - } - echo "\n"; - ?> -
" . htmlspecialchars($name) . ""; - $value = ($data ? $data[$name] : $field["default"]); - $name = htmlspecialchars(bracket_escape($name)); - if ($field["type"] == "enum") { - echo ''; - preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches); - foreach ($matches[1] as $i => $val) { - $id = "field-$name-" . ($i+1); - echo ' '; - } - if ($field["null"]) { - $id = "field-$name-"; - echo ' '; - } - } elseif ($field["type"] == "set") { //! 64 bits - preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches); - foreach ($matches[1] as $i => $val) { - $id = "$name-" . ($i+1); - echo ' '; - } - } elseif (strpos($field["type"], "text") !== false) { - echo ''; - } else { //! numbers, date, binary - echo ''; - } - if ($field["null"] && preg_match('~char|text|set~', $field["type"])) { - echo ''; - } - echo "
" . ($where ? " " : "") . "
-
- -
- - - - diff --git a/select.inc.php b/select.inc.php new file mode 100644 index 00000000..3a5097d1 --- /dev/null +++ b/select.inc.php @@ -0,0 +1,84 @@ +" . lang('Select') . ": " . htmlspecialchars($_GET["select"]) . "\n"; + +echo '

' . lang('New item') . "

\n"; +$indexes = indexes($_GET["select"]); + +echo "
\n"; +if (strlen($_GET["server"])) { + echo ''; +} +echo ''; +echo ''; + +$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 ""; + echo ""; + echo "
\n"; + $i++; + } +} +echo ""; +echo ""; +echo "
\n"; //! JavaScript for adding next +//! fulltext search + +//! sort, limit +$limit = 30; + +echo "\n"; +echo "
\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 "

" . lang('No rows.') . "

\n"; +} else { + $foreign_keys = foreign_keys($_GET["select"]); + + echo "\n"; + for ($j=0; $row = mysql_fetch_assoc($result); $j++) { + if (!$j) { + echo "\n"; + } + echo ""; + foreach ($row as $key => $val) { + if (!isset($val)) { + $val = "NULL"; + } else { + $val = htmlspecialchars($val); + if (count($foreign_keys[$key]) == 1) { + $foreign_key = $foreign_keys[$key][0]; + $val = '">' . "$val"; + foreach ($foreign_key[1] as $i => $source) { + $val = "&where[$i][col]=" . urlencode($foreign_key[2][$i]) . "&where[$i][op]=%3D&where[$i][val]=" . urlencode($row[$source]) . $val; + } + $val = '$val"; + } + echo '"; + echo "\n"; + } + echo "
" . implode("", array_map('htmlspecialchars', array_keys($row))) . "" . lang('Action') . "
edit'; //! views can be unupdatable + //! links to referencing tables - information_schema.key_column_usage - REFERENCED_TABLE_SCHEMA, REFERENCED_TABLE_NAME + echo "
\n"; + if ($found_rows > $limit) { + echo "

" . lang('Page') . ":\n"; + for ($i=0; $i < $found_rows / $limit; $i++) { + echo ($i == $_GET["page"] ? $i + 1 : '' . ($i + 1) . "") . "\n"; + } + echo "

\n"; + } +} +mysql_free_result($result); diff --git a/sql.inc.php b/sql.inc.php new file mode 100644 index 00000000..20855a7c --- /dev/null +++ b/sql.inc.php @@ -0,0 +1,38 @@ +" . lang('SQL command') . "\n"; + +if ($_POST) { + if (!$result) { + echo "

" . lang('Error in query') . ": $error

\n"; + } else { + //! no rows + echo "\n"; + for ($i=0; $row = mysql_fetch_assoc($result); $i++) { + if (!$i) { + echo "\n"; + } + echo ""; + foreach ($row as $val) { + echo ""; + } + echo "\n"; + } + echo "
" . implode("", array_map('htmlspecialchars', array_keys($row))) . "
" . (isset($val) ? htmlspecialchars($val) : "NULL") . "
\n"; + mysql_free_result($result); + } +} +?> +
+

+

+
diff --git a/table.inc.php b/table.inc.php new file mode 100644 index 00000000..9098f9f1 --- /dev/null +++ b/table.inc.php @@ -0,0 +1,36 @@ +" . lang('Table') . ": " . htmlspecialchars($_GET["table"]) . "\n"; + +$result = mysql_query("SHOW FULL COLUMNS FROM " . idf_escape($_GET["table"])); +echo "\n"; +while ($row = mysql_fetch_assoc($result)) { + echo "\n"; +} +echo "
" . htmlspecialchars($row["Field"]) . "$row[Type]" . ($row["Null"] == "NO" ? " NOT NULL" : "") . "
\n"; +mysql_free_result($result); +echo '

' . lang('Alter table') . "

\n"; + +$indexes = indexes($_GET["table"]); +if ($indexes) { + echo "

" . lang('Indexes') . "

\n"; + echo "\n"; + foreach ($indexes as $type => $index) { + foreach ($index as $columns) { + sort($columns); + echo "\n"; + } + } + echo "
$type" . implode(", ", $columns) . "
\n"; +} + +$result = mysql_query("SHOW TRIGGERS LIKE '" . mysql_real_escape_string($_GET["table"]) . "'"); +if (mysql_num_rows($result)) { + echo "

" . lang('Triggers') . "

\n"; + echo "\n"; + while ($row = mysql_fetch_assoc($result)) { + echo "\n"; + } + echo "
$row[Timing]$row[Event]" . htmlspecialchars($row["Statement"]) . "
\n"; +} +mysql_free_result($result); diff --git a/view.inc.php b/view.inc.php new file mode 100644 index 00000000..e69de29b