Skip to content
Newer
Older
100644 114 lines (105 sloc) 3.09 KB
667bfec Decomposition
jakubvrana authored
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored
2 $TABLE = $_GET["edit"];
3 $fields = fields($TABLE);
2703eb9 @vrana Allow editing values with significant binary column (bug #3572781)
authored
4 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0], $fields) : "") : where($_GET, $fields));
5 $update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
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 }
9c78b3b @vrana Add empty lines to source code
authored
11
78639a9 Function results in edit
jakubvrana authored
12 if ($_POST && !$error && !isset($_GET["select"])) {
b681dfb Return to referer after edit
jakubvrana authored
13 $location = $_POST["referer"];
14 if ($_POST["insert"]) { // continue edit or insert
9bb1909 Fix Save and continue edit
jakubvrana authored
15 $location = ($update ? null : $_SERVER["REQUEST_URI"]);
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
16 } elseif (!preg_match('~^.+&select=.+$~', $location)) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
17 $location = ME . "select=" . urlencode($TABLE);
db46fc2 Maintain insert prefill value
jakubvrana authored
18 }
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
19
af30f59 @vrana Don't use LIMIT 1 if updating unique row (bug #3613109)
authored
20 $indexes = indexes($TABLE);
21 $unique_array = unique_array($_GET["where"], $indexes);
22 $query_where = "\nWHERE $where";
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
23
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
24 if (isset($_POST["delete"])) {
1f7fa44 @vrana Abstract DELETE, INSERT and INSERT+UPDATE
authored
25 queries_redirect(
af30f59 @vrana Don't use LIMIT 1 if updating unique row (bug #3613109)
authored
26 $location,
1f7fa44 @vrana Abstract DELETE, INSERT and INSERT+UPDATE
authored
27 lang('Item has been deleted.'),
28 $driver->delete($TABLE, $query_where, !$unique_array)
af30f59 @vrana Don't use LIMIT 1 if updating unique row (bug #3613109)
authored
29 );
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
30
90b8a2f Remove Delete button from Edit page
jakubvrana authored
31 } else {
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
32 $set = array();
33 foreach ($fields as $name => $field) {
34 $val = process_input($field);
3f5b683 Reintegrate sqlite branch
jakubvrana authored
35 if ($val !== false && $val !== null) {
d17b17e @vrana Driver for SimpleDB
authored
36 $set[idf_escape($name)] = $val;
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
37 }
38 }
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
39
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
40 if ($update) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored
41 if (!$set) {
42 redirect($location);
43 }
b7739dc @vrana Abstract UPDATE
authored
44 queries_redirect(
af30f59 @vrana Don't use LIMIT 1 if updating unique row (bug #3613109)
authored
45 $location,
b7739dc @vrana Abstract UPDATE
authored
46 lang('Item has been updated.'),
47 $driver->update($TABLE, $set, $query_where, !$unique_array)
af30f59 @vrana Don't use LIMIT 1 if updating unique row (bug #3613109)
authored
48 );
749f51a @vrana Save and continue edit by AJAX
authored
49 if (is_ajax()) {
50 page_headers();
51 page_messages($error);
52 exit;
53 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
54 } else {
1f7fa44 @vrana Abstract DELETE, INSERT and INSERT+UPDATE
authored
55 $result = $driver->insert($TABLE, $set);
29e7f04 @vrana Display auto_increment value of inserted item
authored
56 $last_id = ($result ? last_id() : 0);
57 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
58 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored
59 }
667bfec Decomposition
jakubvrana authored
60 }
c16c57b E-mail sending
jakubvrana authored
61
0115315 Init with null
jakubvrana authored
62 $row = null;
0cd2afb Remove single item clone
jakubvrana authored
63 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored
64 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored
65 } elseif ($where) {
1faeb90 Rights
jakubvrana authored
66 $select = array();
667bfec Decomposition
jakubvrana authored
67 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored
68 if (isset($field["privileges"]["select"])) {
d540023 @vrana MySQL: Support geometry data types
authored
69 $as = convert_field($field);
70 if ($_POST["clone"] && $field["auto_increment"]) {
71 $as = "''";
72 }
e8c6ef0 @vrana Replace ereg*() by preg_*()
authored
73 if ($jush == "sql" && preg_match("~enum|set~", $field["type"])) {
d540023 @vrana MySQL: Support geometry data types
authored
74 $as = "1*" . idf_escape($name);
75 }
76 $select[] = ($as ? "$as AS " : "") . idf_escape($name);
667bfec Decomposition
jakubvrana authored
77 }
78 }
820c882 Bulk clone
jakubvrana authored
79 $row = array();
d17b17e @vrana Driver for SimpleDB
authored
80 if (!support("table")) {
81 $select = array("*");
82 }
ae372aa Database abstraction
jakubvrana authored
83 if ($select) {
60c8ec6 @vrana Make select(..., , , ) optional
authored
84 $result = $driver->select($TABLE, $select, array($where), $select, array(), (isset($_GET["select"]) ? 2 : 1));
21cc6ce @vrana Elastic: Use select() instead of SELECT
authored
85 $row = $result->fetch_assoc();
e9b5616 @vrana MySQLi: Print error for editing invalid row
authored
86 if (!$row) { // MySQLi returns null
87 $row = false;
88 }
21cc6ce @vrana Elastic: Use select() instead of SELECT
authored
89 if (isset($_GET["select"]) && (!$row || $result->fetch_assoc())) { // $result->num_rows != 1 isn't available in all drivers
90 $row = null;
91 }
ae372aa Database abstraction
jakubvrana authored
92 }
667bfec Decomposition
jakubvrana authored
93 }
2d72101 @vrana Display error with non-existent row
authored
94
d17b17e @vrana Driver for SimpleDB
authored
95 if (!support("table") && !$fields) {
96 if (!$where) { // insert
60c8ec6 @vrana Make select(..., , , ) optional
authored
97 $result = $driver->select($TABLE, array("*"), $where, array("*"));
9824540 @vrana MongoDB: auto_increment
authored
98 $row = ($result ? $result->fetch_assoc() : false);
4bab88a @vrana MongoDB: Fix insert form with empty table
authored
99 if (!$row) {
9824540 @vrana MongoDB: auto_increment
authored
100 $row = array($driver->primary => "");
4bab88a @vrana MongoDB: Fix insert form with empty table
authored
101 }
d17b17e @vrana Driver for SimpleDB
authored
102 }
103 if ($row) {
104 foreach ($row as $key => $val) {
1060a3f @vrana Move SimpleDB fields computation
authored
105 if (!$where) {
d17b17e @vrana Driver for SimpleDB
authored
106 $row[$key] = null;
107 }
9824540 @vrana MongoDB: auto_increment
authored
108 $fields[$key] = array("field" => $key, "null" => ($key != $driver->primary), "auto_increment" => ($key == $driver->primary));
d17b17e @vrana Driver for SimpleDB
authored
109 }
110 }
111 }
112
7da82a1 @vrana Display edit form after error in clone or multi-edit
authored
113 edit_form($TABLE, $fields, $row, $update);
Something went wrong with that request. Please try again.