Check if ldap results can be paged or not
This functionnality is available for PHP 5.4 and higer
static public isLdapPageSizeAvailable ( $config_ldap, $check_config_value = true ) |
public function getAvailableValues() { if (!empty($this->fields['values'])) { $ldap_values = json_decode($this->fields['values']); $ldap_dropdown = new RuleRightParameter(); if (!$ldap_dropdown->getFromDB($ldap_values->ldap_attribute)) { return array(); } $attribute = array($ldap_dropdown->fields['value']); $config_ldap = new AuthLDAP(); if (!$config_ldap->getFromDB($ldap_values->ldap_auth)) { return array(); } if (!function_exists('warning_handler')) { function warning_handler($errno, $errstr, $errfile, $errline, array $errcontext) { if (0 === error_reporting()) { return false; } throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } } set_error_handler("warning_handler", E_WARNING); try { $tab_values = array(); $ds = $config_ldap->connect(); ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); $cookie = ''; do { if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { ldap_control_paged_result($ds, $config_ldap->fields['pagesize'], true, $cookie); } $result = ldap_search($ds, $config_ldap->fields['basedn'], $ldap_values->ldap_filter, $attribute); $entries = ldap_get_entries($ds, $result); array_shift($entries); foreach ($entries as $id => $attr) { if (isset($attr[$attribute[0]]) && !in_array($attr[$attribute[0]][0], $tab_values)) { $tab_values[$id] = $attr[$attribute[0]][0]; } } if (AuthLDAP::isLdapPageSizeAvailable($config_ldap)) { ldap_control_paged_result_response($ds, $result, $cookie); } } while ($cookie !== null && $cookie != ''); if ($this->fields['show_empty']) { $tab_values = array('' => '-----') + $tab_values; } asort($tab_values); return $tab_values; } catch (Exception $e) { return array(); } restore_error_handler(); } else { return array(); } }