From 430034c38a4f4e4dad69d2d2928582b3984bba21 Mon Sep 17 00:00:00 2001
From: jakubvrana
Date: Mon, 9 Jul 2007 06:12:22 +0000
Subject: [PATCH] Cottage homework
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@77 7c3ca157-0c34-0410-bff1-cbf682f78f5c
---
_compile.php | 1 +
_lang.php | 19 ++++---
auth.inc.php | 15 ++++--
connect.inc.php | 1 -
create.inc.php | 54 ++++++++++++-------
database.inc.php | 3 +-
design.inc.php | 14 ++---
download.inc.php | 3 ++
dump.inc.php | 18 ++++---
edit.inc.php | 135 ++++++++++++++++++++++++++++------------------
functions.inc.php | 122 +++++++++++++++++++++++++++++++++++------
index.php | 17 +++---
indexes.inc.php | 4 +-
lang.inc.php | 55 ++++++++++++++-----
select.inc.php | 59 +++++++++++++-------
sql.inc.php | 77 ++++++++++++++++----------
table.inc.php | 12 ++++-
view.inc.php | 2 +-
18 files changed, 420 insertions(+), 191 deletions(-)
create mode 100644 download.inc.php
diff --git a/_compile.php b/_compile.php
index 00ee2236..55e223a3 100644
--- a/_compile.php
+++ b/_compile.php
@@ -38,6 +38,7 @@ $file = preg_replace_callback('~(<\\?php)?\\s*(include|require)(_once)? "([^"]*)
if ($_SESSION["lang"]) {
$file = preg_replace_callback("~(<\\?php\\s*echo )?lang\\('((?:[^\\\\']*|\\\\.)+)'\\)(;\\s*\\?>)?~s", 'remove_lang', $file);
$file = str_replace("\n", "", $file);
+ $file = str_replace("", $_SESSION["lang"], $file);
}
//! remove spaces and comments
file_put_contents($filename, $file);
diff --git a/_lang.php b/_lang.php
index e0a717d3..f82324cb 100644
--- a/_lang.php
+++ b/_lang.php
@@ -4,17 +4,18 @@ if ($_SERVER["argc"] > 1) {
exit(1);
}
-$messages = array();
+$messages_all = array();
foreach (glob("*.php") as $filename) {
$file = file_get_contents($filename);
- preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')\\)~s", $file, $matches);
- $messages += array_flip($matches[1]);
+ preg_match_all("~lang\\(('(?:[^\\\\']*|\\\\.)+')[),]~s", $file, $matches);
+ $messages_all += array_flip($matches[1]);
}
$file = file_get_contents("lang.inc.php");
-preg_match_all("~\n\t\t'.*' => array\\(\n(.*\n)\t\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
-foreach ($translations[1] as $translation) {
- preg_match_all("~^(\\s*(?:// )?)(('(?:[^\\\\']*|\\\\.)+') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
+preg_match_all("~\n\t\t'(.*)' => array\\(\n(.*\n)\t\t\\)~sU", $file, $translations, PREG_OFFSET_CAPTURE);
+foreach (array_reverse($translations[2], true) as $key => $translation) {
+ $messages = $messages_all;
+ preg_match_all("~^(\\s*)(?:// )?(('(?:[^\\\\']*|\\\\.)+') => .*[^,\n]),?~m", $translation[0], $matches, PREG_SET_ORDER);
$s = "";
foreach ($matches as $match) {
if (isset($messages[$match[3]])) {
@@ -24,8 +25,10 @@ foreach ($translations[1] as $translation) {
$s .= "$match[1]// $match[2],\n";
}
}
- foreach($messages as $key => $val) {
- $s .= "\t\t\t$key => '',\n";
+ if ($translations[1][$key][0] != 'en') {
+ foreach($messages as $key => $val) {
+ $s .= "\t\t\t$key => '',\n";
+ }
}
$file = substr_replace($file, $s, $translation[1], strlen($translation[0]));
}
diff --git a/auth.inc.php b/auth.inc.php
index 7a5a74ef..e15ec934 100644
--- a/auth.inc.php
+++ b/auth.inc.php
@@ -11,6 +11,7 @@ if (isset($_POST["server"])) {
} elseif (isset($_GET["logout"])) {
unset($_SESSION["usernames"][$_GET["server"]]);
unset($_SESSION["passwords"][$_GET["server"]]);
+ $_SESSION["tokens"][$_GET["server"]] = array();
}
$username = $_SESSION["usernames"][$_GET["server"]];
@@ -18,8 +19,9 @@ $password = $_SESSION["passwords"][$_GET["server"]];
if (isset($_GET["logout"]) || !@mysql_connect(
(strlen($_GET["server"]) ? $_GET["server"] : ini_get("mysql.default_host")),
(strlen("$_GET[server]$username") ? $username : ini_get("mysql.default_user")),
- (strlen("$_GET[server]$username$password") ? $password : ini_get("mysql.default_password")))
-) {
+ (strlen("$_GET[server]$username$password") ? $password : ini_get("mysql.default_password")),
+ false, 131072 // CLIENT_MULTI_RESULTS for CALL
+)) {
page_header(lang('Login'));
if (isset($_GET["logout"])) {
echo "" . lang('Logout successful.') . "
\n";
@@ -30,17 +32,17 @@ if (isset($_GET["logout"]) || !@mysql_connect(
diff --git a/connect.inc.php b/connect.inc.php
index 6136c77c..33deffb2 100644
--- a/connect.inc.php
+++ b/connect.inc.php
@@ -10,4 +10,3 @@ if (!(strlen($_GET["db"]) ? mysql_select_db($_GET["db"]) : isset($_GET["sql"]) |
exit;
}
mysql_query("SET CHARACTER SET utf8");
-mysql_query("SET SQL_QUOTE_SHOW_CREATE=1");
diff --git a/create.inc.php b/create.inc.php
index 2c0d6877..7605e4d0 100644
--- a/create.inc.php
+++ b/create.inc.php
@@ -1,7 +1,7 @@
" . lang('Unable to operate table') . ": " . htmlspecialchars($error) . "
\n";
}
$row = $_POST;
+ if ($row["auto_increment"]) {
+ $row["fields"][$row["auto_increment"]]["auto_increment"] = true;
+ }
} elseif (strlen($_GET["create"])) {
$row = mysql_fetch_assoc(mysql_query("SHOW TABLE STATUS LIKE '" . mysql_real_escape_string($_GET["create"]) . "'"));
$row["name"] = $_GET["create"];
@@ -64,7 +71,9 @@ if ($_POST) {
} else {
$row = array("fields" => array());
}
-//! default, comments
+if (!$_POST || $_POST["add"]) {
+ $row["fields"][] = array();
+}
$collations = collations();
?>
diff --git a/design.inc.php b/design.inc.php
index 89eae22f..e89ff01e 100644
--- a/design.inc.php
+++ b/design.inc.php
@@ -3,7 +3,7 @@ function page_header($title) {
header("Content-Type: text/html; charset=utf-8");
?>
-
+
@@ -14,7 +14,7 @@ A:visited { color: Navy; }
H1 { font-size: 150%; margin: 0; }
H2 { font-size: 150%; margin-top: 0; }
FIELDSET { float: left; padding: .5em; margin: 0; }
-PRE { margin: 0; font-family: serif; }
+PRE { margin: 0; margin: .12em 0; }
.error { color: Red; }
.message { color: Green; }
#menu { position: absolute; top: 8px; left: 8px; width: 15em; overflow: auto; white-space: nowrap; }
@@ -63,18 +63,18 @@ function page_footer($missing = false) {
" . lang('No tables.') . "\n";
} else {
echo "\n";
- while ($row = mysql_fetch_row($result)) {
- echo '' . lang('select') . ' ';
- echo '' . htmlspecialchars($row[0]) . "
\n"; //! views
+ while ($row = mysql_fetch_assoc($result)) {
+ echo '' . lang('select') . ' ';
+ echo '' . htmlspecialchars($row["Name"]) . "
\n";
}
echo "
\n";
}
- echo '' . lang('Create new table') . "
\n"; //! rights
+ echo '' . lang('Create new table') . "
\n";
mysql_free_result($result);
}
}
diff --git a/download.inc.php b/download.inc.php
new file mode 100644
index 00000000..6d4748e0
--- /dev/null
+++ b/download.inc.php
@@ -0,0 +1,3 @@
+ $val) {
- $where[] = idf_escape($key) . " = BINARY '" . mysql_real_escape_string($val) . "'"; //! enum and set
+$where = where();
+$fields = array();
+foreach (fields($_GET["edit"]) as $name => $field) {
+ if (isset($_GET["default"]) ? !$field["auto_increment"] : isset($field["privileges"][$where ? "update" : "insert"])) {
+ $fields[$name] = $field;
+ }
}
-foreach ((array) $_GET["null"] as $key) {
- $where[] = idf_escape($key) . " IS NULL";
-}
-if ($_POST) {
+if ($_POST && !$error) {
if (isset($_POST["delete"])) {
+ $set = true;
$query = "DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been deleted.');
} else {
$set = array();
- foreach ($_POST["fields"] as $key => $val) {
- $name = bracket_escape($key, "back");
- $field = $fields[$name];
- if (preg_match('~char|text|set~', $field["type"]) ? $_POST["null"][$key] : !strlen($val)) {
+ foreach ($fields as $name => $field) {
+ $key = bracket_escape($name);
+ $val = $_POST["fields"][$key];
+ if (preg_match('~char|text|set|binary|blob~', $field["type"]) ? $_POST["null"][$key] : !strlen($val)) {
$val = "NULL";
} elseif ($field["type"] == "enum") {
- $val = intval($val);
+ $val = (isset($_GET["default"]) && preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches) ? "'" . $matches[1][$val-1] . "'" : intval($val));
} elseif ($field["type"] == "set") {
- $val = array_sum((array) $val);
+ if (!isset($_GET["default"])) {
+ $val = array_sum((array) $val);
+ } else {
+ preg_match_all("~'((?:[^']*|'')+)'~", $field["length"], $matches);
+ $value = array();
+ foreach ((array) $val as $key => $v) {
+ $value[] = $matches[1][$key];
+ }
+ $val = "'" . implode(",", $value) . "'";
+ }
+ } elseif (preg_match('~binary|blob~', $field["type"])) {
+ $file = get_file($key);
+ if (!is_string($file) && !$field["null"]) {
+ continue; //! report errors, also empty $_POST - not only because of file upload
+ }
+ $val = "_binary'" . (is_string($file) ? mysql_real_escape_string($file) : "") . "'";
} else {
$val = "'" . mysql_real_escape_string($val) . "'";
}
- $set[] = idf_escape($name) . " = $val";
+ $set[] = idf_escape($name) . (isset($_GET["default"]) ? ($val == "NULL" ? " DROP DEFAULT" : " SET DEFAULT $val") : " = $val");
}
- if ($where) {
+ if (isset($_GET["default"])) {
+ $query = "ALTER TABLE " . idf_escape($_GET["edit"]) . " ALTER " . implode(", ALTER ", $set);
+ $message = lang('Default values has been set.');
+ } elseif ($where) {
$query = "UPDATE " . idf_escape($_GET["edit"]) . " SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $where) . " LIMIT 1";
$message = lang('Item has been updated.');
} else {
@@ -35,69 +53,82 @@ if ($_POST) {
$message = lang('Item has been inserted.');
}
}
- if (mysql_query($query)) {
- redirect($SELF . ($_POST["insert"] ? "edit=" : "select=") . urlencode($_GET["edit"]), $message);
+ if (!$set || mysql_query($query)) {
+ redirect($SELF . (isset($_GET["default"]) ? "table=" : ($_POST["insert"] ? "edit=" : "select=")) . urlencode($_GET["edit"]), ($set ? $message : null));
}
$error = mysql_error();
}
-page_header(($_GET["where"] ? lang('Edit') : lang('Insert')) . ": " . htmlspecialchars($_GET["edit"]));
+page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))) . ": " . htmlspecialchars($_GET["edit"]));
if ($_POST) {
echo "" . lang('Error during saving') . ": " . htmlspecialchars($error) . "
\n";
- $data = $_POST["fields"];
- foreach ($_POST["null"] as $key => $val) {
+ $data = (array) $_POST["fields"];
+ foreach ((array) $_POST["null"] as $key => $val) {
$data[$key] = null;
}
} elseif ($where) {
$select = array();
foreach ($fields as $name => $field) {
- if (in_array("select", $field["privileges"]) && in_array(($where ? "update" : "insert"), $field["privileges"])) {
+ if (isset($field["privileges"]["select"]) && !preg_match('~binary|blob~', $field["type"])) {
$select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name);
}
}
$data = ($select ? mysql_fetch_assoc(mysql_query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1")) : array());
} else {
- $data = array();
+ unset($data);
}
?>
-
diff --git a/lang.inc.php b/lang.inc.php
index d39ceade..644e6d00 100644
--- a/lang.inc.php
+++ b/lang.inc.php
@@ -1,7 +1,25 @@
array(),
+ 'en' => array(
+ 'Query executed OK, %d row(s) affected.' => array('Query executed OK, %d row affected.', 'Query executed OK, %d rows affected.'),
+ '%d byte(s)' => array('%d byte', '%d bytes'),
+ ),
'cs' => array(
'Login' => 'Přihlásit se',
'phpMinAdmin' => 'phpMinAdmin',
@@ -26,7 +44,7 @@ function lang($idf = null) {
'Type' => 'Typ',
'Length' => 'Délka',
'NULL' => 'NULL',
- 'Auto-increment' => 'Auto-increment',
+ 'Auto Increment' => 'Auto Increment',
'Options' => 'Volby',
'Add row' => 'Přidat řádek',
'Save' => 'Uložit',
@@ -72,7 +90,7 @@ function lang($idf = null) {
'Action' => 'Akce',
'edit' => 'upravit',
'Page' => 'Stránka',
- 'Query executed OK, %d row(s) affected.' => 'Příkaz proběhl v pořádku, bylo změněno %d záznam(ů).',
+ 'Query executed OK, %d row(s) affected.' => array('Příkaz proběhl v pořádku, byl změněn %d záznam.', 'Příkaz proběhl v pořádku, byly změněny %d záznamy.', 'Příkaz proběhl v pořádku, bylo změněno %d záznamů.'),
'Error in query' => 'Chyba v dotazu',
'Execute' => 'Provést',
'Table' => 'Tabulka',
@@ -81,23 +99,34 @@ function lang($idf = null) {
'View' => 'Pohled',
'Unable to select the table' => 'Nepodařilo se vypsat tabulku',
'Unable to show the table definition' => 'Nepodařilo se získat strukturu tabulky',
+ 'Invalid CSRF token. Send the form again.' => 'Neplatný token CSRF. Odešlete formulář znovu.',
+ 'Comment' => 'Komentář',
+ 'Default values has been set.' => 'Výchozí hodnoty byly nastaveny.',
+ 'Default values' => 'Výchozí hodnoty',
+ 'BOOL' => 'BOOL',
+ 'Show column comments' => 'Zobrazit komentáře sloupců',
+ '%d byte(s)' => array('%d bajt', '%d bajty', '%d bajtů'),
+ 'No commands to execute.' => 'Žádné příkazy k vykonání.',
+ 'Unable to upload a file.' => 'Nepodařilo se nahrát soubor.',
+ 'File upload' => 'Nahrání souboru',
+ 'File uploads are disabled.' => 'Nahrávání souborů není povoleno.',
),
);
if (!isset($idf)) {
return array_keys($translations);
}
- if (strlen($_SESSION["lang"])) {
- $lang = $_SESSION["lang"];
- } else {
- $lang = preg_replace('~[,;].*~', '', $_SERVER["HTTP_ACCEPT_LANGUAGE"]);
- if (!isset($translations[$lang])) { //! try next languages
- $lang = preg_replace('~-.*~', '', $lang);
- if (!isset($translations[$lang])) {
- $lang = "en";
- }
+ $lang = get_lang();
+ $translation = $translations[$lang][$idf];
+ $args = func_get_args();
+ if (is_array($translation)) {
+ switch ($lang) {
+ case 'cs': $pos = ($args[1] == 1 ? 0 : (!$args[1] || $args[1] >= 5 ? 2 : 1)); break;
+ default: $pos = ($args[1] == 1 ? 0 : 1);
}
+ $translation = $translation[$pos];
}
- return (strlen($translations[$lang][$idf]) ? $translations[$lang][$idf] : $idf);
+ $args[0] = (strlen($translation) ? $translation : $idf);
+ return call_user_func_array('sprintf', $args);
}
function switch_lang() {
diff --git a/select.inc.php b/select.inc.php
index e70ca4d0..b3a2acfb 100644
--- a/select.inc.php
+++ b/select.inc.php
@@ -1,18 +1,23 @@
' . lang('New item') . "\n";
$fields = fields($_GET["select"]);
+$rights = array();
$columns = array();
foreach ($fields as $key => $field) {
- if (in_array("select", $field["privileges"])) {
+ if (isset($field["privileges"]["select"])) {
$columns[] = $key;
}
+ $rights += $field["privileges"];
+}
+
+if (isset($rights["insert"])) {
+ echo '' . lang('New item') . "
\n";
}
if (!$columns) {
echo "" . lang('Unable to select the table') . ($fields ? "" : ": " . mysql_error()) . ".
\n";
} else {
+ $indexes = indexes($_GET["select"]);
echo "