diff --git a/lib.inc.php3 b/lib.inc.php3 index 3784d60d1..ad2078013 100755 --- a/lib.inc.php3 +++ b/lib.inc.php3 @@ -525,9 +525,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=' . "\n"; } echo ' ' . $query_base; - if (isset($GLOBALS['sql_order'])) { - echo ' ' . $GLOBALS['sql_order']; - } // If a 'LIMIT' clause has been programatically added to the query // displays it $is_append_limit = (isset($GLOBALS['pos']) @@ -622,7 +619,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang= @@ -659,7 +653,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=" /> - @@ -673,7 +666,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=" /> - @@ -695,7 +687,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=" /> - @@ -717,7 +708,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=" /> - @@ -732,7 +722,6 @@ window.parent.frames['nav'].location.replace('./left.php3?lang=" /> - @@ -764,14 +753,13 @@ window.parent.frames['nav'].location.replace('./left.php3?lang= 1 && !$is_simple) { + // Defines the url used to append/modify a sorting order + // 1. Checks if an hard coded 'order by' clause exists + if (eregi('(.*)( ORDER BY (.*))', $sql_query, $regs1)) { + if (eregi('((.*)( ASC| DESC)( |$))(.*)', $regs1[2], $regs2)) { + $unsorted_sql_query = trim($regs1[1] . ' ' . $regs2[5]); + $sql_order = trim($regs2[1]); + } + else if (eregi('((.*)) (LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE)', $regs1[2], $regs3)) { + $unsorted_sql_query = trim($regs1[1] . ' ' . $regs3[3]); + $sql_order = trim($regs3[1]) . ' ASC'; + } else { + $unsorted_sql_query = trim($regs1[1]); + $sql_order = trim($regs1[2]) . ' ASC'; + } + } else { + $unsorted_sql_query = $sql_query; + } + // 2. Checks if the current column is used to sort the result if (empty($sql_order)) { + $is_in_sort = FALSE; + } else { + $is_in_sort = eregi(' (`?)' . str_replace('\\', '\\\\', $field->name) . '(`?)[ ,$]', $sql_order); + } + // 3. Do define the sorting url + if (!$is_in_sort) { $sort_order = ' ORDER BY ' . backquote($field->name) . ' ' . $GLOBALS['cfgOrder']; } - else if (substr($sql_order, -3) == 'ASC') { + else if (substr($sql_order, -3) == 'ASC' && $is_in_sort) { $sort_order = ' ORDER BY ' . backquote($field->name) . ' DESC'; } - else if (substr($sql_order, -4) == 'DESC') { + else if (substr($sql_order, -4) == 'DESC' && $is_in_sort) { $sort_order = ' ORDER BY ' . backquote($field->name) . ' ASC'; } + if (eregi('(.*)( LIMIT (.*)| PROCEDURE (.*)| FOR UPDATE| LOCK IN SHARE MODE)', $unsorted_sql_query, $regs3)) { + $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2]; + } else { + $sorted_sql_query = $unsorted_sql_query . $sort_order; + } $url_query = 'lang=' . $lang . '&server=' . urlencode($server) . '&db=' . urlencode($db) . '&table=' . urlencode($table) . '&pos=' . $pos - . '&sql_query=' . urlencode($sql_query) - . '&sql_order=' . urlencode($sort_order); + . '&sql_query=' . urlencode($sorted_sql_query); ?>