Skip to content
Newer
Older
100644 422 lines (403 sloc) 18.5 KB
667bfec Decomposition
jakubvrana authored Jul 2, 2007
1 <?php
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
2 $TABLE = $_GET["select"];
3 $table_status = table_status($TABLE);
4 $indexes = indexes($TABLE);
f425601 @vrana Hide hidden columns in PostgreSQL (thanks to Pavel Stehule)
authored Nov 11, 2010
5 $fields = fields($TABLE);
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
6 $foreign_keys = column_foreign_keys($TABLE);
37d8146 @vrana Utilize oids in PostgreSQL
authored Feb 1, 2011
7 if ($table_status["Oid"] == "t") {
8 $indexes[] = array("type" => "PRIMARY", "columns" => array("oid"));
9 }
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
10
64ba924 Comments
jakubvrana authored Jun 21, 2009
11 $rights = array(); // privilege => 0
12 $columns = array(); // selectable columns
0115315 Init with null
jakubvrana authored Apr 22, 2010
13 $text_length = null;
ffcea8b Rights
jakubvrana authored Jul 6, 2007
14 foreach ($fields as $key => $field) {
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
15 $name = $adminer->fieldName($field);
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
16 if (isset($field["privileges"]["select"]) && $name != "") {
1e4d11e Select from foreign keys in Editor
jakubvrana authored Jul 23, 2009
17 $columns[$key] = html_entity_decode(strip_tags($name));
375a5c8 @vrana Non-MySQL binary types
authored May 26, 2010
18 if (ereg('text|lob', $field["type"])) {
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
19 $text_length = $adminer->selectLengthProcess();
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
20 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
21 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
22 $rights += $field["privileges"];
23 }
24
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
25 list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
07e1ae1 FOUND_ROWS only with GROUP BY
jakubvrana authored Jul 28, 2009
26 $where = $adminer->selectSearchProcess($fields, $indexes);
27 $order = $adminer->selectOrderProcess($fields, $indexes);
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
28 $limit = $adminer->selectLimitProcess();
37d8146 @vrana Utilize oids in PostgreSQL
authored Feb 1, 2011
29 $from = ($select ? implode(", ", $select) : ($table_status["Oid"] == "t" ? "oid, " : "") . "*") . "\nFROM " . table($TABLE);
e44fbc2 Wrap SQL query
jakubvrana authored Mar 11, 2010
30 $group_by = ($group && count($group) < count($select) ? "\nGROUP BY " . implode(", ", $group) : "") . ($order ? "\nORDER BY " . implode(", ", $order) : "");
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
31
390e38b @vrana Load long texts for inline-edit by AJAX
authored Oct 18, 2010
32 if ($_GET["val"] && is_ajax()) {
33 header("Content-Type: text/plain; charset=utf-8");
34 foreach ($_GET["val"] as $unique_idf => $row) {
35 echo $connection->result("SELECT" . limit(idf_escape(key($row)) . " FROM " . table($TABLE), " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : ""), 1));
36 }
37 exit;
38 }
39
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
40 if ($_POST && !$error) {
56948c9 $_POST[check] may be empty
jakubvrana authored Jul 16, 2009
41 $where_check = "(" . implode(") OR (", array_map('where_check', (array) $_POST["check"])) . ")";
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
42 $primary = $unselected = null;
2ad8ab4 @vrana Primary key detection for other drivers
authored Jul 22, 2010
43 foreach ($indexes as $index) {
44 if ($index["type"] == "PRIMARY") {
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
45 $primary = array_flip($index["columns"]);
46 $unselected = ($select ? $primary : array());
2ad8ab4 @vrana Primary key detection for other drivers
authored Jul 22, 2010
47 break;
48 }
49 }
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
50 foreach ($select as $key => $val) {
51 $val = $_GET["columns"][$key];
52 if (!$val["fun"]) {
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
53 unset($unselected[$val["col"]]);
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
54 }
55 }
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
56 if ($_POST["export"]) {
8ab6fff @vrana Centralize dump_headers
authored Feb 17, 2011
57 dump_headers($TABLE);
095d472 @vrana Customizable export
authored Oct 29, 2010
58 $adminer->dumpTable($TABLE, "");
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
59 if (!is_array($_POST["check"]) || $unselected === array()) {
ee3e045 @vrana Separate $where in limit function
authored May 14, 2010
60 $where2 = $where;
61 if (is_array($_POST["check"])) {
62 $where2[] = "($where_check)";
63 }
15715b3 @vrana Export SQL command result (bug #3116854)
authored Feb 15, 2011
64 $query = "SELECT $from" . ($where2 ? "\nWHERE " . implode(" AND ", $where2) : "") . $group_by;
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
65 } else {
fa5c952 Use extended INSERT in select export
jakubvrana authored Jun 15, 2009
66 $union = array();
f7452ad Import and export
jakubvrana authored Apr 1, 2009
67 foreach ($_POST["check"] as $val) {
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
68 // where is not unique so OR can't be used
ee3e045 @vrana Separate $where in limit function
authored May 14, 2010
69 $union[] = "(SELECT" . limit($from, "\nWHERE " . ($where ? implode(" AND ", $where) . " AND " : "") . where_check($val) . $group_by, 1) . ")";
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
70 }
15715b3 @vrana Export SQL command result (bug #3116854)
authored Feb 15, 2011
71 $query = implode(" UNION ALL ", $union);
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
72 }
15715b3 @vrana Export SQL command result (bug #3116854)
authored Feb 15, 2011
73 $adminer->dumpData($TABLE, "table", $query);
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
74 exit;
75 }
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
76 if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
d90bde5 Fix delete in select
jakubvrana authored Apr 27, 2010
77 if ($_POST["save"] || $_POST["delete"]) { // edit
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
78 $result = true;
79 $affected = 0;
60c7ed9 @vrana MS SQL schema support
authored May 11, 2010
80 $query = table($TABLE);
28b2b8d Readable variable initialization
jakubvrana authored Jul 30, 2009
81 $set = array();
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
82 if (!$_POST["delete"]) {
83 foreach ($columns as $name => $val) { //! should check also for edit or insert privileges
a0def47 Date localization
jakubvrana authored Jul 27, 2009
84 $val = process_input($fields[$name]);
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
85 if ($val !== null) {
86 if ($_POST["clone"]) {
87 $set[idf_escape($name)] = ($val !== false ? $val : idf_escape($name));
88 } elseif ($val !== false) {
89 $set[] = idf_escape($name) . " = $val";
90 }
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
91 }
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
92 }
60c7ed9 @vrana MS SQL schema support
authored May 11, 2010
93 $query .= ($_POST["clone"] ? " (" . implode(", ", array_keys($set)) . ")\nSELECT " . implode(", ", $set) . "\nFROM " . table($TABLE) : " SET\n" . implode(",\n", $set));
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
94 }
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
95 if ($_POST["delete"] || $set) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
96 $command = "UPDATE";
97 if ($_POST["delete"]) {
98 $command = "DELETE";
99 $query = "FROM $query";
100 }
101 if ($_POST["clone"]) {
102 $command = "INSERT";
103 $query = "INTO $query";
104 }
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
105 if ($_POST["all"] || ($unselected === array() && $_POST["check"]) || count($group) < count($select)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
106 $result = queries($command . " $query" . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
64d616c Rename get_dbh to connection
jakubvrana authored Sep 22, 2009
107 $affected = $connection->affected_rows;
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
108 } else {
109 foreach ((array) $_POST["check"] as $val) {
110 // where is not unique so OR can't be used
ee3e045 @vrana Separate $where in limit function
authored May 14, 2010
111 $result = queries($command . limit1($query, "\nWHERE " . where_check($val)));
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
112 if (!$result) {
113 break;
114 }
64d616c Rename get_dbh to connection
jakubvrana authored Sep 22, 2009
115 $affected += $connection->affected_rows;
38059b6 Remove empty if
jakubvrana authored Jun 30, 2009
116 }
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
117 }
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
118 }
dbdd40a Introduce queries_redirect function
jakubvrana authored Oct 13, 2009
119 queries_redirect(remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result);
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
120 //! display edit page in case of an error
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
121 } elseif (!$_POST["import"]) { // modify
5050de5 @vrana Display modify hint as title
authored May 7, 2010
122 if (!$_POST["val"]) {
123 $error = lang('Double click on a value to modify it.');
124 } else {
125 $result = true;
126 $affected = 0;
127 foreach ($_POST["val"] as $unique_idf => $row) {
128 $set = array();
129 foreach ($row as $key => $val) {
130 $key = bracket_escape($key, 1); // 1 - back
0782a7b @vrana Save '' instead of NULL for empty char (some drivers don't have varchar)
authored Oct 17, 2010
131 $set[] = idf_escape($key) . " = " . (ereg('char|text', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
5050de5 @vrana Display modify hint as title
authored May 7, 2010
132 }
ca27ffc @vrana Display 0 in SQLite (bug #3120685)
authored Nov 29, 2010
133 $query = table($TABLE) . " SET " . implode(", ", $set);
134 $where2 = " WHERE " . where_check($unique_idf) . ($where ? " AND " . implode(" AND ", $where) : "");
135 $result = queries("UPDATE" . (count($group) < count($select) ? " $query$where2" : limit1($query, $where2))); // can change row on a different page without unique key
5050de5 @vrana Display modify hint as title
authored May 7, 2010
136 if (!$result) {
137 break;
138 }
139 $affected += $connection->affected_rows;
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
140 }
5050de5 @vrana Display modify hint as title
authored May 7, 2010
141 queries_redirect(remove_from_uri(), lang('%d item(s) have been affected.', $affected), $result);
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
142 }
25f01d3 Compress export and import
jakubvrana authored Aug 28, 2009
143 } elseif (is_string($file = get_file("csv_file", true))) {
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
144 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored Aug 20, 2009
145 $result = true;
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
146 $cols = array_keys($fields);
8a04897 Use atomic group for CSV regexp
jakubvrana authored Feb 24, 2010
147 preg_match_all('~(?>"[^"]*"|[^"\\r\\n]+)+~', $file, $matches);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
148 $affected = count($matches[0]);
d0c72ec Driver specific BEGIN
jakubvrana authored Apr 23, 2010
149 begin();
e225d22 @vrana TSV export and import (bug #3097657)
authored Oct 29, 2010
150 $separator = ($_POST["separator"] == "csv" ? "," : ($_POST["separator"] == "tsv" ? "\t" : ";"));
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
151 foreach ($matches[0] as $key => $val) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
152 preg_match_all("~((\"[^\"]*\")+|[^$separator]*)$separator~", $val . $separator, $matches2);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
153 if (!$key && !array_diff($matches2[1], $cols)) { //! doesn't work with column names containing ",\n
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
154 // first row corresponds to column names - use it for table structure
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
155 $cols = $matches2[1];
156 $affected--;
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
157 } else {
782921b @vrana Finish SQLite
authored May 27, 2010
158 $set = array();
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
159 foreach ($matches2[1] as $i => $col) {
7e644b4 @vrana Save bytes ($connection->quote shortcut)
authored Oct 13, 2010
160 $set[idf_escape($cols[$i])] = ($col == "" && $fields[$cols[$i]]["null"] ? "NULL" : q(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
161 }
6e50eb8 @vrana Pass primary key to insert_update function
authored Jul 22, 2010
162 $result = insert_update($TABLE, $set, $primary);
e895368 Use ON DUPLICATE KEY UPDATE for CSV import
jakubvrana authored Aug 30, 2009
163 if (!$result) {
164 break;
cb370a8 Respect max_allowed_packet in CSV import
jakubvrana authored Aug 20, 2009
165 }
166 }
167 }
6ba224b Rollback unsuccessful CSV import
jakubvrana authored Feb 24, 2010
168 if ($result) {
acf7a42 Improve CSV; export
jakubvrana authored Apr 22, 2010
169 queries("COMMIT");
6ba224b Rollback unsuccessful CSV import
jakubvrana authored Feb 24, 2010
170 }
dbdd40a Introduce queries_redirect function
jakubvrana authored Oct 13, 2009
171 queries_redirect(remove_from_uri("page"), lang('%d row(s) have been imported.', $affected), $result);
782921b @vrana Finish SQLite
authored May 27, 2010
172 queries("ROLLBACK"); // after queries_redirect() to not overwrite error
00d9b36 E-mail sending only in Editor
jakubvrana authored Jul 24, 2009
173 } else {
174 $error = upload_error($file);
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
175 }
ec23248 Exportable select
jakubvrana authored Aug 16, 2008
176 }
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
177 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
178
b9ffd64 Remove common prefix in backward key
jakubvrana authored Sep 8, 2009
179 $table_name = $adminer->tableName($table_status);
180 page_header(lang('Select') . ": $table_name", $error);
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
181 session_write_close();
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
182
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
183 $set = null;
430034c Cottage homework
jakubvrana authored Jul 9, 2007
184 if (isset($rights["insert"])) {
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
185 $set = "";
186 foreach ((array) $_GET["where"] as $val) {
187 if (count($foreign_keys[$val["col"]]) == 1 && ($val["op"] == "="
a1609c7 Align numbers to right in select
jakubvrana authored Sep 25, 2009
188 || (!$val["op"] && !ereg('[_%]', $val["val"])) // LIKE in Editor
98507da Function verify_version doesn't use version parameter
jakubvrana authored Jul 30, 2009
189 )) {
190 $set .= "&set" . urlencode("[" . bracket_escape($val["col"]) . "]") . "=" . urlencode($val["val"]);
191 }
192 }
667bfec Decomposition
jakubvrana authored Jul 2, 2007
193 }
f2ed237 Display table links above table structure
jakubvrana authored Sep 20, 2009
194 $adminer->selectLinks($table_status, $set);
667bfec Decomposition
jakubvrana authored Jul 2, 2007
195
ffcea8b Rights
jakubvrana authored Jul 6, 2007
196 if (!$columns) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
197 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
198 } else {
38894b2 @vrana Send all forms by AJAX
authored Nov 23, 2010
199 echo "<form action='' id='form'>\n";
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
200 echo "<div style='display: none;'>";
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
201 hidden_fields_get();
8878799 @vrana Respect namespace
authored May 6, 2010
202 echo (DB != "" ? '<input type="hidden" name="db" value="' . h(DB) . '">' . (isset($_GET["ns"]) ? '<input type="hidden" name="ns" value="' . h($_GET["ns"]) . '">' : "") : ""); // not used in Editor
79d1902 Substitute table name to $TABLE
jakubvrana authored Aug 29, 2009
203 echo '<input type="hidden" name="select" value="' . h($TABLE) . '">';
d24ad78 Select boxes customization
jakubvrana authored Jul 27, 2009
204 echo "</div>\n";
205 $adminer->selectColumnsPrint($select, $columns);
206 $adminer->selectSearchPrint($where, $columns, $indexes);
207 $adminer->selectOrderPrint($order, $columns, $indexes);
208 $adminer->selectLimitPrint($limit);
209 $adminer->selectLengthPrint($text_length);
210 $adminer->selectActionPrint($text_length);
ffcea8b Rights
jakubvrana authored Jul 6, 2007
211 echo "</form>\n";
212
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
213 $page = $_GET["page"];
214 if ($page == "last") {
60c7ed9 @vrana MS SQL schema support
authored May 11, 2010
215 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
31afb96 @vrana Last page with empty result (thanks to Frantisek Svoboda)
authored Oct 18, 2010
216 $page = floor(max(0, $found_rows - 1) / $limit);
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
217 }
218
04eccba @vrana Allow bigger numbers under 32 bits
authored Oct 22, 2010
219 $query = "SELECT" . limit((+$limit && $group && count($group) < count($select) && $jush == "sql" ? "SQL_CALC_FOUND_ROWS " : "") . $from, ($where ? "\nWHERE " . implode(" AND ", $where) : "") . $group_by, ($limit != "" ? +$limit : null), ($page ? $limit * $page : 0), "\n");
c64c4fd Adminer class
jakubvrana authored Jul 27, 2009
220 echo $adminer->selectQuery($query);
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored Sep 1, 2008
221
64d616c Rename get_dbh to connection
jakubvrana authored Sep 22, 2009
222 $result = $connection->query($query);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
223 if (!$result) {
c1130ed Simplify SQL syntax errors everywhere
jakubvrana authored Dec 17, 2009
224 echo "<p class='error'>" . error() . "\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
225 } else {
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
226 if ($jush == "mssql") {
1b144a1 MS SQL pagination
jakubvrana authored Apr 23, 2010
227 $result->seek($limit * $page);
228 }
f2365d0 Typo
jakubvrana authored Jul 11, 2009
229 $email_fields = array();
b535853 @vrana Full AJAX only with pushState to work correctly with history
authored Nov 12, 2010
230 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
231 $rows = array();
232 while ($row = $result->fetch_assoc()) {
233 $rows[] = $row;
234 }
235 // use count($rows) without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
1b144a1 MS SQL pagination
jakubvrana authored Apr 23, 2010
236 if ($_GET["page"] != "last") {
04eccba @vrana Allow bigger numbers under 32 bits
authored Oct 22, 2010
237 $found_rows = (+$limit && $group && count($group) < count($select)
e672694 @vrana Rename $driver to $jush
authored May 7, 2010
238 ? ($jush == "sql" ? $connection->result(" SELECT FOUND_ROWS()") : $connection->result("SELECT COUNT(*) FROM ($query) x")) // space to allow mysql.trace_mode
1b144a1 MS SQL pagination
jakubvrana authored Apr 23, 2010
239 : count($rows)
240 );
241 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
242
243 if (!$rows) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
244 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
245 } else {
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
246 $backward_keys = $adminer->backwardKeys($TABLE, $table_name);
c42c46a Table relations
jakubvrana authored Jul 15, 2009
247
241fc4e @vrana Ctrl+Up and Down in edit and in-place edit
authored Jan 25, 2011
248 echo "<table cellspacing='0' class='nowrap' onclick='tableClick(event);' onkeydown='return editingKeydown(event);'>\n";
22a7ebd @vrana Hide edit link without columns
authored Jul 1, 2010
249 echo "<thead><tr>" . (!$group && $select ? "" : "<td><input type='checkbox' id='all-page' onclick='formCheck(this, /check/);'> <a href='" . h($_GET["modify"] ? remove_from_uri("modify") : $_SERVER["REQUEST_URI"] . "&modify=1") . "'>" . lang('edit') . "</a>");
5034123 Apply field name with functions
jakubvrana authored Jul 23, 2009
250 $names = array();
c40d1d0 Always handle double click
jakubvrana authored Apr 26, 2010
251 $functions = array();
5034123 Apply field name with functions
jakubvrana authored Jul 23, 2009
252 reset($select);
9bc9b9f @vrana Don't overwrite variable
authored Oct 24, 2010
253 $rank = 1;
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
254 foreach ($rows[0] as $key => $val) {
37d8146 @vrana Utilize oids in PostgreSQL
authored Feb 1, 2011
255 if ($table_status["Oid"] != "t" || $key != "oid") {
256 $val = $_GET["columns"][key($select)];
257 $field = $fields[$select ? $val["col"] : $key];
258 $name = ($field ? $adminer->fieldName($field, $rank) : "*");
259 if ($name != "") {
260 $rank++;
261 $names[$key] = $name;
262 $column = idf_escape($key);
263 echo '<th><a href="' . h(remove_from_uri('(order|desc)[^=]*|page') . '&order%5B0%5D=' . urlencode($key) . ($order[0] == $column || $order[0] == $key || (!$order && $group[0] == $column) ? '&desc%5B0%5D=1' : '')) . '">' . apply_sql_function($val["fun"], $name) . "</a>"; // $order[0] == $key - COUNT(*) //! columns looking like functions
264 }
265 $functions[$key] = $val["fun"];
266 next($select);
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
267 }
ba90d60 Introduce adminer_select_val
jakubvrana authored Jul 14, 2009
268 }
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
269 $lengths = array();
270 if ($_GET["modify"]) {
271 foreach ($rows as $row) {
272 foreach ($row as $key => $val) {
273 $lengths[$key] = max($lengths[$key], min(40, strlen(utf8_decode($val))));
274 }
275 }
276 }
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
277 echo ($backward_keys ? "<th>" . lang('Relations') : "") . "</thead>\n";
dea345c Substitute foreign keys in e-mail fields
jakubvrana authored Sep 9, 2009
278 foreach ($adminer->rowDescriptions($rows, $foreign_keys) as $n => $row) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
279 $unique_array = unique_array($rows[$n], $indexes);
16290b0 Respect where in COUNT(*) link
jakubvrana authored Apr 15, 2010
280 $unique_idf = "";
281 foreach ($unique_array as $key => $val) {
282 $unique_idf .= "&" . (isset($val) ? urlencode("where[" . bracket_escape($key) . "]") . "=" . urlencode($val) : "null%5B%5D=" . urlencode($key));
283 }
22a7ebd @vrana Hide edit link without columns
authored Jul 1, 2010
284 echo "<tr" . odd() . ">" . (!$group && $select ? "" : "<td>" . checkbox("check[]", substr($unique_idf, 1), in_array(substr($unique_idf, 1), (array) $_POST["check"]), "", "this.form['all'].checked = false; formUncheck('all-page');") . (count($group) < count($select) || information_schema(DB) ? "" : " <a href='" . h(ME . "edit=" . urlencode($TABLE) . $unique_idf) . "'>" . lang('edit') . "</a>"));
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
285 foreach ($row as $key => $val) {
78e49f0 Pass $field to select_val
jakubvrana authored Jul 24, 2009
286 if (isset($names[$key])) {
a1609c7 Align numbers to right in select
jakubvrana authored Sep 25, 2009
287 $field = $fields[$key];
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
288 if ($val != "" && (!isset($email_fields[$key]) || $email_fields[$key] != "")) {
1cf374b @vrana Rename functions (avoid conflict with WordPress)
authored Oct 16, 2010
289 $email_fields[$key] = (is_mail($val) ? $names[$key] : ""); //! filled e-mails can be contained on other pages
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
290 }
5911cf1 Always call select_val
jakubvrana authored Jul 21, 2009
291 $link = "";
a1609c7 Align numbers to right in select
jakubvrana authored Sep 25, 2009
292 $val = $adminer->editVal($val, $field);
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
293 if (!isset($val)) {
294 $val = "<i>NULL</i>";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
295 } else {
5a73c01 @vrana Treat binary type as hex
authored Sep 28, 2010
296 if (ereg('blob|bytea|raw|file', $field["type"]) && $val != "") {
35ec64c Link COUNT(*) result to listing
jakubvrana authored Apr 2, 2010
297 $link = h(ME . 'download=' . urlencode($TABLE) . '&field=' . urlencode($key) . $unique_idf);
97b8c7b Display images in Editor
jakubvrana authored Jul 24, 2009
298 }
ca27ffc @vrana Display 0 in SQLite (bug #3120685)
authored Nov 29, 2010
299 if ($val === "") { // === - may be int
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
300 $val = "&nbsp;";
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
301 } elseif ($text_length != "" && ereg('text|blob', $field["type"]) && is_utf8($val)) {
04eccba @vrana Allow bigger numbers under 32 bits
authored Oct 22, 2010
302 $val = shorten_utf8($val, max(0, +$text_length)); // usage of LEFT() would reduce traffic but complicate query - expected average speedup: .001 s VS .01 s on local network
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
303 } else {
50881f8 Move whitespace to CSS
jakubvrana authored Oct 13, 2009
304 $val = h($val);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
305 }
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
306
db46fc2 Maintain insert prefill value
jakubvrana authored Aug 3, 2009
307 if (!$link) { // link related items
308 foreach ((array) $foreign_keys[$key] as $foreign_key) {
81f58ed @vrana Link more foreign keys
authored Nov 3, 2010
309 if (count($foreign_keys[$key]) == 1 || end($foreign_key["source"]) == $key) {
310 $link = "";
db46fc2 Maintain insert prefill value
jakubvrana authored Aug 3, 2009
311 foreach ($foreign_key["source"] as $i => $source) {
312 $link .= where_link($i, $foreign_key["target"][$i], $rows[$n][$source]);
313 }
7352c28 Replace strlen() by != ""
jakubvrana authored Jan 9, 2010
314 $link = h(($foreign_key["db"] != "" ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), ME) : ME) . 'select=' . urlencode($foreign_key["table"]) . $link); // InnoDB supports non-UNIQUE keys
81f58ed @vrana Link more foreign keys
authored Nov 3, 2010
315 if (count($foreign_key["source"]) == 1) {
316 break;
317 }
116c873 Ignore tables and fields with empty name
jakubvrana authored Jul 21, 2009
318 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
319 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
320 }
35ec64c Link COUNT(*) result to listing
jakubvrana authored Apr 2, 2010
321 if ($key == "COUNT(*)") { //! columns looking like functions
322 $link = h(ME . "select=" . urlencode($TABLE));
323 $i = 0;
16290b0 Respect where in COUNT(*) link
jakubvrana authored Apr 15, 2010
324 foreach ((array) $_GET["where"] as $v) {
325 if (!array_key_exists($v["col"], $unique_array)) {
22eb69b @vrana Remove operator double encode
authored May 12, 2010
326 $link .= h(where_link($i++, $v["col"], $v["val"], $v["op"]));
16290b0 Respect where in COUNT(*) link
jakubvrana authored Apr 15, 2010
327 }
328 }
329 foreach ($unique_array as $k => $v) {
8062648 @vrana Use IS NULL operator for null value in where_link function
authored Feb 8, 2011
330 $link .= h(where_link($i++, $k, $v));
35ec64c Link COUNT(*) result to listing
jakubvrana authored Apr 2, 2010
331 }
332 }
fa3dd55 Parent
jakubvrana authored Jul 2, 2007
333 }
2cec758 @vrana Direct links from HTTPS to HTTP
authored May 25, 2010
334 if (!$link) {
1cf374b @vrana Rename functions (avoid conflict with WordPress)
authored Oct 16, 2010
335 if (is_mail($val)) {
2cec758 @vrana Direct links from HTTPS to HTTP
authored May 25, 2010
336 $link = "mailto:$val";
337 }
338 if ($protocol = is_url($row[$key])) {
339 $link = ($protocol == "http" && $HTTPS
340 ? $row[$key] // HTTP links from HTTPS pages don't receive Referer automatically
341 : "$protocol://www.adminer.org/redirect/?url=" . urlencode($row[$key]) // intermediate page to hide Referer, may be changed to rel="noreferrer" in HTML5
342 );
343 }
bc78866 Link URLs in select
jakubvrana authored Oct 2, 2009
344 }
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
345 $id = h("val[$unique_idf][" . bracket_escape($key) . "]");
de24145 @vrana Clear POST with AJAX redirect
authored Oct 18, 2010
346 $value = $_POST["val"][$unique_idf][bracket_escape($key)];
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
347 $h_value = h(isset($value) ? $value : $row[$key]);
687b3fd @vrana Replace <strong> by <b> and <em> by <i>
authored May 20, 2010
348 $long = strpos($val, "<i>...</i>");
390e38b @vrana Load long texts for inline-edit by AJAX
authored Oct 18, 2010
349 $editable = is_utf8($val) && $rows[$n][$key] == $row[$key] && !$functions[$key];
375a5c8 @vrana Non-MySQL binary types
authored May 26, 2010
350 $text = ereg('text|lob', $field["type"]);
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
351 echo (($_GET["modify"] && $editable) || isset($value)
71438d5 @vrana Handle keypress instead of keydown (bug #3112458)
authored Nov 19, 2010
352 ? "<td>" . ($text ? "<textarea name='$id' cols='30' rows='" . (substr_count($row[$key], "\n") + 1) . "' onkeypress='return textareaKeypress(this, event);'>$h_value</textarea>" : "<input name='$id' value='$h_value' size='$lengths[$key]'>")
390e38b @vrana Load long texts for inline-edit by AJAX
authored Oct 18, 2010
353 : "<td id='$id' ondblclick=\"" . ($editable ? "selectDblClick(this, event" . ($long ? ", 2" : ($text ? ", 1" : "")) . ")" : "alert('" . h(lang('Use edit link to modify this value.')) . "')") . ";\">" . $adminer->selectVal($val, $link, $field)
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
354 );
667bfec Decomposition
jakubvrana authored Jul 2, 2007
355 }
356 }
33aec2c @vrana Move <td> from Adminer::backwardKeysPrint
authored Jan 18, 2011
357 if ($backward_keys) {
358 echo "<td>";
359 }
09e93de Move backward keys to Editor
jakubvrana authored Sep 23, 2009
360 $adminer->backwardKeysPrint($backward_keys, $rows[$n]);
26e8ab9 Close </tr> because of white-space: pre
jakubvrana authored Oct 30, 2009
361 echo "</tr>\n"; // close to allow white-space: pre
5ab708a Compact pages
jakubvrana authored Jul 25, 2007
362 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
363 echo "</table>\n";
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
364 }
365
366 parse_str($_COOKIE["adminer_export"], $adminer_export);
367
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
368 if ($rows || $page) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
369 $exact_count = true;
04eccba @vrana Allow bigger numbers under 32 bits
authored Oct 22, 2010
370 if ($_GET["page"] != "last" && +$limit && count($group) >= count($select) && ($found_rows >= $limit || $page)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
371 $found_rows = $table_status["Rows"];
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
372 if (!isset($found_rows) || $where || 2 * $page * $limit > $found_rows || ($table_status["Engine"] == "InnoDB" && $found_rows < 1e4)) {
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
373 // slow with big tables
374 ob_flush();
375 flush();
60c7ed9 @vrana MS SQL schema support
authored May 11, 2010
376 $found_rows = $connection->result("SELECT COUNT(*) FROM " . table($TABLE) . ($where ? " WHERE " . implode(" AND ", $where) : ""));
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
377 } else {
378 $exact_count = false;
379 }
4cdc459 FOUND_ROWS works with last SELECT
jakubvrana authored Jul 16, 2009
380 }
fde1171 Add CSS classes (thanks to cvicebni ubor)
jakubvrana authored Oct 28, 2009
381 echo "<p class='pages'>";
04eccba @vrana Allow bigger numbers under 32 bits
authored Oct 22, 2010
382 if (+$limit && $found_rows > $limit) {
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
383 // display first, previous 4, next 4 and last page
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
384 $max_page = floor(($found_rows - 1) / $limit);
9802869 @vrana Merge from master
authored Nov 12, 2010
385 echo '<a href="' . h(remove_from_uri("page")) . "\" onclick=\"pageClick(this.href, +prompt('" . lang('Page') . "', '" . ($page + 1) . "'), event); return false;\">" . lang('Page') . "</a>:";
6e3c7cb @vrana Use AJAX for pagination
authored Oct 18, 2010
386 echo pagination(0, $page) . ($page > 5 ? " ..." : "");
bd25295 Don't redirect from last page
jakubvrana authored Apr 22, 2010
387 for ($i = max(1, $page - 4); $i < min($max_page, $page + 5); $i++) {
388 echo pagination($i, $page);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
389 }
6585b23 @vrana Generic AJAX links
authored Nov 22, 2010
390 echo ($page + 5 < $max_page ? " ..." : "") . ($exact_count ? pagination($max_page, $page) : ' <a href="' . h(remove_from_uri() . "&page=last") . '">' . lang('last') . "</a>");
5ab708a Compact pages
jakubvrana authored Jul 25, 2007
391 }
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
392 echo " (" . ($exact_count ? "" : "~ ") . lang('%d row(s)', $found_rows) . ") " . checkbox("all", 1, 0, lang('whole result')) . "\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored Sep 1, 2008
393
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
394 if (!information_schema(DB)) {
395 ?>
396 <fieldset><legend><?php echo lang('Edit'); ?></legend><div>
38894b2 @vrana Send all forms by AJAX
authored Nov 23, 2010
397 <input type="submit" id="save" value="<?php echo lang('Save'); ?>" title="<?php echo lang('Double click on a value to modify it.'); ?>">
398 <input type="submit" name="edit" value="<?php echo lang('Edit'); ?>">
399 <input type="submit" name="clone" value="<?php echo lang('Clone'); ?>">
400 <input type="submit" name="delete" value="<?php echo lang('Delete'); ?>" onclick="return confirm('<?php echo lang('Are you sure?'); ?> (' + (this.form['all'].checked ? <?php echo $found_rows; ?> : formChecked(this, /check/)) + ')');">
e0d9b3c In-place editation in select
jakubvrana authored Apr 23, 2010
401 </div></fieldset>
402 <?php
403 }
dc667ea Hide select export and import
jakubvrana authored Sep 11, 2009
404 print_fieldset("export", lang('Export'));
be3410f @vrana Simplify dumpOutput, dumpFormat and dumpData methods
authored Oct 29, 2010
405 $output = $adminer->dumpOutput();
9e8ab1d @vrana Whitespace
authored Jan 31, 2011
406 echo ($output ? html_select("output", $output, $adminer_export["output"]) . " " : "");
407 echo html_select("format", $adminer->dumpFormat(), $adminer_export["format"]);
fc6e71a @vrana Disable AJAX export
authored Dec 2, 2010
408 echo " <input type='submit' name='export' value='" . lang('Export') . "' onclick='eventStop(event);'>\n";
dc667ea Hide select export and import
jakubvrana authored Sep 11, 2009
409 echo "</div></fieldset>\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
410 }
56b0377 @vrana Import supports TSV
authored Jan 27, 2011
411 print_fieldset("import", lang('Import'), !$rows);
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
412 echo "<input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> ";
e225d22 @vrana TSV export and import (bug #3097657)
authored Oct 29, 2010
413 echo html_select("separator", array("csv" => "CSV,", "csv;" => "CSV;", "tsv" => "TSV"), $adminer_export["format"], 1); // 1 - select
3f5b683 Reintegrate sqlite branch
jakubvrana authored Apr 21, 2010
414 echo " <input type='submit' name='import' value='" . lang('Import') . "'>\n";
dc667ea Hide select export and import
jakubvrana authored Sep 11, 2009
415 echo "</div></fieldset>\n";
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
416
1e55d47 User interface for e-mail {$name}
jakubvrana authored Sep 9, 2009
417 $adminer->selectEmailPrint(array_filter($email_fields, 'strlen'), $columns);
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
418
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
419 echo "</form>\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
420 }
421 }
Something went wrong with that request. Please try again.