Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 106 lines (103 sloc) 4.869 kb
667bfec4 » jakubvrana
2007-07-02 Decomposition
1 <?php
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
2 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
3 $update = ($where && !$_POST["clone"]);
27067912 » jakubvrana
2007-07-25 Timestamps
4 $fields = fields($_GET["edit"]);
5 foreach ($fields as $name => $field) {
50341236 » jakubvrana
2009-07-23 Apply field name with functions
6 if ((isset($_GET["default"]) ? $field["auto_increment"] || ereg('text|blob', $field["type"]) : !isset($field["privileges"][$update ? "update" : "insert"])) || !strlen(adminer_field_name($field))) {
27067912 » jakubvrana
2007-07-25 Timestamps
7 unset($fields[$name]);
430034c3 » jakubvrana
2007-07-09 Cottage homework
8 }
a5a6d3b3 » jakubvrana
2007-07-05 Saving uses $where
9 }
78639a98 » jakubvrana
2008-10-01 Function results in edit
10 if ($_POST && !$error && !isset($_GET["select"])) {
64ba9242 » jakubvrana
2009-06-21 Comments
11 $location = ($_POST["insert"] ? $_SERVER["REQUEST_URI"] : $SELF . (isset($_GET["default"]) ? "table=" : "select=") . urlencode($_GET["edit"])); // "insert" to continue edit or insert
90b8a2f9 » jakubvrana
2009-07-23 Remove Delete button from Edit page
12 $set = array();
13 foreach ($fields as $name => $field) {
14 $val = process_input($name, $field);
15 if (!isset($_GET["default"])) {
16 if ($val !== false || !$update) {
17 $set[] = "\n" . idf_escape($name) . " = " . ($val !== false ? $val : "''");
18 }
19 } elseif ($val !== false) {
20 if ($field["type"] == "timestamp" && $val != "NULL") { //! doesn't allow DEFAULT NULL and no ON UPDATE
21 $set[] = "\nMODIFY " . idf_escape($name) . " timestamp" . ($field["null"] ? " NULL" : "") . " DEFAULT $val" . ($_POST["on_update"][bracket_escape($name)] ? " ON UPDATE CURRENT_TIMESTAMP" : "");
22 } else {
23 $set[] = "\nALTER " . idf_escape($name) . ($val == "NULL" ? " DROP DEFAULT" : " SET DEFAULT $val");
667bfec4 » jakubvrana
2007-07-02 Decomposition
24 }
25 }
26 }
90b8a2f9 » jakubvrana
2009-07-23 Remove Delete button from Edit page
27 if (!$set) {
28 redirect($location);
29 }
30 if (isset($_GET["default"])) {
31 query_redirect("ALTER TABLE " . idf_escape($_GET["edit"]) . implode(",", $set), $location, lang('Default values has been set.'));
32 } elseif ($update) {
33 query_redirect("UPDATE " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set) . "\nWHERE $where\nLIMIT 1", $location, lang('Item has been updated.'));
34 } else {
35 query_redirect("INSERT INTO " . idf_escape($_GET["edit"]) . " SET" . implode(",", $set), $location, lang('Item has been inserted.'));
36 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
37 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
38
39 $table_name = adminer_table_name(table_status($_GET["edit"]));
40 page_header(
41 (isset($_GET["default"]) ? lang('Default values') : ($_GET["where"] || (isset($_GET["select"]) && !$_POST["clone"]) ? lang('Edit') : lang('Insert'))),
42 $error,
43 array((isset($_GET["default"]) ? "table" : "select") => array($_GET["edit"], $table_name)),
44 $table_name
45 );
667bfec4 » jakubvrana
2007-07-02 Decomposition
46
d8df5206 » jakubvrana
2008-07-10 Initialize variables outside blocks
47 unset($row);
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
48 if ($_POST["save"]) {
f2cfe8c6 » jakubvrana
2007-07-16 Use $row instead of $data
49 $row = (array) $_POST["fields"];
667bfec4 » jakubvrana
2007-07-02 Decomposition
50 } elseif ($where) {
1faeb90e » jakubvrana
2007-07-06 Rights
51 $select = array();
667bfec4 » jakubvrana
2007-07-02 Decomposition
52 foreach ($fields as $name => $field) {
f8174096 » jakubvrana
2009-06-13 Respect original values in mass edit and clone
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);
667bfec4 » jakubvrana
2007-07-02 Decomposition
55 }
56 }
820c8820 » jakubvrana
2008-10-09 Bulk clone
57 $row = array();
ae372aab » jakubvrana
2007-07-10 Database abstraction
58 if ($select) {
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
59 $result = $dbh->query("SELECT " . implode(", ", $select) . " FROM " . idf_escape($_GET["edit"]) . " WHERE $where LIMIT 1");
f2cfe8c6 » jakubvrana
2007-07-16 Use $row instead of $data
60 $row = $result->fetch_assoc();
ad5da46c » jakubvrana
2008-09-01 Free result
61 $result->free();
ae372aab » jakubvrana
2007-07-10 Database abstraction
62 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
63 }
64 ?>
73e8631b » jakubvrana
2007-07-09 Move stuff to functions.inc.php
65
430034c3 » jakubvrana
2007-07-09 Cottage homework
66 <form action="" method="post" enctype="multipart/form-data">
667bfec4 » jakubvrana
2007-07-02 Decomposition
67 <?php
36221087 » jakubvrana
2007-07-10 One if() instead of two ?:
68 if ($fields) {
f03b3207 » jakubvrana
2007-07-25 Timestamp ON UPDATE
69 unset($create);
d30facef » jakubvrana
2009-05-01 Remove useless table attributes (thanks to Juraj Krivda)
70 echo "<table cellspacing='0'>\n";
36221087 » jakubvrana
2007-07-10 One if() instead of two ?:
71 foreach ($fields as $name => $field) {
50341236 » jakubvrana
2009-07-23 Apply field name with functions
72 echo "<tr><th>" . adminer_field_name($field);
543bc030 » jakubvrana
2009-06-30 Select original value
73 $value = (isset($row)
74 ? (strlen($row[$name]) && ($field["type"] == "enum" || $field["type"] == "set") ? intval($row[$name]) : $row[$name])
36f430e3 » jakubvrana
2009-07-15 Respect default values (thanks to Jiri Pospisil)
75 : ($_POST["clone"] && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : $field["default"]))
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
76 );
ed2c27c2 » jakubvrana
2009-07-17 Respect field function
77 $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
78 input($field, $value, $function);
f03b3207 » jakubvrana
2007-07-25 Timestamp ON UPDATE
79 if (isset($_GET["default"]) && $field["type"] == "timestamp") {
80 if (!isset($create) && !$_POST) {
7ce79142 » jakubvrana
2007-08-11 sql_mode NO_FIELD_OPTIONS should be disabled
81 //! disable sql_mode NO_FIELD_OPTIONS
5f16c75c » jakubvrana
2009-05-08 Prepare for version 2
82 $create = $dbh->result($dbh->query("SHOW CREATE TABLE " . idf_escape($_GET["edit"])), 1);
f03b3207 » jakubvrana
2007-07-25 Timestamp ON UPDATE
83 }
84 $checked = ($_POST ? $_POST["on_update"][bracket_escape($name)] : preg_match("~\n\\s*" . preg_quote(idf_escape($name), '~') . " timestamp.* on update CURRENT_TIMESTAMP~i", $create));
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
85 echo '<label><input type="checkbox" name="on_update[' . htmlspecialchars(bracket_escape($name)) . ']" value="1"' . ($checked ? ' checked="checked"' : '') . '>' . lang('ON UPDATE CURRENT_TIMESTAMP') . '</label>';
f03b3207 » jakubvrana
2007-07-25 Timestamp ON UPDATE
86 }
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
87 echo "\n";
667bfec4 » jakubvrana
2007-07-02 Decomposition
88 }
36221087 » jakubvrana
2007-07-10 One if() instead of two ?:
89 echo "</table>\n";
667bfec4 » jakubvrana
2007-07-02 Decomposition
90 }
91 ?>
430034c3 » jakubvrana
2007-07-09 Cottage homework
92 <p>
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
93 <input type="hidden" name="token" value="<?php echo $token; ?>">
94 <input type="hidden" name="save" value="1">
78639a98 » jakubvrana
2008-10-01 Function results in edit
95 <?php
96 if (isset($_GET["select"])) {
820c8820 » jakubvrana
2008-10-09 Bulk clone
97 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
78639a98 » jakubvrana
2008-10-01 Function results in edit
98 }
99 if ($fields) {
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
100 echo "<input type='submit' value='" . lang('Save') . "'>\n";
0abe5a50 » jakubvrana
2009-06-07 Change HTML to SQL
101 if (!isset($_GET["default"]) && !isset($_GET["select"])) {
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
102 echo "<input type='submit' name='insert' value='" . ($update ? lang('Save and continue edit') : lang('Save and insert next')) . "'>\n";
0abe5a50 » jakubvrana
2009-06-07 Change HTML to SQL
103 }
104 }
105 ?>
667bfec4 » jakubvrana
2007-07-02 Decomposition
106 </form>
Something went wrong with that request. Please try again.