]> git.joonet.de Git - adminer.git/commitdiff
Order, limit
authorjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 6 Jul 2007 09:03:47 +0000 (09:03 +0000)
committerjakubvrana <jakubvrana@7c3ca157-0c34-0410-bff1-cbf682f78f5c>
Fri, 6 Jul 2007 09:03:47 +0000 (09:03 +0000)
git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@55 7c3ca157-0c34-0410-bff1-cbf682f78f5c

select.inc.php

index 234be87b322711a5da2aa83164d89559211265c6..e223843fdb88b694c08118b40f408d686e67681c 100644 (file)
@@ -3,26 +3,24 @@ $indexes = indexes($_GET["select"]);
 page_header(lang('Select') . ": " . htmlspecialchars($_GET["select"]));
 
 echo '<p><a href="' . htmlspecialchars($SELF) . 'edit=' . urlencode($_GET['select']) . '">' . lang('New item') . "</a></p>\n";
-echo "<form action='' id='form'><div>\n";
+echo "<form action='' id='form'>\n<fieldset><legend>" . lang('Search') . "</legend>\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"]) . '" />';
+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 "<select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
+               echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, $val["col"], "not_vals") . "</select>";
                echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, $val["op"], "not_vals") . "</select>";
-               echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /><br />\n";
+               echo "<input name='where[$i][val]' value=\"" . htmlspecialchars($val["val"]) . "\" /></div>\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' : '');
 }
 <?php if ($i) { ?>
-       for (var i=0; <?php echo $i; ?> > i; i++) document.getElementById('form')['where[' + i + '][op]'].onchange();
+for (var i=0; <?php echo $i; ?> > i; i++) {
+       document.getElementById('form')['where[' + i + '][op]'].onchange();
+}
 <?php } ?>
 </script>
 <?php
-echo "<select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
+echo "<div><select name='where[$i][col]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
 echo "<select name='where[$i][op]' onchange=\"where_change(this);\">" . optionlist($operators, array(), "not_vals") . "</select>";
-echo "<input name='where[$i][val]' /><br />\n"; //! JavaScript for adding next
+echo "<input name='where[$i][val]' /></div>\n"; //! JavaScript for adding next
 //! fulltext search
+echo "</fieldset>\n";
+
+echo "<fieldset><legend>" . lang('Order by') . "</legend>\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 "<div><select name='order[$i]'><option></option>" . optionlist($columns, $val, "not_vals") . "</select>";
+               echo "<input type='checkbox' name='desc[]' value='$i' id='desc-$i'" . ($desc ? " checked='checked'" : "") . " /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
+               $i++;
+       }
+}
+echo "<div><select name='order[$i]'><option></option>" . optionlist($columns, array(), "not_vals") . "</select>";
+echo "<input type='checkbox' name='desc[$i]' value='1' id='desc-$i' /><label for='desc-$i'>" . lang('DESC') . "</label></div>\n";
+echo "</fieldset>\n";
+
+echo "<fieldset><legend>" . lang('Limit') . "</legend>\n";
+$limit = (isset($_GET["limit"]) ? $_GET["limit"] : "30");
+echo '<div><input name="limit" size="3" value="' . htmlspecialchars($limit) . '" /></div>';
+echo "</fieldset>\n";
 
-//! sort, limit
-$limit = 30;
+echo "<fieldset><legend>" . lang('Action') . "</legend><div><input type='submit' value='" . lang('Select') . "' /></div></fieldset>\n";
+echo "</form>\n";
+echo "<div style='clear: left; margin-bottom: 1em;'></div>\n";
 
-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"]));
+$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 "<p class='message'>" . lang('No rows.') . "</p>\n";
@@ -98,10 +119,10 @@ if (!mysql_num_rows($result)) {
                echo "</tr>\n";
        }
        echo "</table>\n";
-       if ($found_rows > $limit) {
+       if (intval($limit) && $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 ? "&amp;page=$i" : "") . '">' . ($i + 1) . "</a>") . "\n";
+                       echo ($i == $_GET["page"] ? $i + 1 : '<a href="' . htmlspecialchars(preg_replace('~(\\?)page=[^&]*&|&page=[^&]*~', '\\1', $_SERVER["REQUEST_URI"]) . ($i ? "&page=$i" : "")) . '">' . ($i + 1) . "</a>") . "\n";
                }
                echo "</p>\n";
        }