Ejemplo n.º 1
0
$outcome->success = true;
$outcome->response = new stdClass();
$outcome->error = '';
$searchanywhere = get_user_preferences('userselector_searchanywhere', false);
switch ($action) {
    case 'unenrol':
        $ue = $DB->get_record('user_enrolments', array('id' => required_param('ue', PARAM_INT)), '*', MUST_EXIST);
        list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
        if (!$instance || !$plugin || !enrol_is_enabled($instance->enrol) || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/{$instance->enrol}:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
            throw new enrol_ajax_exception('unenrolnotpermitted');
        }
        break;
    case 'unassign':
        $role = required_param('role', PARAM_INT);
        $user = required_param('user', PARAM_INT);
        if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->unassign_role_from_user($user, $role)) {
            throw new enrol_ajax_exception('unassignnotpermitted');
        }
        break;
    case 'assign':
        $user = $DB->get_record('user', array('id' => required_param('user', PARAM_INT)), '*', MUST_EXIST);
        $roleid = required_param('roleid', PARAM_INT);
        if (!array_key_exists($roleid, $manager->get_assignable_roles())) {
            throw new enrol_ajax_exception('invalidrole');
        }
        if (!has_capability('moodle/role:assign', $manager->get_context()) || !$manager->assign_role_to_user($roleid, $user->id)) {
            throw new enrol_ajax_exception('assignnotpermitted');
        }
        $outcome->response->roleid = $roleid;
        break;
    case 'getassignable':
Ejemplo n.º 2
0
 // Check if the page is confirmed (and sesskey is correct)
 $confirm = optional_param('confirm', false, PARAM_BOOL) && confirm_sesskey();
 $actiontaken = false;
 $pagetitle = '';
 $pageheading = '';
 $mform = null;
 $pagecontent = null;
 switch ($action) {
     /**
      * Removes a role from the user with this course
      */
     case 'unassign':
         if (has_capability('moodle/role:assign', $manager->get_context())) {
             $role = required_param('roleid', PARAM_INT);
             $user = required_param('user', PARAM_INT);
             if ($confirm && $manager->unassign_role_from_user($user, $role)) {
                 redirect($PAGE->url);
             } else {
                 $user = $DB->get_record('user', array('id' => $user), '*', MUST_EXIST);
                 $allroles = $manager->get_all_roles();
                 $role = $allroles[$role];
                 $yesurl = new moodle_url($PAGE->url, array('action' => 'unassign', 'roleid' => $role->id, 'user' => $user->id, 'confirm' => 1, 'sesskey' => sesskey()));
                 $message = get_string('unassignconfirm', 'role', array('user' => fullname($user, true), 'role' => $role->localname));
                 $pagetitle = get_string('unassignarole', 'role', $role->localname);
                 $pagecontent = $OUTPUT->confirm($message, $yesurl, $PAGE->url);
             }
             $actiontaken = true;
         }
         break;
         /**
          * Assigns a new role to a user enrolled within this course.