From f2b7abf058f0d180e2c66b51dede4d854011377d Mon Sep 17 00:00:00 2001 From: danmarsden Date: Mon, 24 Jul 2006 00:37:58 +0000 Subject: [PATCH] =?utf8?q?Bug=20#5882=20ldap=20enrolment=20doesn't=20work.?= =?utf8?q?=20$USER->student=20getting=20munged=20patch=20from=20I=F1aki.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- enrol/ldap/enrol.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/enrol/ldap/enrol.php b/enrol/ldap/enrol.php index 93bc7115d9..6fbfc4033e 100755 --- a/enrol/ldap/enrol.php +++ b/enrol/ldap/enrol.php @@ -81,6 +81,9 @@ function get_user_courses(&$user, $type) { } } + /// Add it to new list + $newenrolments[$course_obj->id] = 'ldap'; + // deal with enrolment in the moodle db if (!empty($course_obj)) { // does course exist now? if(isset($user->{$type}[$course_obj->id]) && $user->{$type}[$course_obj->id] == 'ldap'){ @@ -105,18 +108,26 @@ function get_user_courses(&$user, $type) { // array, those are old enrolments that we want to remove (or are they?) if(!empty($user->{$type})){ foreach ($user->{$type} as $courseid => $value){ - if($value == 'ldap'){ // this was a legacy + if($value === 'ldap'){ // this was a legacy if ($type === 'student') { // enrol unenrol_student($user->id, $courseid); } else if ($type === 'teacher') { remove_teacher($user->id, $courseid); } unset($user->{$type}[$course_obj->id]); + } else { + // This one is from a non-database + // enrolment. Add it to the newenrolments + // array, so we don't loose it. + $newenrolments[$courseid] = $value; } } } + /// Overwrite the old array with the new one + $user->{$type} = $newenrolments; + @ldap_close($ldap_connection); return true; } -- 2.39.5