Skip to content

HTTPS clone URL

Subversion checkout URL

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