Skip to content

Commit

Permalink
Added enrolperiod field.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikawhero committed Jan 21, 2008
1 parent bb1f083 commit 2686b6c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions admin/uploaduser.php
Expand Up @@ -553,7 +553,7 @@
}
}

// find course enrolments, groups and roles/types
// find course enrolments, groups, roles/types and enrol periods
foreach ($columns as $column) {
if (!preg_match('/^course\d+$/', $column)) {
continue;
Expand Down Expand Up @@ -607,11 +607,23 @@
$rid = $ccache[$shortname]->defaultrole;
}
}

// find duration
$timestart = 0;
$timeend = 0;
if (!empty($user->{'enrolperiod'.$i})) {
$duration = (int)$user->{'enrolperiod'.$i} * 86400; // convert days to seconds
if ($duration > 0) { // sanity check
$timestart = time();
$timeend = $timestart + $duration;
}
}

if ($rid) {
$a = new object();
$a->course = $shortname;
$a->role = $rolecache[$rid]->name;
if (role_assign($rid, $user->id, 0, $coursecontext->id)) {
if (role_assign($rid, $user->id, 0, $coursecontext->id, $timestart, $timeend)) {
$upt->track('enrolments', get_string('enrolledincourserole', '', $a));
} else {
$upt->track('enrolments', get_string('enrolledincoursenotrole', '', $a), 'error');
Expand Down Expand Up @@ -840,7 +852,8 @@ function validate_user_upload_columns(&$columns) {
$field = $columns[$key];
if (!in_array($field, $STD_FIELDS) && !in_array($field, $PRF_FIELDS) &&// if not a standard field and not an enrolment field, then we have an error
!preg_match('/^course\d+$/', $field) && !preg_match('/^group\d+$/', $field) &&
!preg_match('/^type\d+$/', $field) && !preg_match('/^role\d+$/', $field)) {
!preg_match('/^type\d+$/', $field) && !preg_match('/^role\d+$/', $field) &&
!preg_match('/^enrolperiod\d+$/', $field)) {
return get_string('invalidfieldname', 'error', $field);
}
if (in_array($field, $processed)) {
Expand Down

0 comments on commit 2686b6c

Please sign in to comment.