}
if ($rid) {
- // find duration
- $timeend = 0;
+ // Find duration and/or enrol status.
+ $timeend = 0;
+ $status = null;
+
+ if (isset($user->{'enrolstatus'.$i})) {
+ $enrolstatus = trim($user->{'enrolstatus'.$i});
+ if ($enrolstatus == '') {
+ $status = null;
+ } else if ($enrolstatus === (string)ENROL_USER_ACTIVE) {
+ $status = ENROL_USER_ACTIVE;
+ } else if ($enrolstatus === (string)ENROL_USER_SUSPENDED) {
+ $status = ENROL_USER_SUSPENDED;
+ } else {
+ debugging('Unknown enrolment status.');
+ }
+ }
+
if (!empty($user->{'enrolperiod'.$i})) {
$duration = (int)$user->{'enrolperiod'.$i} * 60*60*24; // convert days to seconds
if ($duration > 0) { // sanity check
$timeend = $today + $manualcache[$courseid]->enrolperiod;
}
- $manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend);
+ $manual->enrol_user($manualcache[$courseid], $user->id, $rid, $today, $timeend, $status);
$a = new stdClass();
$a->course = $shortname;
// hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field
$newfield = $lcfield;
- } else if (preg_match('/^(cohort|course|group|type|role|enrolperiod)\d+$/', $lcfield)) {
+ } else if (preg_match('/^(cohort|course|group|type|role|enrolperiod|enrolstatus)\d+$/', $lcfield)) {
// special fields for enrolments
$newfield = $lcfield;