diff --git a/select.inc.php b/select.inc.php index 234be87b..e223843f 100644 --- a/select.inc.php +++ b/select.inc.php @@ -3,26 +3,24 @@ $indexes = indexes($_GET["select"]); page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"])); echo '

' . lang('New item') . "

\n"; -echo "
\n"; +echo "\n
" . lang('Search') . "\n"; if (strlen($_GET["server"])) { echo ''; } echo ''; echo ''; +echo "\n"; $where = array(); -$columns = array(); -foreach (fields($_GET["select"]) as $name => $field) { - $columns[] = $name; -} +$columns = array_keys(fields($_GET["select"])); $operators = array("=", "<", ">", "<=", ">=", "!=", "LIKE", "REGEXP", "IS NULL"); $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 ""; + echo "
"; echo ""; - echo "
\n"; + echo "
\n"; $i++; } } @@ -32,21 +30,44 @@ function where_change(op) { op.form[op.name.substr(0, op.name.length - 4) + '[val]'].style.display = (op.value == 'IS NULL' ? 'none' : ''); } - for (var i=0; > i; i++) document.getElementById('form')['where[' + i + '][op]'].onchange(); +for (var i=0; > i; i++) { + document.getElementById('form')['where[' + i + '][op]'].onchange(); +} " . optionlist($columns, array(), "not_vals") . ""; +echo "
"; echo ""; -echo "
\n"; //! JavaScript for adding next +echo "
\n"; //! JavaScript for adding next //! fulltext search +echo "
\n"; -//! sort, limit -$limit = 30; +echo "
" . lang('Order by') . "\n"; +$order = array(); +$i = 0; +foreach ((array) $_GET["order"] as $key => $val) { + if (in_array($val, $columns, true)) { + $desc = in_array($key, (array) $_GET["desc"]); + $order[] = idf_escape($val) . ($desc ? " DESC" : ""); + echo "
"; + echo "
\n"; + $i++; + } +} +echo "
"; +echo "
\n"; +echo "
\n"; -echo "\n"; -echo "
\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"])); +echo "
" . lang('Limit') . "\n"; +$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30"); +echo '
'; +echo "
\n"; + +echo "
" . lang('Action') . "
\n"; +echo "\n"; +echo "
\n"; + +$result = mysql_query("SELECT SQL_CALC_FOUND_ROWS * FROM " . idf_escape($_GET["select"]) . ($where ? " WHERE " . implode(" AND ", $where) : "") . ($order ? " ORDER BY " . implode(", ", $order) : "") . (strlen($limit) ? " LIMIT " . intval($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 "

" . lang('No rows.') . "

\n"; @@ -98,10 +119,10 @@ if (!mysql_num_rows($result)) { echo "\n"; } echo "\n"; - if ($found_rows > $limit) { + if (intval($limit) && $found_rows > $limit) { echo "

" . lang('Page') . ":\n"; for ($i=0; $i < $found_rows / $limit; $i++) { - echo ($i == $_GET["page"] ? $i + 1 : '' . ($i + 1) . "") . "\n"; + echo ($i == $_GET["page"] ? $i + 1 : '' . ($i + 1) . "") . "\n"; } echo "

\n"; }