/// Create the user selector objects. $options = array('context' => $context, 'roleid' => $roleid); if ($context->contextlevel > CONTEXT_COURSE && !is_inside_frontpage($context)) { $potentialuserselector = new potential_assignees_below_course('addselect', $options); } else { $potentialuserselector = new potential_assignees_course_and_above('addselect', $options); } if ($context->contextlevel == CONTEXT_SYSTEM && is_admin_role($roleid)) { $currentuserselector = new existing_role_holders_site_admin('removeselect', $options); } else { $currentuserselector = new existing_role_holders('removeselect', $options); } /// Process incoming role assignments $errors = array(); if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) { $userstoassign = $potentialuserselector->get_selected_users(); if (!empty($userstoassign)) { foreach ($userstoassign as $adduser) { $allow = true; if ($inmeta) { if (has_capability('moodle/course:managemetacourse', $context, $adduser->id)) { //ok } else { $managerroles = get_roles_with_capability('moodle/course:managemetacourse', CAP_ALLOW, $context); if (!empty($managerroles) and !array_key_exists($roleid, $managerroles)) { $erruser = $DB->get_record('user', array('id' => $adduser->id), 'id, firstname, lastname'); $errors[] = get_string('metaassignerror', 'role', fullname($erruser)); $allow = false; } } }