1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-16 19:44:00 +02:00

Bulk clone

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@526 7c3ca157-0c34-0410-bff1-cbf682f78f5c
This commit is contained in:
jakubvrana
2008-10-09 13:23:54 +00:00
parent b8ff2dfa6e
commit 820c88203d
5 changed files with 24 additions and 25 deletions

View File

@@ -49,12 +49,11 @@ if ($_POST) {
$select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name); $select[] = ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "") . idf_escape($name);
} }
} }
$row = array();
if ($select) { if ($select) {
$result = $mysql->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1"); $result = $mysql->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1");
$row = $result->fetch_assoc(); $row = $result->fetch_assoc();
$result->free(); $result->free();
} else {
$row = array();
} }
} }
?> ?>
@@ -66,13 +65,11 @@ if ($fields) {
echo "<table border='0' cellspacing='0' cellpadding='2'>\n"; echo "<table border='0' cellspacing='0' cellpadding='2'>\n";
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
echo "<tr><th>" . htmlspecialchars($name) . "</th><td>"; echo "<tr><th>" . htmlspecialchars($name) . "</th><td>";
if (!isset($row)) { $value = (!isset($row) ? $field["default"] :
$value = $field["default"]; (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) :
} elseif (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set")) { ($_POST["clone"] && $field["auto_increment"] ? "" :
$value = intval($row[$name]); $row[$name]
} else { )));
$value = $row[$name];
}
input($name, $field, $value); input($name, $field, $value);
if (isset($_GET["default"]) && $field["type"] == "timestamp") { if (isset($_GET["default"]) && $field["type"] == "timestamp") {
if (!isset($create) && !$_POST) { if (!isset($create) && !$_POST) {
@@ -91,10 +88,8 @@ if ($fields) {
<input type="hidden" name="token" value="<?php echo $token; ?>" /> <input type="hidden" name="token" value="<?php echo $token; ?>" />
<?php <?php
if (isset($_GET["select"])) { if (isset($_GET["select"])) {
foreach ((array) $_POST["check"] as $val) { hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
echo '<input type="hidden" name="check[]" value="' . htmlspecialchars($val) . '" />'; echo "<input type='hidden' name='save' value='1' />\n";
}
echo ($_POST["all"] ? "<input type='hidden' name='all' value='1' />\n" : "\n");
} }
if ($fields) { if ($fields) {
?> ?>

View File

@@ -341,7 +341,7 @@ function table_comment(&$row) {
} }
} }
function hidden_fields($process, $ignore) { function hidden_fields($process, $ignore = array()) {
while (list($key, $val) = each($process)) { while (list($key, $val) = each($process)) {
if (is_array($val)) { if (is_array($val)) {
foreach ($val as $k => $v) { foreach ($val as $k => $v) {

View File

@@ -99,7 +99,7 @@ if (isset($_GET["download"])) {
if (isset($_GET["default"])) { if (isset($_GET["default"])) {
$_GET["edit"] = $_GET["default"]; $_GET["edit"] = $_GET["default"];
} }
if (isset($_GET["select"]) && $_POST["edit"]) { if (isset($_GET["select"]) && $_POST && (!$_POST["delete"] && !$_POST["export"] && !$_POST["save"])) {
$_GET["edit"] = $_GET["select"]; $_GET["edit"] = $_GET["select"];
} }
if (isset($_GET["callf"])) { if (isset($_GET["callf"])) {
@@ -108,6 +108,9 @@ if (isset($_GET["download"])) {
if (isset($_GET["function"])) { if (isset($_GET["function"])) {
$_GET["procedure"] = $_GET["function"]; $_GET["procedure"] = $_GET["function"];
} }
if (isset($_GET["clone"])) {
$_GET["edit"] = $_GET["clone"];
}
if (isset($_GET["sql"])) { if (isset($_GET["sql"])) {
include "./sql.inc.php"; include "./sql.inc.php";
} elseif (isset($_GET["edit"])) { } elseif (isset($_GET["edit"])) {

View File

@@ -149,7 +149,6 @@ $translations = array(
'Routine' => 'Procedura', 'Routine' => 'Procedura',
'Grant' => 'Povolit', 'Grant' => 'Povolit',
'Revoke' => 'Zakázat', 'Revoke' => 'Zakázat',
'Error during deleting' => 'Chyba při mazání',
'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".', 'Too big POST data. Reduce the data or increase the "post_max_size" configuration directive.' => 'Příliš velká POST data. Zmenšete data nebo zvyšte hodnotu konfigurační direktivy "post_max_size".',
'Logged as: %s' => 'Přihlášen jako: %s', 'Logged as: %s' => 'Přihlášen jako: %s',
'Move up' => 'Přesunout nahoru', 'Move up' => 'Přesunout nahoru',
@@ -167,8 +166,6 @@ $translations = array(
'Tables' => 'Tabulky', 'Tables' => 'Tabulky',
'Structure' => 'Struktura', 'Structure' => 'Struktura',
'Data' => 'Data', 'Data' => 'Data',
// 'Export selected' => 'Exportovat označené',
// 'Export result' => 'Exportovat výsledek',
'Event has been dropped.' => 'Událost byla odstraněna.', 'Event has been dropped.' => 'Událost byla odstraněna.',
'Event has been altered.' => 'Událost byla změněna.', 'Event has been altered.' => 'Událost byla změněna.',
'Event has been created.' => 'Událost byla vytvořena.', 'Event has been created.' => 'Událost byla vytvořena.',
@@ -205,4 +202,5 @@ $translations = array(
'%d item(s) have been affected.' => array('Byl ovlivněn %d záznam.', 'Byly ovlivněny %d záznamy.', 'Bylo ovlivněno %d záznamů.'), '%d item(s) have been affected.' => array('Byl ovlivněn %d záznam.', 'Byly ovlivněny %d záznamy.', 'Bylo ovlivněno %d záznamů.'),
'whole result' => 'celý výsledek', 'whole result' => 'celý výsledek',
'Tables have been dropped.' => 'Tabulky byla odstraněny.', 'Tables have been dropped.' => 'Tabulky byla odstraněny.',
'Clone' => 'Klonovat',
); );

View File

@@ -67,8 +67,6 @@ $limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
$from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : ""); $from = "FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
if ($_POST && !$error) { if ($_POST && !$error) {
$result = true;
$affected = 0;
if ($_POST["export"]) { if ($_POST["export"]) {
dump_headers($_GET["select"]); dump_headers($_GET["select"]);
dump_table($_GET["select"], ""); dump_table($_GET["select"], "");
@@ -82,16 +80,20 @@ if ($_POST && !$error) {
} }
exit; exit;
} }
$command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : "UPDATE ") . idf_escape($_GET["select"]); $result = true;
$affected = 0;
$command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
if (!$_POST["delete"]) { if (!$_POST["delete"]) {
$set = array(); $set = array();
foreach ($fields as $name => $field) { foreach ($fields as $name => $field) {
$val = process_input($name, $field); $val = process_input($name, $field);
if ($val !== false) { if ($_POST["clone"]) {
$set[] = ($val !== false ? $val : idf_escape($name));
} elseif ($val !== false) {
$set[] = idf_escape($name) . " = $val"; $set[] = idf_escape($name) . " = $val";
} }
} }
$command .= " SET " . implode(", ", $set); $command .= ($_POST["clone"] ? " SELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET " . implode(", ", $set));
} }
if (!$_POST["delete"] && !$set) { if (!$_POST["delete"] && !$set) {
// nothing // nothing
@@ -109,8 +111,9 @@ if ($_POST && !$error) {
} }
} }
query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result); query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
//! display edit page in case of an error
} }
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), ($error ? lang('Error during deleting') . ": $error" : "")); page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), $error);
if (isset($rights["insert"])) { if (isset($rights["insert"])) {
//! pass search values forth and back //! pass search values forth and back
@@ -297,7 +300,7 @@ for (var i=0; <?php echo $i; ?> > i; i++) {
} }
echo " (" . lang('%d row(s)', $found_rows) . ")</p>\n"; echo " (" . lang('%d row(s)', $found_rows) . ")</p>\n";
echo "<fieldset><legend>" . lang('Edit') . "</legend><input type='hidden' name='token' value='$token' /><input type='submit' name='edit' value='" . lang('Edit') . "' /> <input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return !this.form['all'].checked || confirm('" . lang('Are you sure?') . "');\" /></fieldset>\n"; echo "<fieldset><legend>" . lang('Edit') . "</legend><input type='hidden' name='token' value='$token' /><input type='submit' value='" . lang('Edit') . "' /> <input type='submit' name='clone' value='" . lang('Clone') . "' /> <input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return !this.form['all'].checked || confirm('" . lang('Are you sure?') . "');\" /></fieldset>\n";
echo "<fieldset><legend>" . lang('Export') . "</legend>$dump_options <input type='submit' name='export' value='" . lang('Export') . "' /></fieldset>\n"; echo "<fieldset><legend>" . lang('Export') . "</legend>$dump_options <input type='submit' name='export' value='" . lang('Export') . "' /></fieldset>\n";
echo "</form>\n"; echo "</form>\n";
} }