public function course_enrolments($courseid, $roles=null) {
        global $DB, $CFG;

        if (!$client = get_mnet_remote_client()) {
            die('Callable via XML-RPC only');
        }

        $sql = "SELECT u.username, r.shortname, r.name, e.enrol, ue.timemodified
                  FROM {user_enrolments} ue
                  JOIN {user} u ON ue.userid = u.id
                  JOIN {enrol} e ON ue.enrolid = e.id
                  JOIN {role} r ON e.roleid = r.id
                 WHERE u.mnethostid = :mnethostid
                       AND e.courseid = :courseid
                       AND u.id <> :guestid
                       AND u.confirmed = 1
                       AND u.deleted = 0";
        $params['mnethostid'] = $client->id;
        $params['courseid'] = $courseid;
        $params['guestid'] = $CFG->siteguest;

        if (!is_null($roles)) {
            if (!is_array($roles)) {
                $roles = explode(',', $roles);
            }
            $roles = array_map('trim', $roles);
            list($rsql, $rparams) = $DB->get_in_or_equal($roles, SQL_PARAMS_NAMED);
            $sql .= " AND r.shortname $rsql";
            $params = array_merge($params, $rparams);
        }

        list($sort, $sortparams) = users_order_by_sql('u');
        $sql .= " ORDER BY $sort";

        $rs = $DB->get_recordset_sql($sql, array_merge($params, $sortparams));
        $list = array();
        foreach ($rs as $record) {
            $list[] = $record;
        }
        $rs->close();

        return $list;
    }