Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 115 lines (111 sloc) 4.152 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"])) {
db46fc2 Maintain insert prefill value
jakubvrana authored
12 $location = $_SERVER["REQUEST_URI"]; // continue edit or insert
13 if (!$_POST["insert"]) {
79d1902 Substitute table name to $TABLE
jakubvrana authored
14 $location = ME . "select=" . urlencode($TABLE);
db46fc2 Maintain insert prefill value
jakubvrana authored
15 $i = 0; // append &set converted to &where
16 foreach ((array) $_GET["set"] as $key => $val) {
17 if ($val == $_POST["fields"][$key]) {
18 $location .= where_link($i++, bracket_escape($key, "back"), $val);
19 }
20 }
21 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
22 if (isset($_POST["delete"])) {
23 query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1", $location, lang('Item has been deleted.'));
90b8a2f Remove Delete button from Edit page
jakubvrana authored
24 } else {
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
25 $set = array();
26 foreach ($fields as $name => $field) {
27 $val = process_input($field);
28 if (!$update) {
29 $set[idf_escape($name)] = ($val !== false ? $val : "''");
30 } elseif ($val !== false) {
31 $set[] = "\n" . idf_escape($name) . " = $val";
32 }
33 }
34 if (!$set) {
35 redirect($location);
36 }
37 if ($update) {
38 query_redirect("UPDATE " . idf_escape($TABLE) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
39 } else {
40 query_redirect("INSERT INTO " . idf_escape($TABLE) . " (" . implode(", ", array_keys($set)) . ")\nVALUES (" . implode(", ", $set) . ")", $location, lang('Item has been inserted.'));
41 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored
42 }
667bfec Decomposition
jakubvrana authored
43 }
c16c57b E-mail sending
jakubvrana authored
44
79d1902 Substitute table name to $TABLE
jakubvrana authored
45 $table_name = $adminer->tableName(table_status($TABLE));
c16c57b E-mail sending
jakubvrana authored
46 page_header(
4cead56 Edit default values directly in table creation
jakubvrana authored
47 ($update ? lang('Edit') : lang('Insert')),
c16c57b E-mail sending
jakubvrana authored
48 $error,
79d1902 Substitute table name to $TABLE
jakubvrana authored
49 array("select" => array($TABLE, $table_name)),
c16c57b E-mail sending
jakubvrana authored
50 $table_name
51 );
667bfec Decomposition
jakubvrana authored
52
d8df520 Initialize variables outside blocks
jakubvrana authored
53 unset($row);
0cd2afb Remove single item clone
jakubvrana authored
54 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored
55 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored
56 } elseif ($where) {
1faeb90 Rights
jakubvrana authored
57 $select = array();
667bfec Decomposition
jakubvrana authored
58 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored
59 if (isset($field["privileges"]["select"])) {
4b3d569 Save bytes
jakubvrana authored
60 $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : (ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
667bfec Decomposition
jakubvrana authored
61 }
62 }
820c882 Bulk clone
jakubvrana authored
63 $row = array();
ae372aa Database abstraction
jakubvrana authored
64 if ($select) {
64d616c Rename get_dbh to connection
jakubvrana authored
65 $result = $connection->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($TABLE) . " WHERE $where " . (isset($_GET["select"]) ? "HAVING COUNT(*) = 1" : "LIMIT 1"));
f2cfe8c Use $row instead of $data
jakubvrana authored
66 $row = $result->fetch_assoc();
ae372aa Database abstraction
jakubvrana authored
67 }
667bfec Decomposition
jakubvrana authored
68 }
69 ?>
73e8631 Move stuff to functions.inc.php
jakubvrana authored
70
430034c Cottage homework
jakubvrana authored
71 <form action="" method="post" enctype="multipart/form-data">
667bfec Decomposition
jakubvrana authored
72 <?php
3622108 One if() instead of two ?:
jakubvrana authored
73 if ($fields) {
f03b320 Timestamp ON UPDATE
jakubvrana authored
74 unset($create);
d30face Remove useless table attributes (thanks to Juraj Krivda)
jakubvrana authored
75 echo "<table cellspacing='0'>\n";
3622108 One if() instead of two ?:
jakubvrana authored
76 foreach ($fields as $name => $field) {
c64c4fd Adminer class
jakubvrana authored
77 echo "<tr><th>" . $adminer->fieldName($field);
98507da Function verify_version doesn't use version parameter
jakubvrana authored
78 $default = $_GET["set"][bracket_escape($name)];
543bc03 Select original value
jakubvrana authored
79 $value = (isset($row)
7352c28 Replace strlen() by != ""
jakubvrana authored
80 ? ($row[$name] != "" && ereg("enum|set", $field["type"]) ? intval($row[$name]) : $row[$name])
98507da Function verify_version doesn't use version parameter
jakubvrana authored
81 : ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : (isset($default) ? $default : $field["default"])))
0cd2afb Remove single item clone
jakubvrana authored
82 );
a0def47 Date localization
jakubvrana authored
83 if (!$_POST["save"] && is_string($value)) {
84 $value = $adminer->editVal($value, $field);
85 }
119a2a2 Display original value in clone
jakubvrana authored
86 $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
87 if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
88 $value = "";
89 $function = "now";
90 }
1e4d11e Select from foreign keys in Editor
jakubvrana authored
91 input($field, $value, $function);
ace55ed HTML instead of XHTML
jakubvrana authored
92 echo "\n";
667bfec Decomposition
jakubvrana authored
93 }
3622108 One if() instead of two ?:
jakubvrana authored
94 echo "</table>\n";
667bfec Decomposition
jakubvrana authored
95 }
96 ?>
430034c Cottage homework
jakubvrana authored
97 <p>
ace55ed HTML instead of XHTML
jakubvrana authored
98 <input type="hidden" name="token" value="<?php echo $token; ?>">
99 <input type="hidden" name="save" value="1">
78639a9 Function results in edit
jakubvrana authored
100 <?php
101 if (isset($_GET["select"])) {
820c882 Bulk clone
jakubvrana authored
102 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
78639a9 Function results in edit
jakubvrana authored
103 }
104 if ($fields) {
ace55ed HTML instead of XHTML
jakubvrana authored
105 echo "<input type='submit' value='" . lang('Save') . "'>\n";
4cead56 Edit default values directly in table creation
jakubvrana authored
106 if (!isset($_GET["select"])) {
ace55ed HTML instead of XHTML
jakubvrana authored
107 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
108 }
109 }
75f9958 Add Delete button to Edit page (revert r887)
jakubvrana authored
110 if ($update) {
111 echo "<input type='submit' name='delete' value='" . lang('Delete') . "'$confirm>\n";
112 }
0abe5a5 Change HTML to SQL
jakubvrana authored
113 ?>
667bfec Decomposition
jakubvrana authored
114 </form>
Something went wrong with that request. Please try again.