Skip to content
Newer
Older
100644 115 lines (110 sloc) 4.43 KB
667bfec Decomposition
jakubvrana authored Jul 2, 2007
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
2 $TABLE = $_GET["edit"];
119a2a2 Display original value in clone
jakubvrana authored Aug 25, 2009
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 Aug 29, 2009
5 $fields = fields($TABLE);
2706791 Timestamps
jakubvrana authored Jul 25, 2007
6 foreach ($fields as $name => $field) {
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
7 if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "") {
2706791 Timestamps
jakubvrana authored Jul 25, 2007
8 unset($fields[$name]);
430034c Cottage homework
jakubvrana authored Jul 9, 2007
9 }
a5a6d3b Saving uses $where
jakubvrana authored Jul 5, 2007
10 }
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
11 if ($_POST && !$error && !isset($_GET["select"])) {
b681dfb Return to referer after edit
jakubvrana authored Mar 5, 2010
12 $location = $_POST["referer"];
13 if ($_POST["insert"]) { // continue edit or insert
9bb1909 Fix Save and continue edit
jakubvrana authored Apr 15, 2010
14 $location = ($update ? null : $_SERVER["REQUEST_URI"]);
b681dfb Return to referer after edit
jakubvrana authored Mar 5, 2010
15 } elseif (!ereg('^.+&select=.+$', $location)) {
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
16 $location = ME . "select=" . urlencode($TABLE);
db46fc2 Maintain insert prefill value
jakubvrana authored Aug 3, 2009
17 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored Dec 14, 2009
18 if (isset($_POST["delete"])) {
07fd522 @vrana Typo
authored Jun 10, 2010
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 Jul 23, 2009
20 } else {
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored Dec 14, 2009
21 $set = array();
22 foreach ($fields as $name => $field) {
23 $val = process_input($field);
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
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 Dec 14, 2009
26 }
27 }
28 if ($update) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
29 if (!$set) {
30 redirect($location);
31 }
ee3e045 @vrana Separate $where in limit function
authored May 14, 2010
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 Dec 14, 2009
33 } else {
29e7f04 @vrana Display auto_increment value of inserted item
authored May 12, 2010
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 Dec 14, 2009
37 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored Jul 23, 2009
38 }
667bfec Decomposition
jakubvrana authored Jul 2, 2007
39 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
40
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
41 $table_name = $adminer->tableName(table_status($TABLE));
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
42 page_header(
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
43 ($update ? lang('Edit') : lang('Insert')),
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
44 $error,
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
45 array("select" => array($TABLE, $table_name)),
5ee1407 @vrana Avoid double escaping
authored Mar 24, 2011
46 $table_name //! two calls of h()
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
47 );
667bfec Decomposition
jakubvrana authored Jul 2, 2007
48
0115315 Init with null
jakubvrana authored Apr 22, 2010
49 $row = null;
0cd2afb Remove single item clone
jakubvrana authored Jun 7, 2009
50 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored Jul 16, 2007
51 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored Jul 2, 2007
52 } elseif ($where) {
1faeb90 Rights
jakubvrana authored Jul 6, 2007
53 $select = array();
667bfec Decomposition
jakubvrana authored Jul 2, 2007
54 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored Jun 13, 2009
55 if (isset($field["privileges"]["select"])) {
4b3d569 Save bytes
jakubvrana authored Oct 7, 2009
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 Jul 2, 2007
57 }
58 }
820c882 Bulk clone
jakubvrana authored Oct 9, 2008
59 $row = array();
ae372aa Database abstraction
jakubvrana authored Jul 10, 2007
60 if ($select) {
b0d637b @vrana Avoid fatal errors
authored Oct 13, 2010
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 Jul 10, 2007
63 }
667bfec Decomposition
jakubvrana authored Jul 2, 2007
64 }
2d72101 @vrana Display error with non-existent row
authored Aug 1, 2011
65
66 if ($row === false) {
67 echo "<p class='error'>" . lang('No rows.') . "\n";
68 }
667bfec Decomposition
jakubvrana authored Jul 2, 2007
69 ?>
73e8631 Move stuff to functions.inc.php
jakubvrana authored Jul 9, 2007
70
ceef6bc @vrana Focus first field with insert (bug #3126501)
authored Jan 31, 2011
71 <form action="" method="post" enctype="multipart/form-data" id="form">
667bfec Decomposition
jakubvrana authored Jul 2, 2007
72 <?php
3622108 One if() instead of two ?:
jakubvrana authored Jul 10, 2007
73 if ($fields) {
241fc4e @vrana Ctrl+Up and Down in edit and in-place edit
authored Jan 25, 2011
74 echo "<table cellspacing='0' onkeydown='return editingKeydown(event);'>\n";
3622108 One if() instead of two ?:
jakubvrana authored Jul 10, 2007
75 foreach ($fields as $name => $field) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
76 echo "<tr><th>" . $adminer->fieldName($field);
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
77 $default = $_GET["set"][bracket_escape($name)];
543bc03 Select original value
jakubvrana authored Jun 30, 2009
78 $value = (isset($row)
9bb7641 @vrana Save and continue edit of set data type (bug #3298804)
authored May 8, 2011
79 ? ($row[$name] != "" && ereg("enum|set", $field["type"]) ? (is_array($row[$name]) ? array_sum($row[$name]) : +$row[$name]) : $row[$name])
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
80 : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : (isset($default) ? $default : $field["default"])))
0cd2afb Remove single item clone
jakubvrana authored Jun 7, 2009
81 );
a0def47 Date localization
jakubvrana authored Jul 27, 2009
82 if (!$_POST["save"] && is_string($value)) {
83 $value = $adminer->editVal($value, $field);
84 }
c0c21d4 @vrana Preserve original timestamp value in multiple update (bug #3312614)
authored Jun 8, 2011
85 $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($update && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
2959a05 Use now function instead of CURRENT_TIMESTAMP
jakubvrana authored Aug 21, 2009
86 if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
87 $value = "";
88 $function = "now";
89 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored Jul 23, 2009
90 input($field, $value, $function);
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
91 echo "\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
92 }
3622108 One if() instead of two ?:
jakubvrana authored Jul 10, 2007
93 echo "</table>\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
94 }
95 ?>
430034c Cottage homework
jakubvrana authored Jul 9, 2007
96 <p>
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
97 <?php
98 if ($fields) {
38894b2 @vrana Send all forms by AJAX
authored Nov 23, 2010
99 echo "<input type='submit' value='" . lang('Save') . "'>\n";
4cead56 Edit default values directly in table creation
jakubvrana authored Aug 21, 2009
100 if (!isset($_GET["select"])) {
aa29b01 @vrana Ctrl+Shift+Enter for Save and continue edit
authored Jun 14, 2011
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 Jun 7, 2009
102 }
103 }
fb7b5ce @vrana No auto-focus with POST
authored Feb 2, 2011
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 Mar 17, 2011
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 Jan 31, 2011
106 );
740ae10 @vrana Don't send incomplete forms
authored Mar 8, 2011
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 Jun 7, 2009
110 ?>
740ae10 @vrana Don't send incomplete forms
authored Mar 8, 2011
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 Jul 2, 2007
114 </form>
Something went wrong with that request. Please try again.