Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 113 lines (109 sloc) 4.933 kB
667bfec Decomposition
jakubvrana authored
1 <?php
c16c57b E-mail sending
jakubvrana authored
2 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
0cd2afb Remove single item clone
jakubvrana authored
3 $update = ($where && !$_POST["clone"]);
2706791 Timestamps
jakubvrana authored
4 $fields = fields($_GET["edit"]);
5 foreach ($fields as $name => $field) {
9edb147 Optimize size
jakubvrana authored
6 if (isset($_GET["default"]) ? $field["auto_increment"] || preg_match('~text|blob~', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) {
2706791 Timestamps
jakubvrana authored
7 unset($fields[$name]);
430034c Cottage homework
jakubvrana authored
8 }
a5a6d3b Saving uses $where
jakubvrana authored
9 }
78639a9 Function results in edit
jakubvrana authored
10 if ($_POST && !$error && !isset($_GET["select"])) {
64ba924 Comments
jakubvrana authored
11 $location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); // "insert" to continue edit or insert
667bfec Decomposition
jakubvrana authored
12 if (isset($_POST["delete"])) {
c16c57b E-mail sending
jakubvrana authored
13 query_redirect("DELETE FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1", $location, lang('Item has been deleted.'));
667bfec Decomposition
jakubvrana authored
14 } else {
f91b2c4 Print SQL query by message
jakubvrana authored
15 $set = array();
430034c Cottage homework
jakubvrana authored
16 foreach ($fields as $name => $field) {
73e8631 Move stuff to functions.inc.php
jakubvrana authored
17 $val = process_input($name, $field);
19e4d59 Don't update unmodified blob (thanks to crempa)
jakubvrana authored
18 if (!isset($_GET["default"])) {
19 if ($val !== false || !$update) {
20679d8 Use \n in SQL commands
jakubvrana authored
20 $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
19e4d59 Don't update unmodified blob (thanks to crempa)
jakubvrana authored
21 }
22 } elseif ($val !== false) {
26d76b2 Allow DEFAULT '' (thanks to pojizdna kocka)
jakubvrana authored
23 if ($field["type"] == "timestamp" && $val != "NULL") { //! doesn't allow DEFAULT NULL and no ON UPDATE
20679d8 Use \n in SQL commands
jakubvrana authored
24 $set[] = "\nMODIFY " . idf_escape($name) . " timestamp" . ($field["null"] ? " NULL" : "") . " DEFAULT $val" . ($_POST["on_update"][bracket_escape($name)] ? " ON UPDATE CURRENT_TIMESTAMP" : "");
2706791 Timestamps
jakubvrana authored
25 } else {
20679d8 Use \n in SQL commands
jakubvrana authored
26 $set[] = "\nALTER " . idf_escape($name) . ($val == "NULL" ? " DROP DEFAULT" : " SET DEFAULT $val");
2706791 Timestamps
jakubvrana authored
27 }
667bfec Decomposition
jakubvrana authored
28 }
29 }
f91b2c4 Print SQL query by message
jakubvrana authored
30 if (!$set) {
31 redirect($location);
32 }
430034c Cottage homework
jakubvrana authored
33 if (isset($_GET["default"])) {
f91b2c4 Print SQL query by message
jakubvrana authored
34 query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values has been set.'));
9edb147 Optimize size
jakubvrana authored
35 } elseif ($update) {
c16c57b E-mail sending
jakubvrana authored
36 query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE $where LIMIT 1", $location, lang('Item has been updated.'));
667bfec Decomposition
jakubvrana authored
37 } else {
20679d8 Use \n in SQL commands
jakubvrana authored
38 query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
667bfec Decomposition
jakubvrana authored
39 }
40 }
41 }
c16c57b E-mail sending
jakubvrana authored
42
43 $table_name = adminer_table_name(table_status($_GET["edit"]));
44 page_header(
45 (isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))),
46 $error,
47 array((isset($_GET["default"]) ? "table" : "select") => array($_GET["edit"], $table_name)),
48 $table_name
49 );
667bfec Decomposition
jakubvrana authored
50
d8df520 Initialize variables outside blocks
jakubvrana authored
51 unset($row);
0cd2afb Remove single item clone
jakubvrana authored
52 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored
53 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored
54 } elseif ($where) {
1faeb90 Rights
jakubvrana authored
55 $select = array();
667bfec Decomposition
jakubvrana authored
56 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored
57 if (isset($field["privileges"]["select"])) {
58 $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : ($field["type"] == "enum" || $field["type"] == "set" ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
667bfec Decomposition
jakubvrana authored
59 }
60 }
820c882 Bulk clone
jakubvrana authored
61 $row = array();
ae372aa Database abstraction
jakubvrana authored
62 if ($select) {
c16c57b E-mail sending
jakubvrana authored
63 $result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1");
f2cfe8c Use $row instead of $data
jakubvrana authored
64 $row = $result->fetch_assoc();
ad5da46 Free result
jakubvrana authored
65 $result->free();
ae372aa Database abstraction
jakubvrana authored
66 }
667bfec Decomposition
jakubvrana authored
67 }
68 ?>
73e8631 Move stuff to functions.inc.php
jakubvrana authored
69
430034c Cottage homework
jakubvrana authored
70 <form action="" method="post" enctype="multipart/form-data">
667bfec Decomposition
jakubvrana authored
71 <?php
3622108 One if() instead of two ?:
jakubvrana authored
72 if ($fields) {
f03b320 Timestamp ON UPDATE
jakubvrana authored
73 unset($create);
d30face Remove useless table attributes (thanks to Juraj Krivda)
jakubvrana authored
74 echo "<table cellspacing='0'>\n";
3622108 One if() instead of two ?:
jakubvrana authored
75 foreach ($fields as $name => $field) {
ace55ed HTML instead of XHTML
jakubvrana authored
76 echo "<tr><th>" . adminer_field_name($fields, $name);
543bc03 Select original value
jakubvrana authored
77 $value = (isset($row)
78 ? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
79 : ($_POST["clone"] && $field["auto_increment"] ? "" : ($where ? $field["default"] : false))
0cd2afb Remove single item clone
jakubvrana authored
80 );
3622108 One if() instead of two ?:
jakubvrana authored
81 input($name, $field, $value);
f03b320 Timestamp ON UPDATE
jakubvrana authored
82 if (isset($_GET["default"]) && $field["type"] == "timestamp") {
83 if (!isset($create) && !$_POST) {
7ce7914 sql_mode NO_FIELD_OPTIONS should be disabled
jakubvrana authored
84 //! disable sql_mode NO_FIELD_OPTIONS
5f16c75 Prepare for version 2
jakubvrana authored
85 $create = $dbh->result($dbh->query("SHOW CREATE TABLE " . idf_escape($_GET["edit"])), 1);
f03b320 Timestamp ON UPDATE
jakubvrana authored
86 }
87 $checked = ($_POST ? $_POST["on_update"][bracket_escape($name)] : preg_match("~\n\\s*" . preg_quote(idf_escape($name), '~') . " timestamp.* on update CURRENT_TIMESTAMP~i", $create));
ace55ed HTML instead of XHTML
jakubvrana authored
88 echo '<label><input type="checkbox" name="on_update[' . htmlspecialchars(bracket_escape($name)) . ']" value="1"' . ($checked ? ' checked="checked"' : '') . '>' . lang('ON UPDATE CURRENT_TIMESTAMP') . '</label>';
f03b320 Timestamp ON UPDATE
jakubvrana authored
89 }
ace55ed HTML instead of XHTML
jakubvrana authored
90 echo "\n";
667bfec Decomposition
jakubvrana authored
91 }
3622108 One if() instead of two ?:
jakubvrana authored
92 echo "</table>\n";
667bfec Decomposition
jakubvrana authored
93 }
94 ?>
430034c Cottage homework
jakubvrana authored
95 <p>
ace55ed HTML instead of XHTML
jakubvrana authored
96 <input type="hidden" name="token" value="<?php echo $token; ?>">
97 <input type="hidden" name="save" value="1">
78639a9 Function results in edit
jakubvrana authored
98 <?php
99 if (isset($_GET["select"])) {
820c882 Bulk clone
jakubvrana authored
100 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
78639a9 Function results in edit
jakubvrana authored
101 }
102 if ($fields) {
ace55ed HTML instead of XHTML
jakubvrana authored
103 echo "<input type='submit' value='" . lang('Save') . "'>\n";
0abe5a5 Change HTML to SQL
jakubvrana authored
104 if (!isset($_GET["default"]) && !isset($_GET["select"])) {
ace55ed HTML instead of XHTML
jakubvrana authored
105 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
106 }
107 }
108 if ($update) {
ace55ed HTML instead of XHTML
jakubvrana authored
109 echo "<input type='submit' name='delete' value='" . lang('Delete') . "'$confirm>\n";
0abe5a5 Change HTML to SQL
jakubvrana authored
110 }
111 ?>
667bfec Decomposition
jakubvrana authored
112 </form>
Something went wrong with that request. Please try again.