Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 325 lines (310 sloc) 17.184 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"])) {
ffcea8b Rights
jakubvrana authored
16 $columns[] = $key;
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) {
27 if ($val["fun"] == "count" || (in_array($val["col"], $columns, true) && (!$val["fun"] || in_array($val["fun"], $functions) || in_array($val["fun"], $grouping)))) {
28 $select[$key] = (in_array($val["col"], $columns, true) ? (!$val["fun"] ? idf_escape($val["col"]) : ($val["fun"] == "distinct" ? "COUNT(DISTINCT " : strtoupper("$val[fun](")) . idf_escape($val["col"]) . ")") : "COUNT(*)");
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"]);
36a3656 Change escape_string to quote
jakubvrana authored
46 $cond = " $val[op]" . (ereg('NULL$', $val["op"]) ? "" : (ereg('IN$', $val["op"]) ? " (" . (strlen($in) ? $in : "NULL") . ")" : " " . $dbh->quote($val["val"]))); //! this searches in numeric values too
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) {
5805eba Remove order of not used functions
jakubvrana authored
64 if (in_array($val, $columns, true) || 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
4c736a0 Use group by in export
jakubvrana authored
80 $union[] = "(SELECT $from " . ($where ? "AND " : "WHERE ") . implode(" AND ", 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 }
d83b654 Detect import errors
jakubvrana authored
88 if (!$_POST["import"]) { // edit
e7eb28d CSV import
jakubvrana authored
89 $result = true;
90 $affected = 0;
91 $command = ($_POST["delete"] ? ($_POST["all"] && !$where ? "TRUNCATE " : "DELETE FROM ") : ($_POST["clone"] ? "INSERT INTO " : "UPDATE ")) . idf_escape($_GET["select"]);
92 if (!$_POST["delete"]) {
93 $set = array();
94 foreach ($fields as $name => $field) {
95 $val = process_input($name, $field);
96 if ($_POST["clone"]) {
97 $set[] = ($val !== false ? $val : idf_escape($name));
98 } elseif ($val !== false) {
0cd2afb Remove single item clone
jakubvrana authored
99 $set[] = "\n" . idf_escape($name) . " = $val";
e7eb28d CSV import
jakubvrana authored
100 }
101 }
0cd2afb Remove single item clone
jakubvrana authored
102 $command .= ($_POST["clone"] ? "\nSELECT " . implode(", ", $set) . " FROM " . idf_escape($_GET["select"]) : " SET" . implode(",", $set));
e7eb28d CSV import
jakubvrana authored
103 }
38059b6 Remove empty if
jakubvrana authored
104 if ($_POST["delete"] || $set) {
105 if ($_POST["all"]) {
106 $result = queries($command . ($where ? "\nWHERE " . implode(" AND ", $where) : ""));
107 $affected = $dbh->affected_rows;
108 } else {
109 foreach ((array) $_POST["check"] as $val) {
110 parse_str($val, $check);
111 // where may not be unique so OR can't be used
112 $result = queries($command . "\nWHERE " . implode(" AND ", where($check)) . " LIMIT 1");
113 if (!$result) {
114 break;
115 }
116 $affected += $dbh->affected_rows;
e7eb28d CSV import
jakubvrana authored
117 }
78639a9 Function results in edit
jakubvrana authored
118 }
119 }
e7eb28d CSV import
jakubvrana authored
120 query_redirect(queries(), remove_from_uri("page"), lang('%d item(s) have been affected.', $affected), $result, false, !$result);
121 //! display edit page in case of an error
d83b654 Detect import errors
jakubvrana authored
122 } elseif (is_string($file = get_file("csv_file"))) {
123 $file = preg_replace("~^\xEF\xBB\xBF~", '', $file); //! character set
124 $cols = "";
125 $rows = array(); //! packet size
126 preg_match_all('~("[^"]*"|[^"\\n]+)+~', $file, $matches);
127 foreach ($matches[0] as $key => $val) {
128 $row = array();
129 preg_match_all('~(("[^"]*")+|[^,]*),~', "$val,", $matches2);
130 if (!$key && !array_diff($matches2[1], array_keys($fields))) { //! doesn't work with column names containing ",\n
64ba924 Comments
jakubvrana authored
131 // first row corresponds to column names - use it for table structure
d83b654 Detect import errors
jakubvrana authored
132 $cols = " (" . implode(", ", array_map('idf_escape', $matches2[1])) . ")";
133 } else {
134 foreach ($matches2[1] as $col) {
36a3656 Change escape_string to quote
jakubvrana authored
135 $row[] = (!strlen($col) ? "NULL" : $dbh->quote(str_replace('""', '"', preg_replace('~^".*"$~s', '', $col))));
d83b654 Detect import errors
jakubvrana authored
136 }
64ba924 Comments
jakubvrana authored
137 $rows[] = "\n(" . implode(", ", $row) . ")";
d83b654 Detect import errors
jakubvrana authored
138 }
139 }
64ba924 Comments
jakubvrana authored
140 $result = queries("INSERT INTO " . idf_escape($_GET["select"]) . "$cols VALUES" . implode(",", $rows));
5f16c75 Prepare for version 2
jakubvrana authored
141 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
142 } else {
143 $error = lang('Unable to upload a file.');
ec23248 Exportable select
jakubvrana authored
144 }
116faf2 Mass delete
jakubvrana authored
145 }
820c882 Bulk clone
jakubvrana authored
146 page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]), $error);
116faf2 Mass delete
jakubvrana authored
147
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
148 echo "<p>";
430034c Cottage homework
jakubvrana authored
149 if (isset($rights["insert"])) {
3d254a3 TODO
jakubvrana authored
150 //! pass search values forth and back
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
151 echo '<a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . '</a> ';
667bfec Decomposition
jakubvrana authored
152 }
d886b00 Link to view
jakubvrana authored
153 echo '<a href="' . htmlspecialchars($SELF) . (isset($table_status["Engine"]) ? 'table=' : 'view=') . urlencode($_GET['select']) . '">' . lang('Table structure') . '</a>';
4099271 Cross links to select and table (bug #2236232)
jakubvrana authored
154 echo "</p>\n";
667bfec Decomposition
jakubvrana authored
155
ffcea8b Rights
jakubvrana authored
156 if (!$columns) {
5f16c75 Prepare for version 2
jakubvrana authored
157 echo "<p class='error'>" . lang('Unable to select the table') . ($fields ? "" : ": " . htmlspecialchars($dbh->error)) . ".</p>\n";
ffcea8b Rights
jakubvrana authored
158 } else {
5ee29cb Select columns, aggregation
jakubvrana authored
159 echo "<form action='' id='form'>\n";
b142000 Hide fieldsets in select
jakubvrana authored
160 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
161 if (strlen($_GET["server"])) {
162 echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
667bfec Decomposition
jakubvrana authored
163 }
ffcea8b Rights
jakubvrana authored
164 echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
165 echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
166 echo "\n";
5ee29cb Select columns, aggregation
jakubvrana authored
167 $i = 0;
168 $fun_group = array(lang('Functions') => $functions, lang('Aggregation') => $grouping);
169 foreach ($select as $key => $val) {
170 $val = $_GET["columns"][$key];
171 echo "<div><select name='columns[$i][fun]'><option></option>" . optionlist($fun_group, $val["fun"]) . "</select>";
172 echo "<select name='columns[$i][col]'><option></option>" . optionlist($columns, $val["col"]) . "</select></div>\n";
173 $i++;
174 }
175 echo "<div><select name='columns[$i][fun]' onchange='this.nextSibling.onchange();'><option></option>" . optionlist($fun_group) . "</select>";
540e217 Separate JavaScript
jakubvrana authored
176 echo "<select name='columns[$i][col]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
177 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
178
b142000 Hide fieldsets in select
jakubvrana authored
179 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
180 foreach ($indexes as $i => $index) {
181 if ($index["type"] == "FULLTEXT") {
9e2848d Escape fulltext columns
jakubvrana authored
182 echo "(<i>" . implode("</i>, <i>", array_map('htmlspecialchars', $index["columns"])) . "</i>) AGAINST";
430034c Cottage homework
jakubvrana authored
183 echo ' <input name="fulltext[' . $i . ']" value="' . htmlspecialchars($_GET["fulltext"][$i]) . '" />';
78639a9 Function results in edit
jakubvrana authored
184 echo "<label><input type='checkbox' name='boolean[$i]' value='1'" . (isset($_GET["boolean"][$i]) ? " checked='checked'" : "") . " />" . lang('BOOL') . "</label>";
430034c Cottage homework
jakubvrana authored
185 echo "<br />\n";
186 }
187 }
ffcea8b Rights
jakubvrana authored
188 $i = 0;
189 foreach ((array) $_GET["where"] as $val) {
25bc058 Search in any column
jakubvrana authored
190 if (strlen("$val[col]$val[val]") && in_array($val["op"], $operators)) {
a96dfd0 Promote search anywhere
jakubvrana authored
191 echo "<div><select name='where[$i][col]'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns, $val["col"]) . "</select>";
71430ee IE fixes
jakubvrana authored
192 echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators, $val["op"]) . "</select>";
540e217 Separate JavaScript
jakubvrana authored
193 echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . '"' . (ereg('NULL$', $val["op"]) ? " class='hidden'" : "") . " /></div>\n";
ffcea8b Rights
jakubvrana authored
194 $i++;
195 }
196 }
540e217 Separate JavaScript
jakubvrana authored
197 echo "<div><select name='where[$i][col]' onchange='select_add_row(this);'><option value=''>" . lang('(anywhere)') . "</option>" . optionlist($columns) . "</select>";
71430ee IE fixes
jakubvrana authored
198 echo "<select name='where[$i][op]' onchange='where_change(this);'>" . optionlist($operators) . "</select>";
4f6f2d4 JavaScript for adding where and order
jakubvrana authored
199 echo "<input name='where[$i][val]' /></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
200 echo "</div></fieldset>\n";
201
202 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";
203 $i = 0;
204 foreach ((array) $_GET["order"] as $key => $val) {
205 if (in_array($val, $columns, true)) {
206 echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, $val) . "</select>";
b0ee71e Update translations
jakubvrana authored
207 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
208 $i++;
209 }
210 }
211 echo "<div><select name='order[$i]' onchange='select_add_row(this);'><option></option>" . optionlist($columns) . "</select>";
b0ee71e Update translations
jakubvrana authored
212 echo "<label><input type='checkbox' name='desc[$i]' value='1' />" . lang('descending') . "</label></div>\n";
b142000 Hide fieldsets in select
jakubvrana authored
213 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
214
64ba924 Comments
jakubvrana authored
215 echo "<fieldset><legend>" . lang('Limit') . "</legend><div>"; // <div> for easy styling
b142000 Hide fieldsets in select
jakubvrana authored
216 echo "<input name='limit' size='3' value=\"" . htmlspecialchars($limit) . "\" />";
217 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
218
63441b1 Max text length
jakubvrana authored
219 if (isset($text_length)) {
b142000 Hide fieldsets in select
jakubvrana authored
220 echo "<fieldset><legend>" . lang('Text length') . "</legend><div>";
221 echo "<input name='text_length' size='3' value=\"" . htmlspecialchars($text_length) . "\" />";
222 echo "</div></fieldset>\n";
63441b1 Max text length
jakubvrana authored
223 }
224
b142000 Hide fieldsets in select
jakubvrana authored
225 echo "<fieldset><legend>" . lang('Action') . "</legend><div>";
226 echo "<input type='submit' value='" . lang('Select') . "' />";
227 echo "</div></fieldset>\n";
ffcea8b Rights
jakubvrana authored
228 echo "</form>\n";
229
4c736a0 Use group by in export
jakubvrana authored
230 $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"]) : "") : "");
06faef2 Print SQL query by messages
jakubvrana authored
231 echo "<p><code class='jush-sql'>" . htmlspecialchars($query) . "</code> <a href='" . htmlspecialchars($SELF) . "sql=" . urlencode($query) . "'>" . lang('Edit') . "</a></p>\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
232
5f16c75 Prepare for version 2
jakubvrana authored
233 $result = $dbh->query($query);
21ea4ae Check errors
jakubvrana authored
234 if (!$result) {
5f16c75 Prepare for version 2
jakubvrana authored
235 echo "<p class='error'>" . htmlspecialchars($dbh->error) . "</p>\n";
ffcea8b Rights
jakubvrana authored
236 } else {
e7eb28d CSV import
jakubvrana authored
237 echo "<form action='' method='post' enctype='multipart/form-data'>\n";
21ea4ae Check errors
jakubvrana authored
238 if (!$result->num_rows) {
239 echo "<p class='message'>" . lang('No rows.') . "</p>\n";
240 } else {
241 $foreign_keys = array();
242 foreach (foreign_keys($_GET["select"]) as $foreign_key) {
243 foreach ($foreign_key["source"] as $val) {
244 $foreign_keys[$val][] = $foreign_key;
245 }
ffcea8b Rights
jakubvrana authored
246 }
21ea4ae Check errors
jakubvrana authored
247
d30face Remove useless table attributes (thanks to Juraj Krivda)
jakubvrana authored
248 echo "<table cellspacing='0' class='nowrap'>\n";
21ea4ae Check errors
jakubvrana authored
249 for ($j=0; $row = $result->fetch_assoc(); $j++) {
250 if (!$j) {
d5a4d14 Separate page and whole result check
jakubvrana authored
251 echo '<thead><tr><td><input type="checkbox" id="all-page" onclick="form_check(this, /check/);" /></td>';
e4089af Order rows by clicking on table heading
jakubvrana authored
252 foreach ($row as $key => $val) {
b142000 Hide fieldsets in select
jakubvrana authored
253 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' : '')) . '">' . htmlspecialchars($key) . '</a></th>';
e4089af Order rows by clicking on table heading
jakubvrana authored
254 }
255 echo "</tr></thead>\n";
21ea4ae Check errors
jakubvrana authored
256 }
4c736a0 Use group by in export
jakubvrana authored
257 $unique_idf = implode('&amp;', unique_idf($row, $indexes)); //! don't use aggregation functions
607e104 Create information_schema function
jakubvrana authored
258 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>') . '</td>';
21ea4ae Check errors
jakubvrana authored
259 foreach ($row as $key => $val) {
260 if (!isset($val)) {
261 $val = "<i>NULL</i>";
017ffb5 Better UTF-8 detection
jakubvrana authored
262 } elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && !is_utf8($val)) {
116faf2 Mass delete
jakubvrana authored
263 $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
264 } else {
a69fff7 Print \n as <br />, not &nbsp;
jakubvrana authored
265 if (!strlen(trim($val, " \t"))) {
4c75d84 Use &nbsp;
jakubvrana authored
266 $val = "&nbsp;";
267 } elseif (intval($text_length) > 0 && preg_match('~blob|text~', $fields[$key]["type"])) {
33e8015 Shorten displayed SQL query
jakubvrana authored
268 $val = nl2br(shorten_utf8($val, intval($text_length)));
21ea4ae Check errors
jakubvrana authored
269 } else {
270 $val = nl2br(htmlspecialchars($val));
271 if ($fields[$key]["type"] == "char") {
272 $val = "<code>$val</code>";
273 }
02a851c Shorten texts in PHP
jakubvrana authored
274 }
21ea4ae Check errors
jakubvrana authored
275 foreach ((array) $foreign_keys[$key] as $foreign_key) {
276 if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
64ba924 Comments
jakubvrana authored
277 // link related items
21ea4ae Check errors
jakubvrana authored
278 $val = "\">$val</a>";
279 foreach ($foreign_key["source"] as $i => $source) {
280 $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;
281 }
282 $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
283 break;
ffcea8b Rights
jakubvrana authored
284 }
fa3dd55 Parent
jakubvrana authored
285 }
667bfec Decomposition
jakubvrana authored
286 }
21ea4ae Check errors
jakubvrana authored
287 echo "<td>$val</td>";
667bfec Decomposition
jakubvrana authored
288 }
21ea4ae Check errors
jakubvrana authored
289 echo "</tr>\n";
5ab708a Compact pages
jakubvrana authored
290 }
21ea4ae Check errors
jakubvrana authored
291 echo "</table>\n";
e4b188c Display found rows
jakubvrana authored
292
293 echo "<p>";
64ba924 Comments
jakubvrana authored
294 // use num_rows without LIMIT, COUNT(*) without grouping, FOUND_ROWS otherwise (slowest)
5d311ef Comment
jakubvrana authored
295 $found_rows = (intval($limit) ? $dbh->result($dbh->query(count($group) < count($select)
296 ? " SELECT FOUND_ROWS()" // space to allow mysql.trace_mode
297 : "SELECT COUNT(*) FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "")
298 )) : $result->num_rows);
e4b188c Display found rows
jakubvrana authored
299 if (intval($limit) && $found_rows > $limit) {
64ba924 Comments
jakubvrana authored
300 // display first, previous 3, next 3 and last page
21ea4ae Check errors
jakubvrana authored
301 $max_page = floor(($found_rows - 1) / $limit);
e4b188c Display found rows
jakubvrana authored
302 echo lang('Page') . ":";
3bda945 Rename confusing print_page
jakubvrana authored
303 print_pagination(0);
21ea4ae Check errors
jakubvrana authored
304 if ($_GET["page"] > 3) {
305 echo " ...";
306 }
307 for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) {
3bda945 Rename confusing print_page
jakubvrana authored
308 print_pagination($i);
21ea4ae Check errors
jakubvrana authored
309 }
310 if ($_GET["page"] + 3 < $max_page) {
311 echo " ...";
312 }
3bda945 Rename confusing print_page
jakubvrana authored
313 print_pagination($max_page);
5ab708a Compact pages
jakubvrana authored
314 }
d5a4d14 Separate page and whole result check
jakubvrana authored
315 echo " (" . lang('%d row(s)', $found_rows) . ') <label><input type="checkbox" name="all" value="1" />' . lang('whole result') . "</label></p>\n";
8b74511 Print SQL query (fixes #2082448)
jakubvrana authored
316
607e104 Create information_schema function
jakubvrana authored
317 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");
fb8a36b Compact export options
jakubvrana authored
318 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
319 }
21ea4ae Check errors
jakubvrana authored
320 $result->free();
e7eb28d CSV import
jakubvrana authored
321 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";
322 echo "</form>\n";
667bfec Decomposition
jakubvrana authored
323 }
324 }
Something went wrong with that request. Please try again.