Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (110 sloc) 4.58 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)),
5ee1407 @vrana Avoid double escaping
authored
46 $table_name //! two calls of h()
c16c57b E-mail sending
jakubvrana authored
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"])) {
a227ec1 @vrana Don't treat enum in PostgreSQL as special (bug #3545899)
authored
56 $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : ($jush == "sql" && 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 }
2d72101 @vrana Display error with non-existent row
authored
65
66 if ($row === false) {
67 echo "<p class='error'>" . lang('No rows.') . "\n";
68 }
667bfec Decomposition
jakubvrana authored
69 ?>
73e8631 Move stuff to functions.inc.php
jakubvrana authored
70
ceef6bc @vrana Focus first field with insert (bug #3126501)
authored
71 <form action="" method="post" enctype="multipart/form-data" id="form">
667bfec Decomposition
jakubvrana authored
72 <?php
3622108 One if() instead of two ?:
jakubvrana authored
73 if ($fields) {
241fc4e @vrana Ctrl+Up and Down in edit and in-place edit
authored
74 echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
3622108 One if() instead of two ?:
jakubvrana authored
75 foreach ($fields as $name => $field) {
c64c4fd Adminer class
jakubvrana authored
76 echo "<tr><th>" . $adminer->fieldName($field);
98507da Function verify_version doesn't use version parameter
jakubvrana authored
77 $default = $_GET["set"][bracket_escape($name)];
6591d48 @vrana Replace isset($var) by $var !== null
authored
78 $value = ($row !== null
a227ec1 @vrana Don't treat enum in PostgreSQL as special (bug #3545899)
authored
79 ? ($row[$name] != "" && $jush == "sql" && ereg("enum|set", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name])
6591d48 @vrana Replace isset($var) by $var !== null
authored
80 : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : ($default !== null ? $default : $field["default"])))
0cd2afb Remove single item clone
jakubvrana authored
81 );
a0def47 Date localization
jakubvrana authored
82 if (!$_POST["save"] && is_string($value)) {
83 $value = $adminer->editVal($value, $field);
84 }
6591d48 @vrana Replace isset($var) by $var !== null
authored
85 $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : ($value !== null ? '' : 'NULL'))));
2959a05 Use now function instead of CURRENT_TIMESTAMP
jakubvrana authored
86 if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
87 $value = "";
88 $function = "now";
89 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored
90 input($field, $value, $function);
ace55ed HTML instead of XHTML
jakubvrana authored
91 echo "\n";
667bfec Decomposition
jakubvrana authored
92 }
3622108 One if() instead of two ?:
jakubvrana authored
93 echo "</table>\n";
667bfec Decomposition
jakubvrana authored
94 }
95 ?>
430034c Cottage homework
jakubvrana authored
96 <p>
78639a9 Function results in edit
jakubvrana authored
97 <?php
98 if ($fields) {
38894b2 @vrana Send all forms by AJAX
authored
99 echo "<input type='submit' value='" . lang('Save') . "'>\n";
4cead56 Edit default values directly in table creation
jakubvrana authored
100 if (!isset($_GET["select"])) {
aa29b01 @vrana Ctrl+Shift+Enter for Save and continue edit
authored
101 echo "<input type='submit' name='insert' value='" . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "' title='Ctrl+Shift+Enter'>\n";
0abe5a5 Change HTML to SQL
jakubvrana authored
102 }
103 }
fb7b5ce @vrana No auto-focus with POST
authored
104 echo ($update ? "<input type='submit' name='delete' value='" . lang('Delete') . "' onclick=\"return confirm('" . lang('Are you sure?') . "');\">\n"
06ba118 @vrana Avoid JS error with empty table
authored
105 : ($_POST || !$fields ? "" : "<script type='text/javascript'>document.getElementById('form').getElementsByTagName('td')[1].firstChild.focus();</script>\n")
ceef6bc @vrana Focus first field with insert (bug #3126501)
authored
106 );
740ae10 @vrana Don't send incomplete forms
authored
107 if (isset($_GET["select"])) {
108 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
109 }
0abe5a5 Change HTML to SQL
jakubvrana authored
110 ?>
740ae10 @vrana Don't send incomplete forms
authored
111 <input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
112 <input type="hidden" name="save" value="1">
113 <input type="hidden" name="token" value="<?php echo $token; ?>">
667bfec Decomposition
jakubvrana authored
114 </form>
Something went wrong with that request. Please try again.