]> git.mjollnir.org Git - moodle.git/commitdiff
Added enrolperiod field.
authorikawhero <ikawhero>
Mon, 21 Jan 2008 06:09:58 +0000 (06:09 +0000)
committerikawhero <ikawhero>
Mon, 21 Jan 2008 06:09:58 +0000 (06:09 +0000)
admin/uploaduser.php

index 192fdf01500450bee122e2a8a39fad423641d670..e76a2f1adbb7210dc2afb2f54a4deebc9635176a 100755 (executable)
@@ -553,7 +553,7 @@ if ($formdata = $mform->is_cancelled()) {
             }
         }
 
-        // 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;
@@ -607,11 +607,23 @@ if ($formdata = $mform->is_cancelled()) {
                     $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');
@@ -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)) {