Skip to content
Newer
Older
100644 367 lines (346 sloc) 18.6 KB
667bfec Decomposition
jakubvrana authored Jul 2, 2007
1 <?php
d72bf4c Select specific variables
jakubvrana authored Apr 7, 2009
2 $functions = array("char_length", "from_unixtime", "hex", "lower", "round", "sec_to_time", "time_to_sec", "unix_timestamp", "upper");
64ba924 Comments
jakubvrana authored Jun 21, 2009
3 $grouping = array("avg", "count", "distinct", "group_concat", "max", "min", "sum"); // distinct is short for COUNT(DISTINCT)
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
4 $table_status = table_status($_GET["select"]);
5 $indexes = indexes($_GET["select"]);
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
6 $primary = null; // empty array means that all primary fields are selected
7 foreach ($indexes as $index) {
8 if ($index["type"] == "PRIMARY") {
9 $primary = array_flip($index["columns"]);
10 }
11 }
26c2ff0 NOT operators
jakubvrana authored Sep 23, 2008
12 $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IN", "IS NULL", "NOT LIKE", "NOT REGEXP", "NOT IN", "IS NOT NULL");
f78779b Maria engine supports fulltext
jakubvrana authored Oct 15, 2008
13 if (eregi('^(MyISAM|Maria)$', $table_status["Engine"])) {
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
14 $operators[] = "AGAINST";
15 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
16 $fields = fields($_GET["select"]);
64ba924 Comments
jakubvrana authored Jun 21, 2009
17 $rights = array(); // privilege => 0
18 $columns = array(); // selectable columns
02a851c Shorten texts in PHP
jakubvrana authored Aug 24, 2007
19 unset($text_length);
ffcea8b Rights
jakubvrana authored Jul 6, 2007
20 foreach ($fields as $key => $field) {
430034c Cottage homework
jakubvrana authored Jul 9, 2007
21 if (isset($field["privileges"]["select"])) {
dd882b1 $columns variable is used only in optionlist
jakubvrana authored Jul 13, 2009
22 $columns[$key] = html_entity_decode(strip_tags(adminer_field_name($fields, $key))); //! numeric $key is problematic in optionlist()
5abd943 Change simple preg_match to ereg
jakubvrana authored Jul 13, 2009
23 if (ereg('text|blob', $field["type"])) {
02a851c Shorten texts in PHP
jakubvrana authored Aug 24, 2007
24 $text_length = (isset($_GET["text_length"]) ? $_GET["text_length"] : "100");
25 }
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
26 if (!$_GET["columns"]) {
27 unset($primary[$key]);
28 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
29 }
430034c Cottage homework
jakubvrana authored Jul 9, 2007
30 $rights += $field["privileges"];
31 }
32
64ba924 Comments
jakubvrana authored Jun 21, 2009
33 $select = array(); // select expressions, empty for *
34 $group = array(); // expressions without aggregation - will be used for GROUP BY if an aggregation function is used
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
35 foreach ((array) $_GET["columns"] as $key => $val) {
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
36 if ($val["fun"] == "count" || (isset($columns[$val["col"]]) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
37 $select[$key] = (isset($columns[$val["col"]]) ? ($val["fun"] ? ($val["fun"] == "distinct" ? "COUNT(DISTINCT " : strtoupper("$val[fun](")) . idf_escape($val["col"]) . ")" : idf_escape($val["col"])) : "COUNT(*)");
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
38 if (!in_array($val["fun"], $grouping)) {
39 $group[] = $select[$key];
40 }
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
41 if (!$val["fun"]) {
42 unset($primary[$val["col"]]);
43 }
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
44 }
45 }
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
46
64ba924 Comments
jakubvrana authored Jun 21, 2009
47 $where = array(); // where expressions - will be joined by AND
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
48 foreach ($indexes as $i => $index) {
49 if ($index["type"] == "FULLTEXT" && strlen($_GET["fulltext"][$i])) {
36a3656 Change escape_string to quote
jakubvrana authored Jun 22, 2009
50 $where[] = "MATCH (" . implode(", ", array_map('idf_escape', $index["columns"])) . ") AGAINST (" . $dbh->quote($_GET["fulltext"][$i]) . (isset($_GET["boolean"][$i]) ? " IN BOOLEAN MODE" : "") . ")";
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
51 }
52 }
53 foreach ((array) $_GET["where"] as $val) {
25bc058 Search in any column
jakubvrana authored Oct 9, 2008
54 if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
55 if ($val["op"] == "AGAINST") {
36a3656 Change escape_string to quote
jakubvrana authored Jun 22, 2009
56 $where[] = "MATCH (" . idf_escape($val["col"]) . ") AGAINST (" . $dbh->quote($val["val"]) . " IN BOOLEAN MODE)";
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
57 } else {
68c46b4 Translate empty IN to NULL
jakubvrana authored Jun 22, 2009
58 $in = process_length($val["val"]);
ab6d105 Remove IS NULL hiding
jakubvrana authored Jul 2, 2009
59 $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $dbh->quote($val["val"])));
25bc058 Search in any column
jakubvrana authored Oct 9, 2008
60 if (strlen($val["col"])) {
61 $where[] = idf_escape($val["col"]) . $cond;
62 } else {
64ba924 Comments
jakubvrana authored Jun 21, 2009
63 // find anywhere
25bc058 Search in any column
jakubvrana authored Oct 9, 2008
64 $cols = array();
65 foreach ($fields as $name => $field) {
66 if (is_numeric($val["val"]) || !ereg('int|float|double|decimal', $field["type"])) {
67 $cols[] = $name;
68 }
69 }
70 $where[] = ($cols ? "(" . implode("$cond OR ", array_map('idf_escape', $cols)) . "$cond)" : "0");
71 }
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
72 }
73 }
74 }
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
75
64ba924 Comments
jakubvrana authored Jun 21, 2009
76 $order = array(); // order expressions - will be joined by comma
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
77 foreach ((array) $_GET["order"] as $key => $val) {
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
78 if (isset($columns[$val]) || in_array($val, $select, true)) {
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
79 $order[] = idf_escape($val) . (isset($_GET["desc"][$key]) ? " DESC" : "");
80 }
81 }
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
82
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
83 $limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
4c736a0 Use group by in export
jakubvrana authored Jun 22, 2009
84 $from = ($select ? implode(", ", $select) : "*") . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "");
85 $group_by = ($group && count($group) < count($select) ? " GROUP BY " . implode(", ", $group) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "");
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
86
87 if ($_POST && !$error) {
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
88 $where_check = "(" . implode(") OR (", array_map('where_check', $_POST["check"])) . ")";
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
89 if ($_POST["export"]) {
9890b6c Export Output in select.inc.php
jakubvrana authored Aug 18, 2008
90 dump_headers($_GET["select"]);
f48161b CSV Byte-order-mark
jakubvrana authored Aug 18, 2008
91 dump_table($_GET["select"], "");
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
92 if (!is_array($_POST["check"]) || $primary === array()) {
93 dump_data($_GET["select"], "INSERT", "SELECT $from" . (is_array($_POST["check"]) ? ($where ? " AND " : " WHERE ") . "($where_check)" : "") . $group_by);
94 } else {
fa5c952 Use extended INSERT in select export
jakubvrana authored Jun 15, 2009
95 $union = array();
f7452ad Import and export
jakubvrana authored Apr 1, 2009
96 foreach ($_POST["check"] as $val) {
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
97 // where is not unique so OR can't be used
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
98 $union[] = "(SELECT $from " . ($where ? "AND " : "WHERE ") . where_check($val) . $group_by . " LIMIT 1)";
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
99 }
fa5c952 Use extended INSERT in select export
jakubvrana authored Jun 15, 2009
100 dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
101 }
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
102 exit;
103 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
104 if ($_POST["email"]) {
105 $sent = 0;
106 if ($_POST["all"] || $_POST["check"]) {
107 $field = idf_escape($_POST["email_field"]);
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
108 $result = $dbh->query("SELECT DISTINCT $field FROM " . idf_escape($_GET["select"]) . " WHERE $field IS NOT NULL AND $field != ''" . ($where ? " AND " . implode(" AND ", $where) : "") . ($_POST["all"] ? "" : " AND ($where_check)"));
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
109 while ($row = $result->fetch_row()) {
110 $sent += mail($row[0], email_header($_POST["email_subject"]), $_POST["email_message"], "MIME-Version: 1.0\nContent-Type: text/plain; charset=utf-8\nContent-Transfer-Encoding: 8bit" . ($_POST["email_from"] ? "\nFrom: " . email_header($_POST["email_from"]) : ""));
111 }
112 $result->free();
113 }
114 redirect(remove_from_uri(), lang('%d e-mail(s) have been sent.', $sent));
115 } elseif (!$_POST["import"]) { // edit
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
116 $result = true;
117 $affected = 0;
118 $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
119 if (!$_POST["delete"]) {
120 $set = array();
121 foreach ($fields as $name => $field) {
122 $val = process_input($name, $field);
123 if ($_POST["clone"]) {
124 $set[] = ($val !== false ? $val : idf_escape($name));
125 } elseif ($val !== false) {
1f90ab2 Newlines in queries
jakubvrana authored Jul 13, 2009
126 $set[] = idf_escape($name) . " = $val";
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
127 }
128 }
1f90ab2 Newlines in queries
jakubvrana authored Jul 13, 2009
129 $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . "\nFROM " . idf_escape($_GET["select"]) : " SET\n" . implode(",\n", $set));
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
130 }
38059b6 Remove empty if
jakubvrana authored Jun 30, 2009
131 if ($_POST["delete"] || $set) {
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
132 if ($_POST["all"] || ($primary === array() && $_POST["check"])) {
133 $result = queries($command . ($_POST["all"] ? ($where ? "\nWHERE " . implode(" AND ", $where) : "") : "\nWHERE $where_check"));
38059b6 Remove empty if
jakubvrana authored Jun 30, 2009
134 $affected = $dbh->affected_rows;
135 } else {
136 foreach ((array) $_POST["check"] as $val) {
16c4ddb Single faster POST query with primary key
jakubvrana authored Jul 13, 2009
137 // where is not unique so OR can't be used
1f90ab2 Newlines in queries
jakubvrana authored Jul 13, 2009
138 $result = queries($command . "\nWHERE " . where_check($val) . "\nLIMIT 1");
38059b6 Remove empty if
jakubvrana authored Jun 30, 2009
139 if (!$result) {
140 break;
141 }
142 $affected += $dbh->affected_rows;
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
143 }
78639a9 Function results in edit
jakubvrana authored Oct 1, 2008
144 }
145 }
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
146 query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
147 //! display edit page in case of an error
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
148 } elseif (is_string($file = get_file("csv_file"))) {
149 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
150 $cols = "";
151 $rows = array(); //! packet size
152 preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
153 foreach ($matches[0] as $key => $val) {
154 $row = array();
155 preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
156 if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
64ba924 Comments
jakubvrana authored Jun 21, 2009
157 // first row corresponds to column names - use it for table structure
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
158 $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
159 } else {
160 foreach ($matches2[1] as $col) {
67b4653 Simplify import quotes removal
jakubvrana authored Jul 13, 2009
161 $row[] = (!strlen($col) ? "NULL" : $dbh->quote(str_replace('""', '"', preg_replace('~^"|"$~', '', $col))));
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
162 }
64ba924 Comments
jakubvrana authored Jun 21, 2009
163 $rows[] = "\n(" . implode(", ", $row) . ")";
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
164 }
165 }
64ba924 Comments
jakubvrana authored Jun 21, 2009
166 $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES" . implode(",", $rows));
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
167 query_redirect(queries(), remove_from_uri("page"), lang('%d row(s) has been imported.', $dbh->affected_rows), $result, false, !$result);
d83b654 Detect import errors
jakubvrana authored Apr 16, 2009
168 } else {
169 $error = lang('Unable to upload a file.');
ec23248 Exportable select
jakubvrana authored Aug 16, 2008
170 }
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
171 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
172
173 page_header(lang('Select') . ": " . adminer_table_name($table_status), $error);
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
174
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored Jan 23, 2009
175 echo "<p>";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
176 if (isset($rights["insert"])) {
3d254a3 TODO
jakubvrana authored Jul 15, 2007
177 //! pass search values forth and back
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored Jan 23, 2009
178 echo '<a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . '</a> ';
667bfec Decomposition
jakubvrana authored Jul 2, 2007
179 }
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
180 echo adminer_select_links($table_status);
667bfec Decomposition
jakubvrana authored Jul 2, 2007
181
ffcea8b Rights
jakubvrana authored Jul 6, 2007
182 if (!$columns) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
183 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
184 } else {
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
185 echo "<form action='' id='form'>\n";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
186 echo '<fieldset><legend><a href="#fieldset-select" onclick="return !toggle(\'fieldset-select\');">' . lang('Select') . "</a></legend><div id='fieldset-select'" . ($select ? "" : " class='hidden'") . ">\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
187 if (strlen($_GET["server"])) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
188 echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '">';
667bfec Decomposition
jakubvrana authored Jul 2, 2007
189 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
190 echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '">';
191 echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '">';
ffcea8b Rights
jakubvrana authored Jul 6, 2007
192 echo "\n";
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
193 $i = 0;
194 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
195 foreach ($select as $key => $val) {
196 $val = $_GET["columns"][$key];
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
197 echo "<div><select name='columns[$i][fun]'><option>" . optionlist($fun_group, $val["fun"]) . "</select>";
198 echo "<select name='columns[$i][col]'><option>" . optionlist($columns, $val["col"]) . "</select></div>\n";
5ee29cb Select columns, aggregation
jakubvrana authored Aug 7, 2008
199 $i++;
200 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
201 echo "<div><select name='columns[$i][fun]' onchange='this.nextSibling.onchange();'><option>" . optionlist($fun_group) . "</select>";
202 echo "<select name='columns[$i][col]' onchange='select_add_row(this);'><option>" . optionlist($columns) . "</select></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
203 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
204
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
205 echo '<fieldset><legend><a href="#fieldset-search" onclick="return !toggle(\'fieldset-search\');">' . lang('Search') . "</a></legend><div id='fieldset-search'" . ($where ? "" : " class='hidden'") . ">\n";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
206 foreach ($indexes as $i => $index) {
207 if ($index["type"] == "FULLTEXT") {
9e2848d Escape fulltext columns
jakubvrana authored Jul 14, 2007
208 echo "(<i>" . implode("</i>, <i>", array_map('htmlspecialchars', $index["columns"])) . "</i>) AGAINST";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
209 echo ' <input name="fulltext[' . $i . ']" value="' . htmlspecialchars($_GET["fulltext"][$i]) . '">';
210 echo "<label><input type='checkbox' name='boolean[$i]' value='1'" . (isset($_GET["boolean"][$i]) ? " checked='checked'" : "") . ">" . lang('BOOL') . "</label>";
211 echo "<br>\n";
430034c Cottage homework
jakubvrana authored Jul 9, 2007
212 }
213 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
214 $i = 0;
215 foreach ((array) $_GET["where"] as $val) {
25bc058 Search in any column
jakubvrana authored Oct 9, 2008
216 if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
217 echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . optionlist($columns, $val["col"]) . "</select>";
ab6d105 Remove IS NULL hiding
jakubvrana authored Jul 2, 2009
218 echo "<select name='where[$i][op]'>" . optionlist($operators, $val["op"]) . "</select>";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
219 echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\"></div>\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
220 $i++;
221 }
222 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
223 echo "<div><select name='where[$i][col]' onchange='select_add_row(this);'><option value=''>" . lang('(anywhere)') . optionlist($columns) . "</select>";
ab6d105 Remove IS NULL hiding
jakubvrana authored Jul 2, 2009
224 echo "<select name='where[$i][op]'>" . optionlist($operators) . "</select>";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
225 echo "<input name='where[$i][val]'></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
226 echo "</div></fieldset>\n";
227
228 echo '<fieldset><legend><a href="#fieldset-sort" onclick="return !toggle(\'fieldset-sort\');">' . lang('Sort') . "</a></legend><div id='fieldset-sort'" . (count($order) > 1 ? "" : " class='hidden'") . ">\n";
229 $i = 0;
230 foreach ((array) $_GET["order"] as $key => $val) {
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
231 if (isset($columns[$val])) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
232 echo "<div><select name='order[$i]'><option>" . optionlist($columns, $val) . "</select>";
233 echo "<label><input type='checkbox' name='desc[$i]' value='1'" . (isset($_GET["desc"][$key]) ? " checked='checked'" : "") . ">" . lang('descending') . "</label></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
234 $i++;
235 }
236 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
237 echo "<div><select name='order[$i]' onchange='select_add_row(this);'><option>" . optionlist($columns) . "</select>";
238 echo "<label><input type='checkbox' name='desc[$i]' value='1'>" . lang('descending') . "</label></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
239 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
240
64ba924 Comments
jakubvrana authored Jun 21, 2009
241 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
242 echo "<input name='limit' size='3' value=\"" . htmlspecialchars($limit) . "\">";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
243 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
244
63441b1 Max text length
jakubvrana authored Jul 11, 2007
245 if (isset($text_length)) {
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
246 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
247 echo "<input name='text_length' size='3' value=\"" . htmlspecialchars($text_length) . "\">";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
248 echo "</div></fieldset>\n";
63441b1 Max text length
jakubvrana authored Jul 11, 2007
249 }
250
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
251 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
252 echo "<input type='submit' value='" . lang('Select') . "'>";
b142000 Hide fieldsets in select
jakubvrana authored Jun 15, 2009
253 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
254 echo "</form>\n";
255
4c736a0 Use group by in export
jakubvrana authored Jun 22, 2009
256 $query = "SELECT " . (count($group) < count($select) ? "SQL_CALC_FOUND_ROWS " : "") . $from . $group_by . (strlen($limit) ? " LIMIT " . intval($limit) . (intval($_GET["page"]) ? " OFFSET " . ($limit * $_GET["page"]) : "") : "");
c74c06a Don't modify $query by adminer_select_query
jakubvrana authored Jul 11, 2009
257 echo adminer_select_query($query);
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored Sep 1, 2008
258
5f16c75 Prepare for version 2
jakubvrana authored May 8, 2009
259 $result = $dbh->query($query);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
260 if (!$result) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
261 echo "<p class='error'>" . htmlspecialchars($dbh->error) . "\n";
ffcea8b Rights
jakubvrana authored Jul 6, 2007
262 } else {
f2365d0 Typo
jakubvrana authored Jul 11, 2009
263 $email_fields = array();
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
264 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
265 if (!$result->num_rows) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
266 echo "<p class='message'>" . lang('No rows.') . "\n";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
267 } else {
268 $foreign_keys = array();
269 foreach (foreign_keys($_GET["select"]) as $foreign_key) {
270 foreach ($foreign_key["source"] as $val) {
271 $foreign_keys[$val][] = $foreign_key;
272 }
ffcea8b Rights
jakubvrana authored Jul 6, 2007
273 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
274
d30face Remove useless table attributes (thanks to Juraj Krivda)
jakubvrana authored May 1, 2009
275 echo "<table cellspacing='0' class='nowrap'>\n";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
276 for ($j=0; $row = $result->fetch_assoc(); $j++) {
277 if (!$j) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
278 echo '<thead><tr><td><input type="checkbox" id="all-page" onclick="form_check(this, /check/);">';
e4089af Order rows by clicking on table heading
jakubvrana authored May 27, 2008
279 foreach ($row as $key => $val) {
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
280 echo '<th><a href="' . htmlspecialchars(remove_from_uri('(order|desc)[^=]*') . '&order%5B0%5D=' . urlencode($key) . ($_GET["order"] == array($key) && !$_GET["desc"][0] ? '&desc%5B0%5D=1' : '')) . '">' . adminer_field_name($fields, $key) . '</a>';
e4089af Order rows by clicking on table heading
jakubvrana authored May 27, 2008
281 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
282 echo "</thead>\n";
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
283 }
4c736a0 Use group by in export
jakubvrana authored Jun 22, 2009
284 $unique_idf = implode('&amp;', unique_idf($row, $indexes)); //! don't use aggregation functions
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
285 echo '<tr' . odd() . '><td><input type="checkbox" name="check[]" value="' . $unique_idf . '" onclick="this.form[\'all\'].checked = false; form_uncheck(\'all-page\');">' . (count($select) != count($group) || information_schema($_GET["db"]) ? '' : ' <a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&amp;' . $unique_idf . '">' . lang('edit') . '</a>');
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
286 foreach ($row as $key => $val) {
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
287 if (strlen($val) && (!isset($email_fields[$key]) || $email_fields[$key])) {
288 $email_fields[$key] = is_email($val); //! filled e-mails may be contained on other pages
289 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
290 if (!isset($val)) {
291 $val = "<i>NULL</i>";
5abd943 Change simple preg_match to ereg
jakubvrana authored Jul 13, 2009
292 } elseif (ereg('blob|binary', $fields[$key]["type"]) && !is_utf8($val)) { //! download link may be printed even with is_utf8
116faf2 Mass delete
jakubvrana authored Jan 8, 2008
293 $val = '<a href="' . htmlspecialchars($SELF) . 'download=' . urlencode($_GET["select"]) . '&amp;field=' . urlencode($key) . '&amp;' . $unique_idf . '">' . lang('%d byte(s)', strlen($val)) . '</a>';
02a851c Shorten texts in PHP
jakubvrana authored Aug 24, 2007
294 } else {
a69fff7 Print \n as <br />, not &nbsp;
jakubvrana authored Jun 21, 2009
295 if (!strlen(trim($val, " \t"))) {
4c75d84 Use &nbsp;
jakubvrana authored Jun 11, 2009
296 $val = "&nbsp;";
5abd943 Change simple preg_match to ereg
jakubvrana authored Jul 13, 2009
297 } elseif (intval($text_length) > 0 && ereg('blob|text', $fields[$key]["type"])) {
1ef58da Comments
jakubvrana authored Jul 12, 2009
298 $val = nl2br(shorten_utf8($val, intval($text_length))); // usage of LEFT() would reduce traffic but complicates query
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
299 } else {
300 $val = nl2br(htmlspecialchars($val));
301 if ($fields[$key]["type"] == "char") {
302 $val = "<code>$val</code>";
303 }
02a851c Shorten texts in PHP
jakubvrana authored Aug 24, 2007
304 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
305 foreach ((array) $foreign_keys[$key] as $foreign_key) {
306 if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
307 // link related items
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
308 $val = "\">$val</a>";
309 foreach ($foreign_key["source"] as $i => $source) {
310 $val = "&amp;where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&amp;where%5B$i%5D%5Bop%5D=%3D&amp;where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val;
311 }
312 $val = '<a href="' . htmlspecialchars(strlen($foreign_key["db"]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key["db"]), $SELF) : $SELF) . 'select=' . htmlspecialchars($foreign_key["table"]) . $val; // InnoDB supports non-UNIQUE keys
313 break;
ffcea8b Rights
jakubvrana authored Jul 6, 2007
314 }
fa3dd55 Parent
jakubvrana authored Jul 2, 2007
315 }
667bfec Decomposition
jakubvrana authored Jul 2, 2007
316 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
317 echo "<td>$val";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
318 }
5ab708a Compact pages
jakubvrana authored Jul 25, 2007
319 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
320 echo "</table>\n";
e4b188c Display found rows
jakubvrana authored Sep 1, 2008
321
322 echo "<p>";
64ba924 Comments
jakubvrana authored Jun 21, 2009
323 // use num_rows without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
5d311ef Comment
jakubvrana authored Jun 19, 2009
324 $found_rows = (intval($limit) ? $dbh->result($dbh->query(count($group) < count($select)
325 ? " SELECT FOUND_ROWS()" // space to allow mysql.trace_mode
326 : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")
327 )) : $result->num_rows);
e4b188c Display found rows
jakubvrana authored Sep 1, 2008
328 if (intval($limit) && $found_rows > $limit) {
64ba924 Comments
jakubvrana authored Jun 21, 2009
329 // display first, previous 3, next 3 and last page
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
330 $max_page = floor(($found_rows - 1) / $limit);
e4b188c Display found rows
jakubvrana authored Sep 1, 2008
331 echo lang('Page') . ":";
3bda945 Rename confusing print_page
jakubvrana authored Jun 21, 2009
332 print_pagination(0);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
333 if ($_GET["page"] > 3) {
334 echo " ...";
335 }
336 for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) {
3bda945 Rename confusing print_page
jakubvrana authored Jun 21, 2009
337 print_pagination($i);
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
338 }
339 if ($_GET["page"] + 3 < $max_page) {
340 echo " ...";
341 }
3bda945 Rename confusing print_page
jakubvrana authored Jun 21, 2009
342 print_pagination($max_page);
5ab708a Compact pages
jakubvrana authored Jul 25, 2007
343 }
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
344 echo " (" . lang('%d row(s)', $found_rows) . ') <label><input type="checkbox" name="all" value="1">' . lang('whole result') . "</label>\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored Sep 1, 2008
345
3c860b7 Name Edit button on select.inc.php
jakubvrana authored Jul 13, 2009
346 echo (information_schema($_GET["db"]) ? "" : "<fieldset><legend>" . lang('Edit') . "</legend><div><input type='submit' name='edit' value='" . lang('Edit') . "'> <input type='submit' name='clone' value='" . lang('Clone') . "'> <input type='submit' name='delete' value='" . lang('Delete') . "'$confirm></div></fieldset>\n");
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
347 echo "<fieldset><legend>" . lang('Export') . "</legend><div>$dump_output $dump_format <input type='submit' name='export' value='" . lang('Export') . "'></div></fieldset>\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
348 }
21ea4ae Check errors
jakubvrana authored Sep 3, 2007
349 $result->free();
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
350 echo "<fieldset><legend>" . lang('CSV Import') . "</legend><div><input type='hidden' name='token' value='$token'><input type='file' name='csv_file'> <input type='submit' name='import' value='" . lang('Import') . "'></div></fieldset>\n";
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
351
352 //! Editor only
353 $email_fields = array_filter($email_fields);
354 if ($email_fields) {
355 echo '<fieldset><legend><a href="#fieldset-email" onclick="return !toggle(\'fieldset-email\');">' . lang('E-mail') . "</a></legend><div id='fieldset-email' class='hidden'>\n";
ace55ed HTML instead of XHTML
jakubvrana authored Jul 11, 2009
356 echo "<p>" . lang('From') . ": <input name='email_from'>\n";
357 echo lang('Subject') . ": <input name='email_subject'>\n";
358 echo "<p><textarea name='email_message' rows='15' cols='60'></textarea>\n";
359 echo (count($email_fields) == 1 ? '<input type="hidden" name="email_field" value="' . htmlspecialchars(key($email_fields)) . '">' : '<select name="email_field">' . optionlist(array_keys($email_fields)) . '</select>');
360 echo "<input type='submit' name='email' value='" . lang('Send') . "'$confirm>\n";
c16c57b E-mail sending
jakubvrana authored Jul 11, 2009
361 echo "</div></fieldset>\n";
362 }
363
e7eb28d CSV import
jakubvrana authored Dec 30, 2008
364 echo "</form>\n";
667bfec Decomposition
jakubvrana authored Jul 2, 2007
365 }
366 }
Something went wrong with that request. Please try again.