Fixed typos in some installer translation files.
[fa-stable.git] / includes / db_pager.inc
index f3f0050db32da69dffc2296200f52a039b428ee6..522b04b6873eb1aa9da1ca2258fa8c053c6d8574 100644 (file)
@@ -143,7 +143,16 @@ class db_pager {
        //
        function sort_table($col) 
        {
+
+                       $max_priority = 0;
+                       foreach($this->columns as $id => $_col) {
+                       if(!isset($_col['ord_priority'])) continue;
+                               $max_priority = max($max_priority, $_col['ord_priority']);
+                       };
+
+
            $ord = $this->columns[$col]['ord'];
+               $this->columns[$col]['ord_priority']  = $max_priority+1; // set priority , higher than anything else
            $ord = ($ord == '') ? 'asc' : (($ord == 'asc') ? 'desc' : '');
            $this->columns[$col]['ord'] = $ord;
            $this->set_page(1);
@@ -278,24 +287,30 @@ class db_pager {
                }
                if ($where) $where = " WHERE ($where)";
 
-               if ($count) {
-                       $group = $group == '' ? "*" : "DISTINCT $group";
-
-                       return "SELECT COUNT($group) FROM $from $where";
-               }
+               if ($count)
+                       return "SELECT COUNT(*) FROM ($this->sql) tmp_count";
 
                $sql = "$select FROM $from $where";
                if ($group) $sql.= " GROUP BY $group";
            $ord = array();
 
+                       // sort order column by priority instead of table order.
+                       $columns = array();
            foreach ($this->columns as $col) {
+                                       if(isset($col['ord_priority'])) {
+                                               $columns[$col['ord_priority']] = $col;
+                                       }
+               }
+               krsort($columns);
+
+           foreach ($columns as $col) {
                if (isset($col['ord'])) {
                        if ( $col['ord'] != '' && isset($col['name'])) {
                            $ord[] = $col['name'] .' '. $col['ord'];
                            }
                        }
            }
-                               
+
            if (count($ord)) {
                        $ord = array_map(function_exists('mysql_real_escape_string') ? 
                                'mysql_real_escape_string': 'mysql_escape_string', $ord);
@@ -486,4 +501,4 @@ function refresh_pager($name)
        if (isset($_SESSION[$name]))
                $_SESSION[$name]->ready = false;
 }
-?>
\ No newline at end of file
+?>