Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (107 sloc) 4.113 kb
667bfec4 » jakubvrana
2007-07-02 Decomposition
1 <?php
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
2 $TABLE = $_GET["edit"];
119a2a23 » jakubvrana
2009-08-25 Display original value in clone
3 $where = (isset($_GET["select"]) ? (count($_POST["check"]) == 1 ? where_check($_POST["check"][0]) : "") : where($_GET));
4 $update = (isset($_GET["select"]) ? $_POST["edit"] : $where);
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
5 $fields = fields($TABLE);
27067912 » jakubvrana
2007-07-25 Timestamps
6 foreach ($fields as $name => $field) {
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
7 if (!isset($field["privileges"][$update ? "update" : "insert"]) || $adminer->fieldName($field) == "") {
27067912 » jakubvrana
2007-07-25 Timestamps
8 unset($fields[$name]);
430034c3 » jakubvrana
2007-07-09 Cottage homework
9 }
a5a6d3b3 » jakubvrana
2007-07-05 Saving uses $where
10 }
78639a98 » jakubvrana
2008-10-01 Function results in edit
11 if ($_POST && !$error && !isset($_GET["select"])) {
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
12 $location = $_POST["referer"];
13 if ($_POST["insert"]) { // continue edit or insert
9bb1909f » jakubvrana
2010-04-15 Fix Save and continue edit
14 $location = ($update ? null : $_SERVER["REQUEST_URI"]);
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
15 } elseif (!ereg('^.+&select=.+$', $location)) {
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
16 $location = ME . "select=" . urlencode($TABLE);
db46fc24 » jakubvrana
2009-08-03 Maintain insert prefill value
17 }
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
18 if (isset($_POST["delete"])) {
07fd5229 »
2010-06-10 Typo
19 query_redirect("DELETE" . limit1("FROM " . table($TABLE), " WHERE $where"), $location, lang('Item has been deleted.'));
90b8a2f9 » jakubvrana
2009-07-23 Remove Delete button from Edit page
20 } else {
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
21 $set = array();
22 foreach ($fields as $name => $field) {
23 $val = process_input($field);
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
24 if ($val !== false && $val !== null) {
25 $set[idf_escape($name)] = ($update ? "\n" . idf_escape($name) . " = $val" : $val);
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
26 }
27 }
28 if ($update) {
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
29 if (!$set) {
30 redirect($location);
31 }
ee3e0459 »
2010-05-14 Separate $where in limit function
32 query_redirect("UPDATE" . limit1(table($TABLE) . " SET" . implode(",", $set), "\nWHERE $where"), $location, lang('Item has been updated.'));
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
33 } else {
29e7f041 »
2010-05-12 Display auto_increment value of inserted item
34 $result = insert_into($TABLE, $set);
35 $last_id = ($result ? last_id() : 0);
36 queries_redirect($location, lang('Item%s has been inserted.', ($last_id ? " $last_id" : "")), $result); //! link
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
37 }
90b8a2f9 » jakubvrana
2009-07-23 Remove Delete button from Edit page
38 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
39 }
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
40
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
41 $table_name = $adminer->tableName(table_status($TABLE));
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
42 page_header(
4cead560 » jakubvrana
2009-08-21 Edit default values directly in table creation
43 ($update ? lang('Edit') : lang('Insert')),
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
44 $error,
79d19028 » jakubvrana
2009-08-29 Substitute table name to $TABLE
45 array("select" => array($TABLE, $table_name)),
c16c57b1 » jakubvrana
2009-07-11 E-mail sending
46 $table_name
47 );
667bfec4 » jakubvrana
2007-07-02 Decomposition
48
0115315a » jakubvrana
2010-04-22 Init with null
49 $row = null;
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
50 if ($_POST["save"]) {
f2cfe8c6 » jakubvrana
2007-07-16 Use $row instead of $data
51 $row = (array) $_POST["fields"];
667bfec4 » jakubvrana
2007-07-02 Decomposition
52 } elseif ($where) {
1faeb90e » jakubvrana
2007-07-06 Rights
53 $select = array();
667bfec4 » jakubvrana
2007-07-02 Decomposition
54 foreach ($fields as $name => $field) {
f8174096 » jakubvrana
2009-06-13 Respect original values in mass edit and clone
55 if (isset($field["privileges"]["select"])) {
4b3d569a » jakubvrana
2009-10-07 Save bytes
56 $select[] = ($_POST["clone"] && $field["auto_increment"] ? "'' AS " : (ereg("enum|set", $field["type"]) ? "1*" . idf_escape($name) . " AS " : "")) . idf_escape($name);
667bfec4 » jakubvrana
2007-07-02 Decomposition
57 }
58 }
820c8820 » jakubvrana
2008-10-09 Bulk clone
59 $row = array();
ae372aab » jakubvrana
2007-07-10 Database abstraction
60 if ($select) {
b0d637b6 »
2010-10-13 Avoid fatal errors
61 $rows = get_rows("SELECT" . limit(implode(", ", $select) . " FROM " . table($TABLE), " WHERE $where", (isset($_GET["select"]) ? 2 : 1)));
62 $row = (isset($_GET["select"]) && count($rows) != 1 ? null : reset($rows));
ae372aab » jakubvrana
2007-07-10 Database abstraction
63 }
667bfec4 » jakubvrana
2007-07-02 Decomposition
64 }
65 ?>
73e8631b » jakubvrana
2007-07-09 Move stuff to functions.inc.php
66
430034c3 » jakubvrana
2007-07-09 Cottage homework
67 <form action="" method="post" enctype="multipart/form-data">
667bfec4 » jakubvrana
2007-07-02 Decomposition
68 <?php
36221087 » jakubvrana
2007-07-10 One if() instead of two ?:
69 if ($fields) {
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) {
c64c4fd1 » jakubvrana
2009-07-27 Adminer class
72 echo "<tr><th>" . $adminer->fieldName($field);
98507da3 » jakubvrana
2009-07-30 Function verify_version doesn't use version parameter
73 $default = $_GET["set"][bracket_escape($name)];
543bc030 » jakubvrana
2009-06-30 Select original value
74 $value = (isset($row)
7352c281 » jakubvrana
2010-01-09 Replace strlen() by != ""
75 ? ($row[$name] != "" && ereg("enum|set", $field["type"]) ? intval($row[$name]) : $row[$name])
3f5b6834 » jakubvrana
2010-04-21 Reintegrate sqlite branch
76 : (!$update && $field["auto_increment"] ? "" : (isset($_GET["select"]) ? false : (isset($default) ? $default : $field["default"])))
0cd2afbb » jakubvrana
2009-06-07 Remove single item clone
77 );
a0def479 » jakubvrana
2009-07-27 Date localization
78 if (!$_POST["save"] && is_string($value)) {
79 $value = $adminer->editVal($value, $field);
80 }
dc86757f » jakubvrana
2010-01-11 Set now() for timestamp only in single edit (bug #2929925)
81 $function = ($_POST["save"] ? (string) $_POST["function"][$name] : ($where && $field["on_update"] == "CURRENT_TIMESTAMP" ? "now" : ($value === false ? null : (isset($value) ? '' : 'NULL'))));
2959a052 » jakubvrana
2009-08-21 Use now function instead of CURRENT_TIMESTAMP
82 if ($field["type"] == "timestamp" && $value == "CURRENT_TIMESTAMP") {
83 $value = "";
84 $function = "now";
85 }
1e4d11e9 » jakubvrana
2009-07-23 Select from foreign keys in Editor
86 input($field, $value, $function);
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; ?>">
b681dfbb » jakubvrana
2010-03-05 Return to referer after edit
94 <input type="hidden" name="referer" value="<?php echo h(isset($_POST["referer"]) ? $_POST["referer"] : $_SERVER["HTTP_REFERER"]); ?>">
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
95 <input type="hidden" name="save" value="1">
78639a98 » jakubvrana
2008-10-01 Function results in edit
96 <?php
97 if (isset($_GET["select"])) {
820c8820 » jakubvrana
2008-10-09 Bulk clone
98 hidden_fields(array("check" => (array) $_POST["check"], "clone" => $_POST["clone"], "all" => $_POST["all"]));
78639a98 » jakubvrana
2008-10-01 Function results in edit
99 }
100 if ($fields) {
ace55ed1 » jakubvrana
2009-07-11 HTML instead of XHTML
101 echo "<input type='submit' value='" . lang('Save') . "'>\n";
4cead560 » jakubvrana
2009-08-21 Edit default values directly in table creation
102 if (!isset($_GET["select"])) {
5edbc1e9 »
2010-08-06 Fix translation (bug #3039743)
103 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
104 }
105 }
75f99584 » jakubvrana
2009-12-14 Add Delete button to Edit page (revert r887)
106 if ($update) {
107 echo "<input type='submit' name='delete' value='" . lang('Delete') . "'$confirm>\n";
108 }
0abe5a50 » jakubvrana
2009-06-07 Change HTML to SQL
109 ?>
667bfec4 » jakubvrana
2007-07-02 Decomposition
110 </form>
Something went wrong with that request. Please try again.