Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 111 lines (107 sloc) 4.201 kB
667bfec Decomposition
jakubvrana authored
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored
2 $TABLE = $_GET["edit"];
119a2a2 Display original value in clone
jakubvrana authored
3 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
4 $update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
79d1902 Substitute table name to $TABLE
jakubvrana authored
5 $fields = fields($TABLE);
2706791 Timestamps
jakubvrana authored
6 foreach ($fields as $name => $field) {
7352c28 Replace strlen() by != ""
jakubvrana authored
7 if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "") {
2706791 Timestamps
jakubvrana authored
8 unset($fields[$name]);
430034c Cottage homework
jakubvrana authored
9 }
a5a6d3b Saving uses $where
jakubvrana authored
10 }
78639a9 Function results in edit
jakubvrana authored
11 if ($_POST && !$error && !isset($_GET["select"])) {
b681dfb Return to referer after edit
jakubvrana authored
12 $location = $_POST["referer"];
13 if ($_POST["insert"]) { // continue edit or insert
9bb1909 Fix Save and continue edit
jakubvrana authored
14 $location = ($update ? null : $_SERVER["REQUEST_URI"]);
b681dfb Return to referer after edit
jakubvrana authored
15 } elseif (!ereg('^.+&select=.+$', $location)) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
16 $location = ME . "select=" . urlencode($TABLE);
db46fc2 Maintain insert prefill value
jakubvrana authored
17 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
18 if (isset($_POST["delete"])) {
07fd522 @vrana Typo
authored
19 query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE $where"), $location, lang('Item has been deleted.'));
90b8a2f Remove Delete button from Edit page
jakubvrana authored
20 } else {
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
21 $set = array();
22 foreach ($fields as $name => $field) {
23 $val = process_input($field);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
24 if ($val !== false && $val !== null) {
25 $set[idf_escape($name)] = ($update ? "\n" . idf_escape($name) . " = $val" : $val);
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
26 }
27 }
28 if ($update) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
29 if (!$set) {
30 redirect($location);
31 }
ee3e045 @vrana Separate $where in limit function
authored
32 query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE $where"), $location, lang('Item has been updated.'));
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
33 } else {
29e7f04 @vrana Display auto_increment value of inserted item
authored
34 $result = insert_into($TABLE, $set);
35 $last_id = ($result ? last_id() : 0);
36 queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
37 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored
38 }
667bfec Decomposition
jakubvrana authored
39 }
c16c57b E-mail sending
jakubvrana authored
40
79d1902 Substitute table name to $TABLE
jakubvrana authored
41 $table_name = $adminer->tableName(table_status($TABLE));
c16c57b E-mail sending
jakubvrana authored
42 page_header(
4cead56 Edit default values directly in table creation
jakubvrana authored
43 ($update ? lang('Edit') : lang('Insert')),
c16c57b E-mail sending
jakubvrana authored
44 $error,
79d1902 Substitute table name to $TABLE
jakubvrana authored
45 array("select" => array($TABLE, $table_name)),
c16c57b E-mail sending
jakubvrana authored
46 $table_name
47 );
667bfec Decomposition
jakubvrana authored
48
0115315 Init with null
jakubvrana authored
49 $row = null;
0cd2afb Remove single item clone
jakubvrana authored
50 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored
51 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored
52 } elseif ($where) {
1faeb90 Rights
jakubvrana authored
53 $select = array();
667bfec Decomposition
jakubvrana authored
54 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored
55 if (isset($field["privileges"]["select"])) {
4b3d569 Save bytes
jakubvrana authored
56 $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : (ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
667bfec Decomposition
jakubvrana authored
57 }
58 }
820c882 Bulk clone
jakubvrana authored
59 $row = array();
ae372aa Database abstraction
jakubvrana authored
60 if ($select) {
b0d637b @vrana Avoid fatal errors
authored
61 $rows = get_rows("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
62 $row = (isset($_GET["select"]) && count($rows) != 1 ? null : reset($rows));
ae372aa Database abstraction
jakubvrana authored
63 }
667bfec Decomposition
jakubvrana authored
64 }
65 ?>
73e8631 Move stuff to functions.inc.php
jakubvrana authored
66
b535853 @vrana Full AJAX only with pushState to work correctly with history
authored
67 <form action="" method="post" enctype="multipart/form-data">
667bfec Decomposition
jakubvrana authored
68 <?php
3622108 One if() instead of two ?:
jakubvrana authored
69 if ($fields) {
241fc4e @vrana Ctrl+Up and Down in edit and in-place edit
authored
70 echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
3622108 One if() instead of two ?:
jakubvrana authored
71 foreach ($fields as $name => $field) {
c64c4fd Adminer class
jakubvrana authored
72 echo "<tr><th>" . $adminer->fieldName($field);
98507da Function verify_version doesn't use version parameter
jakubvrana authored
73 $default = $_GET["set"][bracket_escape($name)];
543bc03 Select original value
jakubvrana authored
74 $value = (isset($row)
04eccba @vrana Allow bigger numbers under 32 bits
authored
75 ? ($row[$name] != "" && ereg("enum|set", $field["type"]) ? +$row[$name] : $row[$name])
3f5b683 Reintegrate sqlite branch
jakubvrana authored
76 : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : (isset($default) ? $default : $field["default"])))
0cd2afb Remove single item clone
jakubvrana authored
77 );
a0def47 Date localization
jakubvrana authored
78 if (!$_POST["save"] && is_string($value)) {
79 $value = $adminer->editVal($value, $field);
80 }
dc86757 Set now() for timestamp only in single edit (bug #2929925)
jakubvrana authored
81 $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
2959a05 Use now function instead of CURRENT_TIMESTAMP
jakubvrana authored
82 if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
83 $value = "";
84 $function = "now";
85 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored
86 input($field, $value, $function);
ace55ed HTML instead of XHTML
jakubvrana authored
87 echo "\n";
667bfec Decomposition
jakubvrana authored
88 }
3622108 One if() instead of two ?:
jakubvrana authored
89 echo "</table>\n";
667bfec Decomposition
jakubvrana authored
90 }
91 ?>
430034c Cottage homework
jakubvrana authored
92 <p>
ace55ed HTML instead of XHTML
jakubvrana authored
93 <input type="hidden" name="token" value="<?php echo $token; ?>">
b681dfb Return to referer after edit
jakubvrana authored
94 <input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
ace55ed HTML instead of XHTML
jakubvrana authored
95 <input type="hidden" name="save" value="1">
78639a9 Function results in edit
jakubvrana authored
96 <?php
97 if (isset($_GET["select"])) {
820c882 Bulk clone
jakubvrana authored
98 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
78639a9 Function results in edit
jakubvrana authored
99 }
100 if ($fields) {
38894b2 @vrana Send all forms by AJAX
authored
101 echo "<input type='submit' value='" . lang('Save') . "'>\n";
4cead56 Edit default values directly in table creation
jakubvrana authored
102 if (!isset($_GET["select"])) {
38894b2 @vrana Send all forms by AJAX
authored
103 echo '<input type="submit" name="insert" value="' . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "\">\n";
0abe5a5 Change HTML to SQL
jakubvrana authored
104 }
105 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
106 if ($update) {
38894b2 @vrana Send all forms by AJAX
authored
107 echo "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\">\n";
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
108 }
0abe5a5 Change HTML to SQL
jakubvrana authored
109 ?>
667bfec Decomposition
jakubvrana authored
110 </form>
Something went wrong with that request. Please try again.