From 6af7e0d63dc42901b55ca9530959d9ddaffa56d6 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Sat, 18 Jun 2011 15:45:26 -0400
Subject: [PATCH] Use numSubOrdindates inconjuction with VLV to count total

---
 program/include/rcube_ldap.php |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/program/include/rcube_ldap.php b/program/include/rcube_ldap.php
index e377de7..4ea4f60 100644
--- a/program/include/rcube_ldap.php
+++ b/program/include/rcube_ldap.php
@@ -884,10 +884,18 @@
 
             $this->_debug("C: Search [".$filter."]");
 
-            // when using VLV, we need to issue listing command first in order to get the full count
+            // when using VLV, we get the total count by...
             if (!$count && $function != 'ldap_read' && $this->prop['vlv']) {
-                if ($this->_exec_search(true))
-                    $this->vlv_count = ldap_count_entries($this->conn, $this->ldap_result);
+                // ...either reading numSubOrdinates attribute
+                if ($this->prop['numsub_filter'] && ($result_count = @$function($this->conn, $this->base_dn, $this->prop['numsub_filter'], array('numSubOrdinates'), 0, 0, 0))) {
+                    $counts = ldap_get_entries($this->conn, $result_count);
+                    for ($this->vlv_count = $j = 0; $j < $counts['count']; $j++)
+                        $this->vlv_count += $counts[$j]['numsubordinates'][0];
+                    $this->_debug("D: total numsubordinates = " . $this->vlv_count);
+                }
+                else  // ...or by fetching all records dn and count them
+                    $this->vlv_count = $this->_exec_search(true);
+                
                 $this->vlv_active = $this->_vlv_set_controls();
             }
 

--
Gitblit v1.9.1