public static void enrolUsers(MoodleEnrolUser[] user) throws UnsupportedEncodingException, MoodleRestEnrolException, MoodleRestException {
        try {
            StringBuilder data=new StringBuilder();
            String functionCall=MoodleCallRestWebService.isLegacy()?MoodleServices.MOODLE_ROLE_ASSIGN:MoodleServices.CORE_ROLE_ASSIGN_ROLES;
            if (MoodleCallRestWebService.getAuth()==null)
                throw new MoodleRestEnrolException();
            else
                data.append(MoodleCallRestWebService.getAuth());
            data.append("&").append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(functionCall, MoodleServices.ENCODING));
            for (int i=0;i<user.length;i++) {
                if (user[i]==null) throw new MoodleRestEnrolException();
                if (user[i].getRoleId()==-1) throw new MoodleRestEnrolException(); else data.append("&").append(URLEncoder.encode("assignments["+i+"][roleid]", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(""+user[i].getRoleId(), MoodleServices.ENCODING));
                if (user[i].getUserId()==-1) throw new MoodleRestEnrolException(); else data.append("&").append(URLEncoder.encode("assignments["+i+"][userid]", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(""+user[i].getUserId(), MoodleServices.ENCODING));
                if (user[i].getContextId()==-1) throw new MoodleRestEnrolException(); else data.append("&").append(URLEncoder.encode("assignments["+i+"][contextid]", MoodleServices.ENCODING)).append("=").append(URLEncoder.encode(""+user[i].getContextId(), MoodleServices.ENCODING));
            }
            data.trimToSize();
            MoodleCallRestWebService.call(data.toString());
        }  catch (IOException ex) {
            Logger.getLogger(MoodleRestEnrol.class.getName()).log(Level.SEVERE, null, ex);
        }
    }