Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (102 sloc) 3.839 kb
667bfec Decomposition
jakubvrana authored
1 <?php
119a2a2 Display original value in clone
jakubvrana authored
2 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
3 $update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
2706791 Timestamps
jakubvrana authored
4 $fields = fields($_GET["edit"]);
5 foreach ($fields as $name => $field) {
4cead56 Edit default values directly in table creation
jakubvrana authored
6 if (!isset($field["privileges"][$update ? "update" : "insert"]) || !strlen($adminer->fieldName($field))) {
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"])) {
db46fc2 Maintain insert prefill value
jakubvrana authored
11 $location = $_SERVER["REQUEST_URI"]; // continue edit or insert
12 if (!$_POST["insert"]) {
4cead56 Edit default values directly in table creation
jakubvrana authored
13 $location = ME . "select=" . urlencode($_GET["edit"]);
db46fc2 Maintain insert prefill value
jakubvrana authored
14 $i = 0; // append &set converted to &where
15 foreach ((array) $_GET["set"] as $key => $val) {
16 if ($val == $_POST["fields"][$key]) {
17 $location .= where_link($i++, bracket_escape($key, "back"), $val);
18 }
19 }
20 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored
21 $set = array();
22 foreach ($fields as $name => $field) {
a0def47 Date localization
jakubvrana authored
23 $val = process_input($field);
4cead56 Edit default values directly in table creation
jakubvrana authored
24 if ($val !== false || !$update) {
25 $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
667bfec Decomposition
jakubvrana authored
26 }
27 }
90b8a2f Remove Delete button from Edit page
jakubvrana authored
28 if (!$set) {
29 redirect($location);
30 }
4cead56 Edit default values directly in table creation
jakubvrana authored
31 if ($update) {
90b8a2f Remove Delete button from Edit page
jakubvrana authored
32 query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
33 } else {
34 query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
35 }
667bfec Decomposition
jakubvrana authored
36 }
c16c57b E-mail sending
jakubvrana authored
37
c64c4fd Adminer class
jakubvrana authored
38 $table_name = $adminer->tableName(table_status($_GET["edit"]));
c16c57b E-mail sending
jakubvrana authored
39 page_header(
4cead56 Edit default values directly in table creation
jakubvrana authored
40 ($update ? lang('Edit') : lang('Insert')),
c16c57b E-mail sending
jakubvrana authored
41 $error,
4cead56 Edit default values directly in table creation
jakubvrana authored
42 array("select" => array($_GET["edit"], $table_name)),
c16c57b E-mail sending
jakubvrana authored
43 $table_name
44 );
667bfec Decomposition
jakubvrana authored
45
d8df520 Initialize variables outside blocks
jakubvrana authored
46 unset($row);
0cd2afb Remove single item clone
jakubvrana authored
47 if ($_POST["save"]) {
f2cfe8c Use $row instead of $data
jakubvrana authored
48 $row = (array) $_POST["fields"];
667bfec Decomposition
jakubvrana authored
49 } elseif ($where) {
1faeb90 Rights
jakubvrana authored
50 $select = array();
667bfec Decomposition
jakubvrana authored
51 foreach ($fields as $name => $field) {
f817409 Respect original values in mass edit and clone
jakubvrana authored
52 if (isset($field["privileges"]["select"])) {
53 $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
54 }
55 }
820c882 Bulk clone
jakubvrana authored
56 $row = array();
ae372aa Database abstraction
jakubvrana authored
57 if ($select) {
119a2a2 Display original value in clone
jakubvrana authored
58 $result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE $where " . (isset($_GET["select"]) ? "HAVING COUNT(*) = 1" : "LIMIT 1"));
f2cfe8c Use $row instead of $data
jakubvrana authored
59 $row = $result->fetch_assoc();
ad5da46 Free result
jakubvrana authored
60 $result->free();
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.