$field) {
if (isset($field["privileges"]["select"])) {
$columns[] = $key;
}
$rights += $field["privileges"];
}
if (isset($rights["insert"])) {
//! pass search values forth and back
echo '
' . lang('New item') . "
\n";
}
if (!$columns) {
echo "" . lang('Unable to select the table') . ($fields ? "" : ": " . $mysql->error) . ".
\n";
} else {
$indexes = indexes($_GET["select"]);
echo "\n";
echo "
\n";
$result = $mysql->query("SELECT SQL_CALC_FOUND_ROWS " . implode(", ", $select) . " FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($limit) . " OFFSET " . ($limit * $_GET["page"]) : ""));
if (!$result->num_rows) {
echo "" . lang('No rows.') . "
\n";
} else {
$found_rows = $mysql->result($mysql->query(" SELECT FOUND_ROWS()")); // space for mysql.trace_mode
$foreign_keys = array();
foreach (foreign_keys($_GET["select"]) as $foreign_key) {
foreach ($foreign_key["source"] as $val) {
$foreign_keys[$val][] = $foreign_key;
}
}
echo "\n";
for ($j=0; $row = $result->fetch_assoc(); $j++) {
if (!$j) {
echo " | " . implode(" | ", array_map('htmlspecialchars', array_keys($row))) . " |
\n";
}
echo '' . lang('edit') . " | ";
$unique_idf = '&' . implode('&', unique_idf($row, $indexes));
//! multiple delete by checkboxes
foreach ($row as $key => $val) {
if (!isset($val)) {
$val = "NULL";
} elseif (preg_match('~blob|binary~', $fields[$key]["type"]) && preg_match('~[\\x80-\\xFF]~', $val)) {
$val = '' . lang('%d byte(s)', strlen($val)) . '';
} else {
$val = (strlen(trim($val)) ? nl2br(htmlspecialchars($val)) : " ");
if ($fields[$key]["type"] == "char") {
$val = "$val
";
}
foreach ((array) $foreign_keys[$key] as $foreign_key) {
if (count($foreign_keys[$key]) == 1 || count($foreign_key["source"]) == 1) {
$val = '">' . "$val";
foreach ($foreign_key["source"] as $i => $source) {
$val = "&where%5B$i%5D%5Bcol%5D=" . urlencode($foreign_key["target"][$i]) . "&where%5B$i%5D%5Bop%5D=%3D&where%5B$i%5D%5Bval%5D=" . urlencode($row[$source]) . $val;
}
$val = '$val";
}
echo "
\n";
}
echo "
\n";
if (intval($limit) && $found_rows > $limit) {
$max_page = floor($found_rows / $limit);
function print_page($page) {
echo " " . ($page == $_GET["page"] ? $page + 1 : '' . ($page + 1) . "");
}
echo "" . lang('Page') . ":";
print_page(0);
if ($_GET["page"] > 3) {
echo " ...";
}
for ($i = max(1, $_GET["page"] - 2); $i < min($max_page, $_GET["page"] + 3); $i++) {
print_page($i);
}
if ($_GET["page"] + 3 < $max_page) {
echo " ...";
}
print_page($max_page);
echo "
\n";
}
}
$result->free();
}