From 968083cd02ae00b4fe66006f7d987f90486a4bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 21 Apr 2013 17:20:09 +0200 Subject: [PATCH] MDL-39213 allow role assignments in frontpage in user upload --- admin/tool/uploaduser/index.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/admin/tool/uploaduser/index.php b/admin/tool/uploaduser/index.php index 88aaedab2c7..dd1baecbfa6 100644 --- a/admin/tool/uploaduser/index.php +++ b/admin/tool/uploaduser/index.php @@ -900,7 +900,28 @@ if ($formdata = $mform2->is_cancelled()) { } } - if ($manual and $manualcache[$courseid]) { + if ($courseid == SITEID) { + // Technically frontpage does not have enrolments, but only role assignments, + // let's not invent new lang strings here for this rarely used feature. + + if (!empty($user->{'role'.$i})) { + $addrole = $user->{'role'.$i}; + if (array_key_exists($addrole, $rolecache)) { + $rid = $rolecache[$addrole]->id; + } else { + $upt->track('enrolments', get_string('unknownrole', 'error', s($addrole)), 'error'); + continue; + } + + role_assign($rid, $user->id, context_course::instance($courseid)); + + $a = new stdClass(); + $a->course = $shortname; + $a->role = $rolecache[$rid]->name; + $upt->track('enrolments', get_string('enrolledincourserole', 'enrol_manual', $a)); + } + + } else if ($manual and $manualcache[$courseid]) { // find role $rid = false;