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