function ldap_get_userlist($filter='*') {
        $fresult = array();

        $ldapconnection = $this->ldap_connect();

        if ($filter == '*') {
           $filter = '(&('.$this->config->user_attribute.'=*)'.$this->config->objectclass.')';
        }

        $contexts = explode(';', $this->config->contexts);
        if (!empty($this->config->create_context)) {
            array_push($contexts, $this->config->create_context);
        }

        $ldap_cookie = '';
        $ldap_pagedresults = ldap_paged_results_supported($this->config->ldap_version, $ldapconnection);
        foreach ($contexts as $context) {
            $context = trim($context);
            if (empty($context)) {
                continue;
            }

            do {
                if ($ldap_pagedresults) {
                    ldap_control_paged_result($ldapconnection, $this->config->pagesize, true, $ldap_cookie);
                }
                if ($this->config->search_sub) {
                    // Use ldap_search to find first user from subtree.
                    $ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
                } else {
                    // Search only in this context.
                    $ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
                }
                if(!$ldap_result) {
                    continue;
                }
                if ($ldap_pagedresults) {
                    ldap_control_paged_result_response($ldapconnection, $ldap_result, $ldap_cookie);
                }
                $users = ldap_get_entries_moodle($ldapconnection, $ldap_result);
                // Add found users to list.
                for ($i = 0; $i < count($users); $i++) {
                    $extuser = core_text::convert($users[$i][$this->config->user_attribute][0],
                                                $this->config->ldapencoding, 'utf-8');
                    array_push($fresult, $extuser);
                }
                unset($ldap_result); // Free mem.
            } while ($ldap_pagedresults && !empty($ldap_cookie));
        }

        // If paged results were used, make sure the current connection is completely closed
        $this->ldap_close($ldap_pagedresults);
        return $fresult;
    }
function ldap_get_userlist($filter='*') {
        $fresult = array();

        $ldapconnection = $this->ldap_connect();

        if ($filter == '*') {
           $filter = '(&('.$this->config->user_attribute.'=*)'.$this->config->objectclass.')';
        }

        $contexts = explode(';', $this->config->contexts);
        if (!empty($this->config->create_context)) {
            array_push($contexts, $this->config->create_context);
        }

        $ldap_cookie = '';
        $ldap_pagedresults = ldap_paged_results_supported($this->config->ldap_version, $ldapconnection);
        foreach ($contexts as $context) {
            $context = trim($context);
            if (empty($context)) {
                continue;
            }

            do {
                if ($ldap_pagedresults) {
                    ldap_control_paged_result($ldapconnection, $this->config->pagesize, true, $ldap_cookie);
                }
                if ($this->config->search_sub) {
                    // Use ldap_search to find first user from subtree.
                    $ldap_result = ldap_search($ldapconnection, $context, $filter, array($this->config->user_attribute));
                } else {
                    // Search only in this context.
                    $ldap_result = ldap_list($ldapconnection, $context, $filter, array($this->config->user_attribute));
                }
                if(!$ldap_result) {
                    continue;
                }
                if ($ldap_pagedresults) {
                    ldap_control_paged_result_response($ldapconnection, $ldap_result, $ldap_cookie);
                }
                $users = ldap_get_entries_moodle($ldapconnection, $ldap_result);
                // Add found users to list.
                for ($i = 0; $i < count($users); $i++) {
                    $extuser = core_text::convert($users[$i][$this->config->user_attribute][0],
                                                $this->config->ldapencoding, 'utf-8');
                    array_push($fresult, $extuser);
                }
                unset($ldap_result); // Free mem.
            } while ($ldap_pagedresults && !empty($ldap_cookie));
        }

        // If paged results were used, make sure the current connection is completely closed
        $this->ldap_close($ldap_pagedresults);
        return $fresult;
    }
function ldap_get_userlist ( $ filter = '*' ) { $ fresult = array ( ) ; $ ldapconnection = $ this -> ldap_connect ( ) ; if ( $ filter == '*' ) { $ filter = '(&(' . $ this -> config -> user_attribute . '=*)' . $ this -> config -> objectclass . ')' ; } $ contexts = explode ( ';' , $ this -> config -> contexts ) ; if ( ! empty ( $ this -> config -> create_context ) ) { array_push ( $ contexts , $ this -> config -> create_context ) ; } $ ldap_cookie = '' ; $ ldap_pagedresults = ldap_paged_results_supported ( $ this -> config -> ldap_version , $ ldapconnection ) ; foreach ( $ contexts as $ context ) { $ context = trim ( $ context ) ; if ( empty ( $ context ) ) { continue ; } do { if ( $ ldap_pagedresults ) { ldap_control_paged_result ( $ ldapconnection , $ this -> config -> pagesize , true , $ ldap_cookie ) ; } if ( $ this -> config -> search_sub ) { // Use ldap_search to find first user from subtree. $ ldap_result = ldap_search ( $ ldapconnection , $ context , $ filter , array ( $ this -> config -> user_attribute ) ) ; } else { // Search only in this context. $ ldap_result = ldap_list ( $ ldapconnection , $ context , $ filter , array ( $ this -> config -> user_attribute ) ) ; } if ( ! $ ldap_result ) { continue ; } if ( $ ldap_pagedresults ) { ldap_control_paged_result_response ( $ ldapconnection , $ ldap_result , $ ldap_cookie ) ; } $ users = ldap_get_entries_moodle ( $ ldapconnection , $ ldap_result ) ; // Add found users to list. for ( $ i = 0 ; $ i < count ( $ users ) ; $ i ++ ) { $ extuser = core_text :: convert ( $ users [ $ i ] [ $ this -> config -> user_attribute ] [ 0 ] , $ this -> config -> ldapencoding , 'utf-8' ) ; array_push ( $ fresult , $ extuser ) ; } unset ( $ ldap_result ) ; // Free mem. } while ( $ ldap_pagedresults && ! empty ( $ ldap_cookie ) ) ; } // If paged results were used, make sure the current connection is completely closed $ this -> ldap_close ( $ ldap_pagedresults ) ; return $ fresult ; }
Returns all usernames from LDAP

@param $filter An LDAP search filter to select desired users
@return array of LDAP user names converted to UTF-8
Returns all usernames from LDAP