Permalink
Browse files

Function results in edit

Bulk edit
Remove <label for>
Simplify optionlist()
Only one button for each action in select

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@508 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 4bee1c0 commit 78639a98ca813dd86f2bce3b4b061182d6d323d9 jakubvrana committed Oct 1, 2008
Showing with 105 additions and 92 deletions.
  1. +1 −1 create.inc.php
  2. +14 −10 edit.inc.php
  3. +38 −26 editing.inc.php
  4. +2 −3 functions.inc.php
  5. +3 −0 index.php
  6. +5 −6 lang/cs.inc.php
  7. +1 −1 lang/en.inc.php
  8. +38 −40 select.inc.php
  9. +1 −1 sql.inc.php
  10. +1 −3 todo.txt
  11. +1 −1 user.inc.php
View
@@ -97,7 +97,7 @@
<?php echo lang('Auto Increment'); ?>: <input name="Auto_increment" size="4" value="<?php echo intval($row["Auto_increment"]); ?>" />
<?php echo lang('Comment'); ?>: <input name="Comment" value="<?php echo htmlspecialchars($row["Comment"]); ?>" maxlength="60" />
<script type="text/javascript">// <![CDATA[
-document.write('<label for="column_comments"><input type="checkbox" id="column_comments"<?php if ($column_comments) { ?> checked="checked"<?php } ?> onclick="column_comments_click(this.checked);" /><?php echo lang('Show column comments'); ?></label>');
+document.write('<label><input type="checkbox"<?php if ($column_comments) { ?> checked="checked"<?php } ?> onclick="column_comments_click(this.checked);" /><?php echo lang('Show column comments'); ?></label>');
function column_comments_click(checked) {
var trs = document.getElementsByTagName('tr');
for (var i=0; i < trs.length; i++) {
View
@@ -1,13 +1,13 @@
<?php
-$where = where($_GET);
+$where = (isset($_GET["select"]) ? array() : where($_GET));
$update = ($where && !$_GET["clone"]);
$fields = fields($_GET["edit"]);
foreach ($fields as $name => $field) {
if (isset($_GET["default"]) ? $field["auto_increment"] || preg_match('~text|blob~', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) {
unset($fields[$name]);
}
}
-if ($_POST && !$error) {
+if ($_POST && !$error && !isset($_GET["select"])) {
$location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"]));
if (isset($_POST["delete"])) {
query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE " . implode(" AND ", $where) . " LIMIT 1", $location, lang('Item has been deleted.'));
@@ -37,14 +37,11 @@
}
}
}
-page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
+page_header((isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || isset($_GET["select"]) ? lang('Edit') : lang('Insert'))), $error, array((isset($_GET["default"]) ? "table" : "select") => $_GET["edit"]), $_GET["edit"]);
unset($row);
if ($_POST) {
$row = (array) $_POST["fields"];
- foreach ((array) $_POST["null"] as $key => $val) {
- $row[$key] = null;
- }
} elseif ($where) {
$select = array();
foreach ($fields as $name => $field) {
@@ -78,13 +75,12 @@
}
input($name, $field, $value);
if (isset($_GET["default"]) && $field["type"] == "timestamp") {
- $id = htmlspecialchars("on_update-$name");
if (!isset($create) && !$_POST) {
//! disable sql_mode NO_FIELD_OPTIONS
$create = $mysql->result($mysql->query("SHOW CREATE TABLE " . idf_escape($_GET["edit"])), 1);
}
$checked = ($_POST ? $_POST["on_update"][bracket_escape($name)] : preg_match("~\n\\s*" . preg_quote(idf_escape($name), '~') . " timestamp.* on update CURRENT_TIMESTAMP~i", $create));
- echo '<label for="' . $id . '"><input type="checkbox" name="on_update[' . htmlspecialchars(bracket_escape($name)) . ']" id="' . $id . '" value="1"' . ($checked ? ' checked="checked"' : '') . ' />' . lang('ON UPDATE CURRENT_TIMESTAMP') . '</label>';
+ echo '<label><input type="checkbox" name="on_update[' . htmlspecialchars(bracket_escape($name)) . ']" value="1"' . ($checked ? ' checked="checked"' : '') . ' />' . lang('ON UPDATE CURRENT_TIMESTAMP') . '</label>';
}
echo "</td></tr>\n";
}
@@ -93,9 +89,17 @@
?>
<p>
<input type="hidden" name="token" value="<?php echo $token; ?>" />
-<?php if ($fields) { ?>
+<?php
+if (isset($_GET["select"])) {
+ foreach ((array) $_POST["check"] as $val) {
+ echo '<input type="hidden" name="check[]" value="' . htmlspecialchars($val) . '" />';
+ }
+ echo ($_POST["all"] ? "<input type='hidden' name='all' value='1' />\n" : "\n");
+}
+if ($fields) {
+ ?>
<input type="submit" value="<?php echo lang('Save'); ?>" />
-<?php if (!isset($_GET["default"])) { ?><input type="submit" name="insert" value="<?php echo ($update ? lang('Save and continue edit') : lang('Save and insert next')); ?>" /><?php } ?>
+<?php if (!isset($_GET["default"]) && !isset($_GET["select"])) { ?><input type="submit" name="insert" value="<?php echo ($update ? lang('Save and continue edit') : lang('Save and insert next')); ?>" /><?php } ?>
<?php } ?>
<?php if ($update) { ?> <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?>');" /><?php } ?>
</p>
View
@@ -2,61 +2,73 @@
function input($name, $field, $value) {
global $types;
$name = htmlspecialchars(bracket_escape($name));
- $onchange = ($field["null"] ? ' onchange="this.form[\'null[' . addcslashes($name, "\r\n'\\") . ']\'].checked = false;"' : '');
if ($field["type"] == "enum") {
+ if (isset($_GET["select"])) {
+ echo ' <label><input type="radio" name="fields[' . $name . ']" value="-1" checked="checked" /><em>' . lang('original') . '</em></label>';
+ }
+ if ($field["null"]) {
+ echo ' <label><input type="radio" name="fields[' . $name . ']" value=""' . (isset($value) || isset($_GET["select"]) ? '' : ' checked="checked"') . ' /><em>NULL</em></label>';
+ }
if (!isset($_GET["default"])) {
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) {
$val = stripcslashes(str_replace("''", "'", $val));
- $id = "field-$name-" . ($i+1);
$checked = (is_int($value) ? $value == $i+1 : $value === $val);
- echo ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? (strlen($val) ? htmlspecialchars($val) : " ") : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . ' />' . htmlspecialchars($val) . '</label>';
+ echo ' <label><input type="radio" name="fields[' . $name . ']" value="' . (isset($_GET["default"]) ? (strlen($val) ? htmlspecialchars($val) : " ") : $i+1) . '"' . ($checked ? ' checked="checked"' : '') . ' />' . htmlspecialchars($val) . '</label>';
}
+ } else {
+ $first = (isset($_GET["select"]) ? 2 : 1);
+ $onchange = ($field["null"] || isset($_GET["select"]) ? ' onchange="var f = this.form[\'function[' . addcslashes($name, "\r\n'\\") . ']\']; f.selectedIndex = Math.max(f.selectedIndex, ' . $first . ');"' : '');
+ $options = (preg_match('~char~', $field["type"]) ? array("", "md5", "sha1", "password", "uuid") : (preg_match('~date|time~', $field["type"]) ? array("", "now") : array("")));
if ($field["null"]) {
- $id = "field-$name-";
- echo ' <label for="' . $id . '"><input type="radio" name="fields[' . $name . ']" id="' . $id . '" value=""' . (isset($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
+ array_unshift($options, "NULL");
}
- } elseif ($field["type"] == "set") { //! 64 bits
- preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
- foreach ($matches[1] as $i => $val) {
- $val = stripcslashes(str_replace("''", "'", $val));
- $id = "field-$name-" . ($i+1);
- $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
- echo ' <input type="checkbox" name="fields[' . $name . '][' . $i . ']" id="' . $id . '" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : 1 << $i) . '"' . ($checked ? ' checked="checked"' : '') . $onchange . ' /><label for="' . $id . '">' . htmlspecialchars($val) . '</label>';
+ if (count($options) > 1 || isset($_GET["select"])) {
+ echo '<select name="function[' . $name . ']">' . (isset($_GET["select"]) ? '<option value="orig">' . lang('original') . '</option>' : '') . optionlist($options, (isset($value) ? (string) $_POST["function"][$name] : null)) . '</select>';
+ }
+ if ($field["type"] == "set") { //! 64 bits
+ preg_match_all("~'((?:[^']+|'')*)'~", $field["length"], $matches);
+ foreach ($matches[1] as $i => $val) {
+ $val = stripcslashes(str_replace("''", "'", $val));
+ $checked = (is_int($value) ? ($value >> $i) & 1 : in_array($val, explode(",", $value), true));
+ echo ' <label><input type="checkbox" name="fields[' . $name . '][' . $i . ']" value="' . (isset($_GET["default"]) ? htmlspecialchars($val) : 1 << $i) . '"' . ($checked ? ' checked="checked"' : '') . $onchange . ' />' . htmlspecialchars($val) . '</label>';
+ }
+ } elseif (strpos($field["type"], "text") !== false) {
+ echo '<textarea name="fields[' . $name . ']" cols="50" rows="12"' . $onchange . '>' . htmlspecialchars($value) . '</textarea>';
+ } elseif (preg_match('~binary|blob~', $field["type"])) {
+ echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '"' . $onchange . ' />' : lang('File uploads are disabled.') . ' ');
+ } else {
+ echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? " maxlength='" . ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) . "'" : ($types[$field["type"]] ? " maxlength='" . $types[$field["type"]] . "'" : '')) . $onchange . ' />';
}
- } elseif (strpos($field["type"], "text") !== false) {
- echo '<textarea name="fields[' . $name . ']" cols="50" rows="12"' . $onchange . '>' . htmlspecialchars($value) . '</textarea>';
- } elseif (preg_match('~binary|blob~', $field["type"])) {
- echo (ini_get("file_uploads") ? '<input type="file" name="' . $name . '"' . $onchange . ' />' : lang('File uploads are disabled.') . ' ');
- } else {
- echo '<input name="fields[' . $name . ']" value="' . htmlspecialchars($value) . '"' . (preg_match('~^([0-9]+)(,([0-9]+))?$~', $field["length"], $match) ? " maxlength='" . ($match[1] + ($match[3] ? 1 : 0) + ($match[2] && !$field["unsigned"] ? 1 : 0)) . "'" : ($types[$field["type"]] ? " maxlength='" . $types[$field["type"]] . "'" : '')) . $onchange . ' />';
- }
- if ($field["null"] && $field["type"] != "enum") {
- $id = "null-$name";
- echo '<label for="' . $id . '"><input type="checkbox" name="null[' . $name . ']" value="1" id="' . $id . '"' . (isset($value) ? '' : ' checked="checked"') . ' />' . lang('NULL') . '</label>';
}
}
function process_input($name, $field) {
global $mysql;
- $name = bracket_escape($name);
- $value = $_POST["fields"][$name];
- if ($field["type"] != "enum" && !$field["auto_increment"] ? $_POST["null"][$name] : !strlen($value)) {
+ $idf = bracket_escape($name);
+ $value = $_POST["fields"][$idf];
+ if ($field["type"] == "enum" ? $value == -1 : $_POST["function"][$idf] == "orig") {
+ return false;
+ } elseif ($field["type"] == "enum" || $field["auto_increment"] ? !strlen($value) : $_POST["function"][$idf] == "NULL") {
return "NULL";
} elseif ($field["type"] == "enum") {
return (isset($_GET["default"]) ? "'" . $mysql->escape_string($value) . "'" : intval($value));
} elseif ($field["type"] == "set") {
return (isset($_GET["default"]) ? "'" . implode(",", array_map(array($mysql, 'escape_string'), (array) $value)) . "'" : array_sum((array) $value));
} elseif (preg_match('~binary|blob~', $field["type"])) {
- $file = get_file($name);
+ $file = get_file($idf);
if (!is_string($file) && ($file != UPLOAD_ERR_NO_FILE || !$field["null"])) {
return false; //! report errors
}
return "_binary'" . (is_string($file) ? $mysql->escape_string($file) : "") . "'";
} elseif ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
return $value;
+ } elseif (preg_match('~^(now|uuid)$~', $_POST["function"][$idf])) {
+ return $_POST["function"][$idf] . "()";
+ } elseif (preg_match('~^(md5|sha1|password)$~', $_POST["function"][$idf])) {
+ return $_POST["function"][$idf] . "('" . $mysql->escape_string($value) . "')";
} else {
return "'" . $mysql->escape_string($value) . "'";
}
View
@@ -12,15 +12,14 @@ function bracket_escape($idf, $back = false) {
return strtr($idf, ($back ? array_flip($trans) : $trans));
}
-function optionlist($options, $selected = array()) {
+function optionlist($options, $selected = null) {
$return = "";
foreach ($options as $k => $v) {
if (is_array($v)) {
$return .= '<optgroup label="' . htmlspecialchars($k) . '">';
}
foreach ((is_array($v) ? $v : array($v)) as $val) {
- $checked = in_array($val, (array) $selected, true);
- $return .= '<option' . ($checked ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
+ $return .= '<option' . ($val === $selected ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>';
}
if (is_array($v)) {
$return .= '</optgroup>';
View
@@ -83,6 +83,9 @@
if (isset($_GET["default"])) {
$_GET["edit"] = $_GET["default"];
}
+ if (isset($_GET["select"]) && $_POST["edit"]) {
+ $_GET["edit"] = $_GET["select"];
+ }
if (isset($_GET["callf"])) {
$_GET["call"] = $_GET["callf"];
}
View
@@ -150,10 +150,6 @@
'Grant' => 'Povolit',
'Revoke' => 'Zakázat',
'Error during deleting' => 'Chyba při mazání',
- '%d item(s) have been deleted.' => array('Byl smazán %d záznam.', 'Byly smazány %d záznamy.', 'Bylo smazáno %d záznamů.'),
- 'all' => 'vše',
- 'Delete selected' => 'Smazat označené',
- 'Truncate result' => 'Promazat výsledek',
'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',
'Move up' => 'Přesunout nahoru',
@@ -171,8 +167,8 @@
'Tables' => 'Tabulky',
'Structure' => 'Struktura',
'Data' => 'Data',
- 'Export selected' => 'Exportovat označené',
- 'Export result' => 'Exportovat výsledek',
+ // 'Export selected' => 'Exportovat označené',
+ // 'Export result' => 'Exportovat výsledek',
'Event has been dropped.' => 'Událost byla odstraněna.',
'Event has been altered.' => 'Událost byla změněna.',
'Event has been created.' => 'Událost byla vytvořena.',
@@ -205,4 +201,7 @@
'Engine' => 'Úložiště',
'Save and continue edit' => 'Uložit a pokračovat v editaci',
'clone' => 'klonovat',
+ 'original' => 'původní',
+ '%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',
);
View
@@ -5,5 +5,5 @@
'Routine has been called, %d row(s) affected.' => array('Routine has been called, %d row affected.', 'Routine has been called, %d rows affected.'),
'%d process(es) has been killed.' => array('%d process has been killed.', '%d processes have been killed.'),
'%d row(s)' => array('%d row', '%d rows'),
- '%d item(s) have been deleted.' => array('%d item has been deleted.', '%d items have been deleted.'),
+ '%d item(s) have been affected.' => array('%d item have been affected.', '%d items have been affected.'),
);
Oops, something went wrong.

0 comments on commit 78639a9

Please sign in to comment.