Changeset fb6cc89 in github
- Timestamp:
- Oct 14, 2011 12:50:33 PM (19 months ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.7, release-0.8
- Children:
- 54b0d86
- Parents:
- 58487bb
- File:
-
- 1 edited
-
program/include/rcube_ldap.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/include/rcube_ldap.php
rce53b67 rfb6cc89 87 87 if (empty($this->prop['groups']['name_attr'])) 88 88 $this->prop['groups']['name_attr'] = 'cn'; 89 if (empty($this->prop['groups']['scope'])) 90 $this->prop['groups']['scope'] = 'sub'; 89 91 } 90 92 … … 548 550 } 549 551 } 552 553 if ($this->prop['sizelimit'] && count($group_members) > $this->prop['sizelimit']) 554 break; 550 555 } 551 556 … … 1112 1117 { 1113 1118 $filter = $this->filter ? $this->filter : '(objectclass=*)'; 1114 1115 switch ($this->prop['scope']) { 1116 case 'sub': 1117 $function = $ns_function = 'ldap_search'; 1118 break; 1119 case 'base': 1120 $function = $ns_function = 'ldap_read'; 1121 break; 1122 default: 1123 $function = 'ldap_list'; 1124 $ns_function = 'ldap_read'; 1125 break; 1126 } 1127 1128 $this->_debug("C: Search [$filter]"); 1119 $function = $this->_scope2func($this->prop['scope'], $ns_function); 1120 1121 $this->_debug("C: Search [$filter][dn: $this->base_dn]"); 1129 1122 1130 1123 // when using VLV, we get the total count by... … … 1140 1133 $this->vlv_count = $this->_exec_search(true); 1141 1134 1142 $this->vlv_active = $this->_vlv_set_controls( );1135 $this->vlv_active = $this->_vlv_set_controls($this->prop, $this->list_page, $this->page_size); 1143 1136 } 1144 1137 … … 1151 1144 if ($err = ldap_errno($this->conn)) 1152 1145 $this->_debug("S: Error: " .ldap_err2str($err)); 1153 return true;1146 return $count ? ldap_count_entries($this->conn, $this->ldap_result) : true; 1154 1147 } 1155 1148 else … … 1163 1156 1164 1157 /** 1158 * Choose the right PHP function according to scope property 1159 */ 1160 private function _scope2func($scope, &$ns_function = null) 1161 { 1162 switch ($scope) { 1163 case 'sub': 1164 $function = $ns_function = 'ldap_search'; 1165 break; 1166 case 'base': 1167 $function = $ns_function = 'ldap_read'; 1168 break; 1169 default: 1170 $function = 'ldap_list'; 1171 $ns_function = 'ldap_read'; 1172 break; 1173 } 1174 1175 return $function; 1176 } 1177 1178 /** 1165 1179 * Set server controls for Virtual List View (paginated listing) 1166 1180 */ 1167 private function _vlv_set_controls() 1168 { 1169 $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473", 'value' => $this->_sort_ber_encode((array)$this->prop['sort'])); 1170 $vlv_ctrl = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => $this->_vlv_ber_encode(($offset = ($this->list_page-1) * $this->page_size + 1), $this->page_size), 'iscritical' => true); 1171 1172 $this->_debug("C: set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ({$this->sort_col});" 1173 . " vlv=" . join(' ', (unpack('H'.(strlen($vlv_ctrl['value'])*2), $vlv_ctrl['value']))) . " ($offset/$this->page_size)"); 1181 private function _vlv_set_controls($prop, $list_page, $page_size) 1182 { 1183 $sort_ctrl = array('oid' => "1.2.840.113556.1.4.473", 'value' => $this->_sort_ber_encode((array)$prop['sort'])); 1184 $vlv_ctrl = array('oid' => "2.16.840.1.113730.3.4.9", 'value' => $this->_vlv_ber_encode(($offset = ($list_page-1) * $page_size + 1), $page_size), 'iscritical' => true); 1185 1186 $sort = (array)$prop['sort']; 1187 $this->_debug("C: set controls sort=" . join(' ', unpack('H'.(strlen($sort_ctrl['value'])*2), $sort_ctrl['value'])) . " ($sort[0]);" 1188 . " vlv=" . join(' ', (unpack('H'.(strlen($vlv_ctrl['value'])*2), $vlv_ctrl['value']))) . " ($offset/$page_size)"); 1174 1189 1175 1190 if (!ldap_set_option($this->conn, LDAP_OPT_SERVER_CONTROLS, array($sort_ctrl, $vlv_ctrl))) { … … 1353 1368 * Fetch groups from server 1354 1369 */ 1355 private function _fetch_groups( )1370 private function _fetch_groups($vlv_page = 0) 1356 1371 { 1357 1372 $base_dn = $this->groups_base_dn; … … 1359 1374 $name_attr = $this->prop['groups']['name_attr']; 1360 1375 $email_attr = $this->prop['groups']['email_attr'] ? $this->prop['groups']['email_attr'] : 'mail'; 1376 $sort_attrs = $this->prop['groups']['sort'] ? (array)$this->prop['groups']['sort'] : array($name_attr); 1377 $sort_attr = $sort_attrs[0]; 1361 1378 1362 1379 $this->_debug("C: Search [$filter][dn: $base_dn]"); 1363 1380 1364 $res = @ldap_search($this->conn, $base_dn, $filter, array('dn', $name_attr, 'objectClass', $email_attr)); 1381 // use vlv to list groups 1382 if ($this->prop['groups']['vlv']) { 1383 $page_size = 200; 1384 if (!$this->prop['groups']['sort']) 1385 $this->prop['groups']['sort'] = $sort_attrs; 1386 $vlv_active = $this->_vlv_set_controls($this->prop['groups'], $vlv_page+1, $page_size); 1387 } 1388 1389 $function = $this->_scope2func($this->prop['groups']['scope'], $ns_function); 1390 $res = @$function($this->conn, $base_dn, $filter, array_unique(array('dn', 'objectClass', $name_attr, $email_attr, $sort_attr))); 1365 1391 if ($res === false) 1366 1392 { … … 1374 1400 $groups = array(); 1375 1401 $group_sortnames = array(); 1376 for ($i=0; $i<$ldap_data["count"]; $i++) 1377 { 1378 $group_name = $ldap_data[$i][$name_attr][0]; 1402 $group_count = $ldap_data["count"]; 1403 for ($i=0; $i < $group_count; $i++) 1404 { 1405 $group_name = is_array($ldap_data[$i][$name_attr]) ? $ldap_data[$i][$name_attr][0] : $ldap_data[$i][$name_attr]; 1379 1406 $group_id = self::dn_encode($group_name); 1380 1407 $groups[$group_id]['ID'] = $group_id; … … 1404 1431 } 1405 1432 1406 $group_sortnames[] = strtolower($group_name); 1407 } 1408 array_multisort($group_sortnames, SORT_ASC, SORT_STRING, $groups); 1433 $group_sortnames[] = strtolower($ldap_data[$i][$sort_attr][0]); 1434 } 1435 1436 // recursive call can exit here 1437 if ($vlv_page > 0) 1438 return $groups; 1439 1440 // call recursively until we have fetched all groups 1441 while ($vlv_active && $group_count == $page_size) 1442 { 1443 $next_page = $this->_fetch_groups(++$vlv_page); 1444 $groups = array_merge($groups, $next_page); 1445 $group_count = count($next_page); 1446 } 1447 1448 // when using VLV the list of groups is already sorted 1449 if (!$this->prop['groups']['vlv']) 1450 array_multisort($group_sortnames, SORT_ASC, SORT_STRING, $groups); 1409 1451 1410 1452 // cache this
Note: See TracChangeset
for help on using the changeset viewer.
