--- rcube_contacts.php.orig	2010-04-26 15:37:02.742122684 -0700
+++ rcube_contacts.php	2010-04-26 13:05:23.176085182 -0700
@@ -55,6 +55,7 @@
      */
     function __construct($dbconn, $user)
     {
+
         $this->db = $dbconn;
         $this->db_name = get_table_name('contacts');
         $this->user_id = $user;
@@ -166,7 +167,7 @@
             $join = " LEFT JOIN ".get_table_name('contactgroupmembers')." AS m".
                 " ON (m.contact_id = c.".$this->primary_key.")";
 
-        $sql_result = $this->db->limitquery(
+        /* $sql_result = $this->db->limitquery(
             "SELECT * FROM ".$this->db_name." AS c" .
             $join .
             " WHERE c.del<>1" .
@@ -177,7 +178,18 @@
             $start_row,
             $length,
             $this->user_id,
-            $this->group_id);
+            $this->group_id); */
+
+        $sql_result = $this->db->limitquery(
+            "SELECT * FROM ".$this->db_name." AS c" .
+            $join .
+            " WHERE c.del<>1" .
+                " AND c.user_id=?" .
+                ($this->filter ? " AND (".$this->filter.")" : "") .
+            " ORDER BY c.name",
+            $start_row,
+            $length,
+            $this->user_id);
 
         while ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) {
             $sql_arr['ID'] = $sql_arr[$this->primary_key];
@@ -270,7 +282,7 @@
                 " ON (m.contact_id=c.".$this->primary_key.")";
       
         // count contacts for this user
-        $sql_result = $this->db->query(
+        /* $sql_result = $this->db->query(
             "SELECT COUNT(c.contact_id) AS rows".
             " FROM ".$this->db_name." AS c".
                 $join.
@@ -280,6 +292,15 @@
             ($this->filter ? " AND (".$this->filter.")" : ""),
             $this->user_id,
             $this->group_id
+        ); */
+        $sql_result = $this->db->query(
+            "SELECT COUNT(c.contact_id) AS rows".
+            " FROM ".$this->db_name." AS c".
+                $join.
+            " WHERE c.del<>1".
+            " AND c.user_id=?".
+            ($this->filter ? " AND (".$this->filter.")" : ""),
+            $this->user_id
         );
 
         $sql_arr = $this->db->fetch_assoc($sql_result);

