git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@5 7c3ca157-0c34-0410-bff1-cbf682f78f5c
100 lines
5 KiB
PHP
100 lines
5 KiB
PHP
<?php
|
|
page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
|
|
echo "<h2>" . lang('Select') . ": " . htmlspecialchars($_GET["select"]) . "</h2>\n";
|
|
|
|
echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
|
|
$indexes = indexes($_GET["select"]);
|
|
|
|
echo "<form action=''><div>\n";
|
|
if (strlen($_GET["server"])) {
|
|
echo '<input type="hidden" name="server" value="' . htmlspecialchars($_GET["server"]) . '" />';
|
|
}
|
|
echo '<input type="hidden" name="db" value="' . htmlspecialchars($_GET["db"]) . '" />';
|
|
echo '<input type="hidden" name="select" value="' . htmlspecialchars($_GET["select"]) . '" />';
|
|
|
|
$where = array();
|
|
$columns = array();
|
|
foreach (fields($_GET["select"]) as $name => $field) {
|
|
$columns[] = $name;
|
|
}
|
|
$operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL"); //! IS NULL - hide input by JavaScript
|
|
$i = 0;
|
|
foreach ((array) $_GET["where"] as $val) {
|
|
if ($val["col"] && in_array($val["op"], $operators)) {
|
|
$where[] = idf_escape($val["col"]) . " $val[op]" . ($val["op"] != "IS NULL" ? " '" . mysql_real_escape_string($val["val"]) . "'" : "");
|
|
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
|
|
echo "<select name='where[$i][op]'>" . optionlist($operators, $val["op"], "not_vals") . "</select>";
|
|
echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /><br />\n";
|
|
$i++;
|
|
}
|
|
}
|
|
echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
|
|
echo "<select name='where[$i][op]'>" . optionlist($operators, array(), "not_vals") . "</select>";
|
|
echo "<input name='where[$i][val]' /><br />\n"; //! JavaScript for adding next
|
|
//! fulltext search
|
|
|
|
//! sort, limit
|
|
$limit = 30;
|
|
|
|
echo "<input type='submit' value='" . lang('Search') . "' />\n";
|
|
echo "</div></form>\n";
|
|
$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . " LIMIT $limit OFFSET " . ($limit * $_GET["page"]));
|
|
$found_rows = mysql_result(mysql_query(" SELECT FOUND_ROWS()"), 0); // space for mysql.trace_mode
|
|
if (!mysql_num_rows($result)) {
|
|
echo "<p class='message'>" . lang('No rows.') . "</p>\n";
|
|
} else {
|
|
$foreign_keys = foreign_keys($_GET["select"]);
|
|
$childs = array();
|
|
$result1 = mysql_query("SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = '" . mysql_real_escape_string($_GET["db"]) . "' AND REFERENCED_TABLE_NAME = '" . mysql_real_escape_string($_GET["select"]) . "' ORDER BY ORDINAL_POSITION");
|
|
while ($row1 = mysql_fetch_assoc($result1)) {
|
|
$childs[$row1["CONSTRAINT_NAME"]][0] = $row1["TABLE_SCHEMA"];
|
|
$childs[$row1["CONSTRAINT_NAME"]][1] = $row1["TABLE_NAME"];
|
|
$childs[$row1["CONSTRAINT_NAME"]][2][] = $row1["REFERENCED_COLUMN_NAME"];
|
|
$childs[$row1["CONSTRAINT_NAME"]][3][] = $row1["COLUMN_NAME"];
|
|
}
|
|
mysql_free_result($result1);
|
|
|
|
echo "<table border='1' cellspacing='0' cellpadding='2'>\n";
|
|
for ($j=0; $row = mysql_fetch_assoc($result); $j++) {
|
|
if (!$j) {
|
|
echo "<thead><tr><th>" . implode("</th><th>", array_map('htmlspecialchars', array_keys($row))) . "</th><th>" . lang('Action') . "</th></tr></thead>\n";
|
|
}
|
|
echo "<tr>";
|
|
foreach ($row as $key => $val) {
|
|
if (!isset($val)) {
|
|
$val = "<i>NULL</i>";
|
|
} else {
|
|
$val = htmlspecialchars($val);
|
|
if (count($foreign_keys[$key]) == 1) {
|
|
$foreign_key = $foreign_keys[$key][0];
|
|
$val = '">' . "$val</a>";
|
|
foreach ($foreign_key[2] as $i => $source) {
|
|
$val = "&where[$i][col]=" . urlencode($foreign_key[3][$i]) . "&where[$i][op]=%3D&where[$i][val]=" . urlencode($row[$source]) . $val;
|
|
}
|
|
$val = '<a href="' . htmlspecialchars(strlen($foreign_key[0]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($foreign_key[0]), $SELF) : $SELF) . 'select=' . htmlspecialchars($foreign_key[1]) . $val; // InnoDB support non-UNIQUE keys //! reference to other database
|
|
}
|
|
}
|
|
echo "<td>$val</td>";
|
|
}
|
|
echo '<td><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '&' . implode('&', unique_idf($row, $indexes)) . '">edit</a>'; //! views can be unupdatable
|
|
foreach ($childs as $child) {
|
|
echo ' <a href="' . htmlspecialchars(strlen($child[0]) ? preg_replace('~([?&]db=)[^&]+~', '\\1' . urlencode($child[0]), $SELF) : $SELF) . 'select=' . urlencode($child[1]);
|
|
foreach ($child[2] as $i => $source) {
|
|
echo "&where[$i][col]=" . urlencode($child[3][$i]) . "&where[$i][op]=%3D&where[$i][val]=" . urlencode($row[$source]);
|
|
}
|
|
echo '">' . htmlspecialchars($child[1]) . '</a>';
|
|
}
|
|
echo "</td>";
|
|
echo "</tr>\n";
|
|
}
|
|
echo "</table>\n";
|
|
if ($found_rows > $limit) {
|
|
echo "<p>" . lang('Page') . ":\n";
|
|
for ($i=0; $i < $found_rows / $limit; $i++) {
|
|
echo ($i == $_GET["page"] ? $i + 1 : '<a href="' . htmlspecialchars($SELF) . 'select=' . urlencode($_GET['select']) . ($i ? "&page=$i" : "") . '">' . ($i + 1) . "</a>") . "\n";
|
|
}
|
|
echo "</p>\n";
|
|
}
|
|
}
|
|
mysql_free_result($result);
|