当前位置: 首页>>代码示例>>PHP>>正文


PHP role_unassign函数代码示例

本文整理汇总了PHP中role_unassign函数的典型用法代码示例。如果您正苦于以下问题:PHP role_unassign函数的具体用法?PHP role_unassign怎么用?PHP role_unassign使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了role_unassign函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: test_assign_roles

 /**
  * Test assign_roles
  */
 public function test_assign_roles()
 {
     global $USER;
     $this->resetAfterTest(true);
     $course = self::getDataGenerator()->create_course();
     // Set the required capabilities by the external function.
     $context = context_course::instance($course->id);
     $roleid = $this->assignUserCapability('moodle/role:assign', $context->id);
     $this->assignUserCapability('moodle/course:view', $context->id, $roleid);
     // Add manager role to $USER.
     // So $USER is allowed to assign 'manager', 'editingteacher', 'teacher' and 'student'.
     role_assign(1, $USER->id, context_system::instance()->id);
     // Check the teacher role has not been assigned to $USER.
     $users = get_role_users(3, $context);
     $this->assertEquals(count($users), 0);
     // Call the external function. Assign teacher role to $USER with contextid.
     core_role_external::assign_roles(array(array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id)));
     // Check the role has been assigned.
     $users = get_role_users(3, $context);
     $this->assertEquals(count($users), 1);
     // Unassign role.
     role_unassign(3, $USER->id, $context->id);
     $users = get_role_users(3, $context);
     $this->assertEquals(count($users), 0);
     // Call the external function. Assign teacher role to $USER.
     core_role_external::assign_roles(array(array('roleid' => 3, 'userid' => $USER->id, 'contextlevel' => "course", 'instanceid' => $course->id)));
     $users = get_role_users(3, $context);
     $this->assertEquals(count($users), 1);
     // Call without required capability.
     $this->unassignUserCapability('moodle/role:assign', $context->id, $roleid);
     $this->expectException('moodle_exception');
     $categories = core_role_external::assign_roles(array('roleid' => 3, 'userid' => $USER->id, 'contextid' => $context->id));
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:36,代码来源:role_external_test.php

示例2: _unenrollUserFromCourse

function _unenrollUserFromCourse($user, $course)
{
    $retVal = true;
    echo "<br> {$username} is now going to be unenrolled from {$course->fullname}.";
    if (unenrollQSUser($user, $course)) {
        echo "<br> unenrollQSUser for {$user->username} and {$course->fullname} was successful.";
        if (enrollUserInCourse($user->username, $user->username, $course->fullname, false)) {
            echo "<br> enrollUserInCourse for {$user->username} and {$course->fullname} and false was successful.";
            if (!($context = get_context_instance(CONTEXT_COURSE, $course->id))) {
                echo "<br> Course context for {$course->fullname} is invalid";
                admin_moodlefailed_email($user, 'unenrollUser', $course);
                $retVal = false;
            }
            echo "<br> Course context id is {$context->id}";
            if (!role_unassign(0, $user->id, 0, $context->id)) {
                echo "An error occurred in role_unassign while trying to unenroll {$username} from vLab via auto-delete.";
                admin_moodlefailed_email($user, 'unenrollUser', $course);
                $retVal = false;
            }
            echo "<br> role_unassign for user id of {$user->id} and context id of {$context->id} was successful.";
            send_unenrollment_notification($course, $user);
            add_to_log($course->id, 'course', 'unenrol', "auto-delete", $course->id);
        } else {
            enrollQSUser($user, $course);
            echo "An error occurred in enrollUserInCourse while trying to unenrll {$username} from vLab via auto-delete.";
            admin_moodlefailed_email($user, 'unenrollUser', $course);
            $retVal = false;
        }
    } else {
        echo "An error occurred in unenrollQSUser while trying to unenroll {$username} from vLab via auto-delete.";
        admin_moodlefailed_email($user, 'unenrollUser', $course);
        $retVal = false;
    }
    return $retVal;
}
开发者ID:kaseya-university,项目名称:efront,代码行数:35,代码来源:auto-delete.php

示例3: perform_remove

 function perform_remove($userid)
 {
     // Try to remove the necessary role
     $context = get_context_instance(CONTEXT_SYSTEM);
     $roleid = $this->check_role();
     // Regardless if the user has the role or not, remove the assignment
     if ($assign = get_record('block_student_' . $this->type, 'path', $this->path, 'usersid', $userid)) {
         $this->remove_assignment($assign);
     }
     $count = count_records('block_student_' . $this->type, 'usersid', $userid) + count_records('block_student_person', 'usersid', $userid);
     // If they don't have any mentor assignments, then remove them from that role
     if ($count == 0) {
         role_unassign($roleid, $userid, 0, $context->id);
     }
 }
开发者ID:rrusso,项目名称:EARS,代码行数:15,代码来源:lib.php

示例4: delete_user

function delete_user($user)
{
    $updateuser = new object();
    $updateuser->id = $user->id;
    $updateuser->deleted = 1;
    $updateuser->username = addslashes("{$user->email}." . time());
    $updateuser->email = '';
    $updateuser->idnumber = '';
    $updateuser->timemodified = time();
    if (update_record('user', $updateuser)) {
        role_unassign(0, $user->id);
        return true;
    } else {
        return false;
    }
}
开发者ID:veritech,项目名称:pare-project,代码行数:16,代码来源:index.php

示例5: require_capability

} else {
    // Unenrol yourself
    require_capability('moodle/role:unassignself', $context, NULL, false);
}
if (!empty($USER->access['rsw'][$context->path])) {
    print_error('cantunenrollinthisrole', '', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
}
if ($confirm and confirm_sesskey()) {
    if ($userid) {
        if (!role_unassign(0, $userid, 0, $context->id)) {
            print_error("unenrolerror");
        }
        add_to_log($course->id, 'course', 'unenrol', "view.php?id={$course->id}", $course->id);
        redirect($CFG->wwwroot . '/user/index.php?id=' . $course->id);
    } else {
        if (!role_unassign(0, $USER->id, 0, $context->id)) {
            print_error("unenrolerror");
        }
        // force a refresh of mycourses
        unset($USER->mycourses);
        add_to_log($course->id, 'course', 'unenrol', "view.php?id={$course->id}", $course->id);
        redirect($CFG->wwwroot);
    }
}
$strunenrol = get_string('unenrol');
$navlinks = array();
$navlinks[] = array('name' => $strunenrol, 'link' => null, 'type' => 'misc');
$navigation = build_navigation($navlinks);
print_header("{$course->shortname}: {$strunenrol}", $course->fullname, $navigation);
if ($userid) {
    if (!($user = $DB->get_record('user', array('id' => $userid)))) {
开发者ID:ajv,项目名称:Offline-Caching,代码行数:31,代码来源:unenrol.php

示例6: sync_enrolments


//.........这里部分代码省略.........
                     } else {
                         $roleid = $roles[$fields[$rolefield_l]];
                     }
                     $requested_roles[$userid][$roleid] = $roleid;
                 }
             }
             $rs->Close();
         } else {
             mtrace("  error: skipping course '{$course->mapping}' - could not match with external database");
             continue;
         }
         unset($user_mapping);
         // Enrol all users and sync roles.
         foreach ($requested_roles as $userid => $userroles) {
             foreach ($userroles as $roleid) {
                 if (empty($current_roles[$userid])) {
                     $this->enrol_user($instance, $userid, $roleid, 0, 0, ENROL_USER_ACTIVE);
                     $current_roles[$userid][$roleid] = $roleid;
                     $current_status[$userid] = ENROL_USER_ACTIVE;
                     if ($verbose) {
                         mtrace("  enrolling: {$userid} ==> {$course->shortname} as " . $allroles[$roleid]->shortname);
                     }
                 }
             }
             // Assign extra roles.
             foreach ($userroles as $roleid) {
                 if (empty($current_roles[$userid][$roleid])) {
                     role_assign($roleid, $userid, $context->id, 'enrol_database', $instance->id);
                     $current_roles[$userid][$roleid] = $roleid;
                     if ($verbose) {
                         mtrace("  assigning roles: {$userid} ==> {$course->shortname} as " . $allroles[$roleid]->shortname);
                     }
                 }
             }
             // Unassign removed roles.
             foreach ($current_roles[$userid] as $cr) {
                 if (empty($userroles[$cr])) {
                     role_unassign($cr, $userid, $context->id, 'enrol_database', $instance->id);
                     unset($current_roles[$userid][$cr]);
                     if ($verbose) {
                         mtrace("  unsassigning roles: {$userid} ==> {$course->shortname}");
                     }
                 }
             }
             // Reenable enrolment when previously disable enrolment refreshed.
             if ($current_status[$userid] == ENROL_USER_SUSPENDED) {
                 $this->update_user_enrol($instance, $userid, ENROL_USER_ACTIVE);
                 if ($verbose) {
                     mtrace("  unsuspending: {$userid} ==> {$course->shortname}");
                 }
             }
         }
         // Deal with enrolments removed from external table.
         if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
             if (!$preventfullunenrol) {
                 // Unenrol.
                 foreach ($current_status as $userid => $status) {
                     if (isset($requested_roles[$userid])) {
                         continue;
                     }
                     $this->unenrol_user($instance, $userid);
                     if ($verbose) {
                         mtrace("  unenrolling: {$userid} ==> {$course->shortname}");
                     }
                 }
             }
         } else {
             if ($unenrolaction == ENROL_EXT_REMOVED_KEEP) {
                 // Keep - only adding enrolments.
             } else {
                 if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
                     // Suspend enrolments.
                     foreach ($current_status as $userid => $status) {
                         if (isset($requested_roles[$userid])) {
                             continue;
                         }
                         if ($status != ENROL_USER_SUSPENDED) {
                             $this->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
                             if ($verbose) {
                                 mtrace("  suspending: {$userid} ==> {$course->shortname}");
                             }
                         }
                         if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
                             role_unassign_all(array('contextid' => $context->id, 'userid' => $userid, 'component' => 'enrol_database', 'itemid' => $instance->id));
                             if ($verbose) {
                                 mtrace("  unsassigning all roles: {$userid} ==> {$course->shortname}");
                             }
                         }
                     }
                 }
             }
         }
     }
     // Close db connection.
     $extdb->Close();
     if ($verbose) {
         mtrace('...user enrolment synchronisation finished.');
     }
     return 0;
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:101,代码来源:lib.php

示例7: sync_with_parent_course

 /**
  * Synchronise user enrolments in given instance as fast as possible.
  *
  * All roles are removed if the meta plugin disabled.
  *
  * @static
  * @param stdClass $instance
  * @param int $userid
  * @return void
  */
 protected static function sync_with_parent_course(stdClass $instance, $userid)
 {
     global $DB, $CFG;
     $plugin = enrol_get_plugin('meta');
     if ($instance->customint1 == $instance->courseid) {
         // can not sync with self!!!
         return;
     }
     $context = context_course::instance($instance->courseid);
     if (!($parentcontext = context_course::instance($instance->customint1, IGNORE_MISSING))) {
         // linking to missing course is not possible
         role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_meta'));
         return;
     }
     // list of enrolments in parent course (we ignore meta enrols in parents completely)
     list($enabled, $params) = $DB->get_in_or_equal(explode(',', $CFG->enrol_plugins_enabled), SQL_PARAMS_NAMED, 'e');
     $params['userid'] = $userid;
     $params['parentcourse'] = $instance->customint1;
     $sql = "SELECT ue.*\n                  FROM {user_enrolments} ue\n                  JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol <> 'meta' AND e.courseid = :parentcourse AND e.enrol {$enabled})\n                 WHERE ue.userid = :userid";
     $parentues = $DB->get_records_sql($sql, $params);
     // current enrolments for this instance
     $ue = $DB->get_record('user_enrolments', array('enrolid' => $instance->id, 'userid' => $userid));
     // first deal with users that are not enrolled in parent
     if (empty($parentues)) {
         self::user_not_supposed_to_be_here($instance, $ue, $context, $plugin);
         return;
     }
     if (!enrol_is_enabled('meta')) {
         if ($ue) {
             role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_meta'));
         }
         return;
     }
     $skiproles = $plugin->get_config('nosyncroleids', '');
     $skiproles = empty($skiproles) ? array() : explode(',', $skiproles);
     $syncall = $plugin->get_config('syncall', 1);
     // roles in parent course (meta enrols must be ignored!)
     $parentroles = array();
     list($ignoreroles, $params) = $DB->get_in_or_equal($skiproles, SQL_PARAMS_NAMED, 'ri', false, -1);
     $params['contextid'] = $parentcontext->id;
     $params['userid'] = $userid;
     $select = "contextid = :contextid AND userid = :userid AND component <> 'enrol_meta' AND roleid {$ignoreroles}";
     foreach ($DB->get_records_select('role_assignments', $select, $params) as $ra) {
         $parentroles[$ra->roleid] = $ra->roleid;
     }
     // roles from this instance
     $roles = array();
     $ras = $DB->get_records('role_assignments', array('contextid' => $context->id, 'userid' => $userid, 'component' => 'enrol_meta', 'itemid' => $instance->id));
     foreach ($ras as $ra) {
         $roles[$ra->roleid] = $ra->roleid;
     }
     unset($ras);
     // do we want users without roles?
     if (!$syncall and empty($parentroles)) {
         self::user_not_supposed_to_be_here($instance, $ue, $context, $plugin);
         return;
     }
     // is parent enrol active? (we ignore enrol starts and ends, sorry it would be too complex)
     $parentstatus = ENROL_USER_SUSPENDED;
     foreach ($parentues as $pue) {
         if ($pue->status == ENROL_USER_ACTIVE) {
             $parentstatus = ENROL_USER_ACTIVE;
             break;
         }
     }
     // enrol user if not enrolled yet or fix status
     if ($ue) {
         if ($parentstatus != $ue->status) {
             $plugin->update_user_enrol($instance, $userid, $parentstatus);
             $ue->status = $parentstatus;
         }
     } else {
         $plugin->enrol_user($instance, $userid, NULL, 0, 0, $parentstatus);
         $ue = new stdClass();
         $ue->userid = $userid;
         $ue->enrolid = $instance->id;
         $ue->status = $parentstatus;
     }
     // only active users in enabled instances are supposed to have roles (we can reassign the roles any time later)
     if ($ue->status != ENROL_USER_ACTIVE or $instance->status != ENROL_INSTANCE_ENABLED) {
         if ($roles) {
             role_unassign_all(array('userid' => $userid, 'contextid' => $context->id, 'component' => 'enrol_meta', 'itemid' => $instance->id));
         }
         return;
     }
     // add new roles
     foreach ($parentroles as $rid) {
         if (!isset($roles[$rid])) {
             role_assign($rid, $userid, $context->id, 'enrol_meta', $instance->id);
         }
//.........这里部分代码省略.........
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:101,代码来源:locallib.php

示例8: admin_webservicefailed_email

     echo "<br> \$destination is set to {$destination}";
     if (!enrollQSUser($user, $course)) {
         //Added: 12.30.2010
         echo "<br> enrollQSUser was NOT successful";
         admin_webservicefailed_email($user, 'enrollUser', $course);
         if (!role_unassign(0, $user->id, 0, $context->id)) {
             // Should email the Admin if this happens
             error("An error occurred while trying to unenrol that person.");
             exit;
         }
         //admin_moodlefailed_email($user,'unenrollUser');
     } else {
         echo "<br> enrollQSUser was successful";
         if (!enrollUserInCourse($user->username, $user->username, $course->fullname, true)) {
             echo "<br> enrollUserInCourse was NOT successful";
             if (!role_unassign(0, $user->id, 0, $context->id)) {
                 error("An error occurred while trying to unenrol that person.");
                 exit;
             }
             echo "<br> role_unassign was successful";
             // Should email the Admin if this happens
             unenrollQSUser($user, $course);
             admin_webservicefailed_email($user, 'enrollUser', $course);
         }
         echo "<br> enrollUserInCourse was successful";
     }
     $payload = file_get_contents($destination);
     send_enrollment_notification($course, $user);
 } else {
     echo "<br> User {$user->username} was already enrolled in course {$course->fullname}";
 }
开发者ID:kaseya-university,项目名称:efront,代码行数:31,代码来源:auto-enroll.php

示例9: sync_enrolments


//.........这里部分代码省略.........
         } else {
             //search only in this context
             $ldap_result = @ldap_list($ldap_connection, $context, $ldap_search_pattern, $ldap_fields_wanted, 0, 0);
         }
         // check and push results
         $records = $ldap_result ? ldap_get_entries($ldap_connection, $ldap_result) : array('count' => 0);
         // ldap libraries return an odd array, really. fix it:
         $flat_records = array();
         for ($c = 0; $c < $records['count']; $c++) {
             array_push($flat_records, $records["{$c}"]);
         }
         // free mem -- is there a leak?
         $records = 0;
         $ldap_result = 0;
         if (count($flat_records)) {
             foreach ($flat_records as $course) {
                 $idnumber = $course[$CFG->enrol_ldap_course_idnumber][0];
                 print "== Synching {$idnumber}\n";
                 // does the course exist in moodle already?
                 $course_obj = false;
                 $course_obj = get_record('course', $this->enrol_localcoursefield, $idnumber);
                 if (!is_object($course_obj)) {
                     // ok, now then let's create it!
                     print "Creating Course {$idnumber}...";
                     $newcourseid = $this->create_course($course, true);
                     // we are skipping fix_course_sortorder()
                     $course_obj = get_record('course', 'id', $newcourseid);
                     if (is_object($course_obj)) {
                         print "OK!\n";
                     } else {
                         print "failed\n";
                     }
                 }
                 // enrol&unenrol if required
                 if ($enrol && is_object($course_obj)) {
                     // Get a context object.
                     $context = get_context_instance(CONTEXT_COURSE, $course_obj->id);
                     // pull the ldap membership into a nice array
                     // this is an odd array -- mix of hash and array --
                     $ldapmembers = array();
                     if (array_key_exists('enrol_ldap_memberattribute_role' . $role->id, $CFG) && !empty($CFG->{'enrol_ldap_memberattribute_role' . $role->id}) && !empty($course[strtolower($CFG->{'enrol_ldap_memberattribute_role' . $role->id})])) {
                         // may have no membership!
                         $ldapmembers = $course[strtolower($CFG->{'enrol_ldap_memberattribute_role' . $role->id})];
                         unset($ldapmembers['count']);
                         // remove oddity ;)
                         $ldapmembers = addslashes_recursive($ldapmembers);
                     }
                     // prune old ldap enrolments
                     // hopefully they'll fit in the max buffer size for the RDBMS
                     $sql = '
                     SELECT enr.userid AS user, 1
                     FROM ' . $CFG->prefix . 'role_assignments enr
                     JOIN ' . $CFG->prefix . 'user usr ON usr.id=enr.userid
                     WHERE enr.roleid = ' . $role->id . '
                      AND enr.contextid = ' . $context->id . '
                      AND enr.enrol = \'ldap\' ';
                     if (!empty($ldapmembers)) {
                         $sql .= 'AND usr.idnumber NOT IN (\'' . join('\',\'', $ldapmembers) . '\')';
                     } else {
                         print "Empty enrolment for {$course_obj->shortname} \n";
                     }
                     $todelete = get_records_sql($sql);
                     if (!empty($todelete)) {
                         foreach ($todelete as $member) {
                             $member = $member->user;
                             if (role_unassign($role->id, $member, 0, $context->id, 'ldap')) {
                                 print "Unassigned {$type} from {$member} for course {$course_obj->id} ({$course_obj->shortname})\n";
                             } else {
                                 print "Failed to unassign {$type} from {$member} for course {$course_obj->id} ({$course_obj->shortname})\n";
                             }
                         }
                     }
                     // insert current enrolments
                     // bad we can't do INSERT IGNORE with postgres...
                     foreach ($ldapmembers as $ldapmember) {
                         $sql = 'SELECT id,1 FROM ' . $CFG->prefix . 'user ' . " WHERE idnumber='{$ldapmember}'";
                         $member = get_record_sql($sql);
                         //                        print "sql: $sql \nidnumber = ".stripslashes($ldapmember)." \n".var_dump($member);
                         if (empty($member) || empty($member->id)) {
                             print "Could not find user " . stripslashes($ldapmember) . ", skipping\n";
                             continue;
                         }
                         $member = $member->id;
                         if (!get_record('role_assignments', 'roleid', $role->id, 'contextid', $context->id, 'userid', $member, 'enrol', 'ldap')) {
                             if (role_assign($role->id, $member, 0, $context->id, 0, 0, 0, 'ldap')) {
                                 print "Assigned role {$type} to {$member} (" . stripslashes($ldapmember) . ") for course {$course_obj->id} ({$course_obj->shortname})\n";
                             } else {
                                 print "Failed to assign role {$type} to {$member} (" . stripslashes($ldapmember) . ") for course {$course_obj->id} ({$course_obj->shortname})\n";
                             }
                         }
                     }
                 }
             }
         }
     }
     // we are done now, a bit of housekeeping
     fix_course_sortorder();
     @ldap_close($ldap_connection);
     return true;
 }
开发者ID:arshanam,项目名称:Moodle-ITScholars-LMS,代码行数:101,代码来源:enrol.php

示例10: substr

         $sysrolename = $user->{$column};
         if ($sysrolename[0] == '-') {
             $removing = true;
             $sysrolename = substr($sysrolename, 1);
         } else {
             $removing = false;
         }
         if (array_key_exists($sysrolename, $sysrolecache)) {
             $sysroleid = $sysrolecache[$sysrolename]->id;
         } else {
             $upt->track('enrolments', get_string('unknownrole', 'error', s($sysrolename)), 'error');
             continue;
         }
         if ($removing) {
             if (user_has_role_assignment($user->id, $sysroleid, SYSCONTEXTID)) {
                 role_unassign($sysroleid, $user->id, SYSCONTEXTID);
                 $upt->track('enrolments', get_string('unassignedsysrole', 'tool_uploaduser', $sysrolecache[$sysroleid]->name));
             }
         } else {
             if (!user_has_role_assignment($user->id, $sysroleid, SYSCONTEXTID)) {
                 role_assign($sysroleid, $user->id, SYSCONTEXTID);
                 $upt->track('enrolments', get_string('assignedsysrole', 'tool_uploaduser', $sysrolecache[$sysroleid]->name));
             }
         }
     }
     continue;
 }
 if (!preg_match('/^course\\d+$/', $column)) {
     continue;
 }
 $i = substr($column, 6);
开发者ID:educakanchay,项目名称:campus,代码行数:31,代码来源:index.php

示例11: email_paypal_error_to_admin

    echo "<p>Error: could not access paypal.com</p>";
    email_paypal_error_to_admin("Could not access paypal.com to verify payment", $data);
    die;
}
/// Connection is OK, so now we post the data to validate it
fputs($fp, $header . $req);
/// Now read the response and check if everything is OK.
while (!feof($fp)) {
    $result = fgets($fp, 1024);
    if (strcmp($result, "VERIFIED") == 0) {
        // VALID PAYMENT!
        // check the payment_status and payment_reason
        // If status is not completed or pending then unenrol the student if already enrolled
        // and notify admin
        if ($data->payment_status != "Completed" and $data->payment_status != "Pending") {
            role_unassign(0, $data->userid, 0, $context->id);
            // force accessinfo refresh for users visiting this context...
            mark_context_dirty($context->path);
            email_paypal_error_to_admin("Status not completed or pending. User unenrolled from course", $data);
            die;
        }
        // If status is pending and reason is other than echeck then we are on hold until further notice
        // Email user to let them know. Email admin.
        if ($data->payment_status == "Pending" and $data->pending_reason != "echeck") {
            email_to_user($user, get_admin(), "Moodle: PayPal payment", "Your PayPal payment is pending.");
            email_paypal_error_to_admin("Payment pending", $data);
            die;
        }
        // If our status is not completed or not pending on an echeck clearance then ignore and die
        // This check is redundant at present but may be useful if paypal extend the return codes in the future
        if (!($data->payment_status == "Completed" or $data->payment_status == "Pending" and $data->pending_reason == "echeck")) {
开发者ID:BackupTheBerlios,项目名称:samouk-svn,代码行数:31,代码来源:ipn.php

示例12: remove_user_role

 function remove_user_role($username, $course_id, $role_id)
 {
     global $DB;
     $username = utf8_decode($username);
     $username = strtolower($username);
     $params = array('username' => $username);
     $user = $DB->get_record('user', $params);
     if (!$user) {
         return;
     }
     $params = array('id' => $course_id);
     $course = $DB->get_record('course', $params);
     $context = context_course::instance($course->id);
     if (!$context) {
         return;
     }
     if (!role_unassign($role_id, $user->id, $context->id)) {
         return;
     }
 }
开发者ID:anawu2006,项目名称:PeerLearning,代码行数:20,代码来源:auth.php

示例13: sync_enrolments


//.........这里部分代码省略.........
         $sql = "SELECT {$CFG->enrol_remoteuserfield} " . " FROM {$CFG->enrol_dbtable} " . " WHERE {$CFG->enrol_remotecoursefield} = " . $enroldb->quote($extcourse) . ($have_role ? ' AND ' . $remote_role_name . ' = ' . $remote_role_value : '');
         $crs = $enroldb->Execute($sql);
         if (!$crs) {
             trigger_error($enroldb->ErrorMsg() . ' STATEMENT: ' . $sql);
             return false;
         }
         if ($crs->EOF) {
             // shouldn't happen, but cover all bases
             continue;
         }
         // slurp results into an array
         while ($crs_obj = rs_fetch_next_record($crs)) {
             $crs_obj = (object) array_change_key_case((array) $crs_obj, CASE_LOWER);
             array_push($extenrolments, $crs_obj->{strtolower($CFG->enrol_remoteuserfield)});
         }
         rs_close($crs);
         // release the handle
         //
         // prune enrolments to users that are no longer in ext auth
         // hopefully they'll fit in the max buffer size for the RDBMS
         //
         // TODO: This doesn't work perfectly.  If we are operating without
         // roles in the external DB, then this doesn't handle changes of role
         // within a course (because the user is still enrolled in the course,
         // so NOT IN misses the course).
         //
         // When the user logs in though, their role list will be updated
         // correctly.
         //
         if (!$CFG->enrol_db_disableunenrol) {
             $to_prune = get_records_sql("\n             SELECT ra.*\n             FROM {$CFG->prefix}role_assignments ra\n              JOIN {$CFG->prefix}user u ON ra.userid = u.id\n             WHERE ra.enrol = 'database'\n              AND ra.contextid = {$context->id}\n              AND ra.roleid = " . $role->id . ($extenrolments ? " AND u.{$CFG->enrol_localuserfield} NOT IN (" . join(", ", array_map(array(&$db, 'quote'), $extenrolments)) . ")" : ''));
             if ($to_prune) {
                 foreach ($to_prune as $role_assignment) {
                     if (role_unassign($role->id, $role_assignment->userid, 0, $role_assignment->contextid)) {
                         error_log("Unassigned {$role->shortname} assignment #{$role_assignment->id} for course {$course->id} (" . format_string($course->shortname) . "); user {$role_assignment->userid}");
                     } else {
                         error_log("Failed to unassign {$role->shortname} assignment #{$role_assignment->id} for course {$course->id} (" . format_string($course->shortname) . "); user {$role_assignment->userid}");
                     }
                 }
             }
         }
         //
         // insert current enrolments
         // bad we can't do INSERT IGNORE with postgres...
         //
         foreach ($extenrolments as $member) {
             // Get the user id and whether is enrolled in one fell swoop
             $sql = "\n                SELECT u.id AS userid, ra.id AS enrolmentid\n                FROM {$CFG->prefix}user u\n                 LEFT OUTER JOIN {$CFG->prefix}role_assignments ra ON u.id = ra.userid\n                  AND ra.roleid = {$role->id}\n                  AND ra.contextid = {$context->id}\n                 WHERE u.{$CFG->enrol_localuserfield} = " . $db->quote($member) . " AND (u.deleted IS NULL OR u.deleted=0) ";
             $ers = $db->Execute($sql);
             if (!$ers) {
                 trigger_error($db->ErrorMsg() . ' STATEMENT: ' . $sql);
                 return false;
             }
             if ($ers->EOF) {
                 // if this returns empty, it means we don't have the student record.
                 // should not happen -- but skip it anyway
                 trigger_error('weird! no user record entry?');
                 continue;
             }
             $user_obj = rs_fetch_record($ers);
             $userid = $user_obj->userid;
             $enrolmentid = $user_obj->enrolmentid;
             rs_close($ers);
             // release the handle
             if ($enrolmentid) {
                 // already enrolled - skip
开发者ID:nadavkav,项目名称:MoodleTAO,代码行数:67,代码来源:enrol.php

示例14: process

 public function process($departmentid, $roletype)
 {
     global $DB, $USER;
     $companymanagerrole = $DB->get_record('role', array('shortname' => 'companymanager'));
     $departmentmanagerrole = $DB->get_record('role', array('shortname' => 'companydepartmentmanager'));
     $companycoursenoneditorrole = $DB->get_record('role', array('shortname' => 'companycoursenoneditor'));
     $companycourseeditorrole = $DB->get_record('role', array('shortname' => 'companycourseeditor'));
     // Process incoming assignments.
     if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
         $userstoassign = $this->potentialusers->get_selected_users();
         if (!empty($userstoassign)) {
             foreach ($userstoassign as $adduser) {
                 $allow = true;
                 // GWL : Check the userid is valid.
                 if (!company::check_valid_user($this->selectedcompany, $adduser->id, $this->departmentid)) {
                     print_error('invaliduserdepartment', 'block_iomad_company_management');
                 }
                 if ($allow) {
                     if ($roletype != 0) {
                         // Adding a manager type.
                         // Add user to the company manager table.
                         if ($userrecord = $DB->get_record('company_users', array('companyid' => $this->selectedcompany, 'userid' => $adduser->id))) {
                             if ($roletype == 1 && $userrecord->managertype == 0) {
                                 // Give them the company manager role.
                                 role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
                                 // Deal with company courses.
                                 if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                     foreach ($companycourses as $companycourse) {
                                         if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                             if ($DB->record_exists('company_created_courses', array('companyid' => $companycourse->companyid, 'courseid' => $companycourse->courseid))) {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                                             } else {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                             }
                                         }
                                     }
                                 }
                             } else {
                                 if ($roletype == 2 && $userrecord->managertype == 0) {
                                     // Give them the department manager role.
                                     role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                     // Deal with company courses.
                                     if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                         foreach ($companycourses as $companycourse) {
                                             if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                 company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                             }
                                         }
                                     }
                                 } else {
                                     if ($roletype == 1 && ($userrecord->managertype = 2)) {
                                         // Give them the department manager role.
                                         role_unassign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                         role_assign($companymanagerrole->id, $adduser->id, $this->context->id);
                                         // Deal with course permissions.
                                         if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                             foreach ($companycourses as $companycourse) {
                                                 if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                     // If its a company created course then assign the editor role to the user.
                                                     if ($DB->record_exists('company_created_courses', array('companyid' => $this->selectedcompany, 'courseid' => $companycourse->courseid))) {
                                                         company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycourseeditorrole->id);
                                                     } else {
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                                     }
                                                 }
                                             }
                                         }
                                     } else {
                                         if ($roletype == 2 && ($userrecord->managertype = 1)) {
                                             // Give them the department manager role.
                                             role_unassign($companymanagerrole->id, $adduser->id, $this->context->id);
                                             role_assign($departmentmanagerrole->id, $adduser->id, $this->context->id);
                                             // Deal with company course roles.
                                             if ($companycourses = $DB->get_records('company_course', array('companyid' => $this->selectedcompany))) {
                                                 foreach ($companycourses as $companycourse) {
                                                     if ($DB->record_exists('course', array('id' => $companycourse->courseid))) {
                                                         company_user::unenrol($adduser, array($companycourse->courseid), $companycourse->companyid);
                                                         company_user::enrol($adduser, array($companycourse->courseid), $companycourse->companyid, $companycoursenoneditorrole->id);
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                             $userrecord->managertype = $roletype;
                             $DB->update_record('company_users', $userrecord);
                         } else {
                             if ($roletype == 1 && $DB->get_records_sql('SELECT id FROM {company_users}
                                                         WHERE
                                                         userid = :userid
                                                         AND managertype = :roletype
                                                         AND companyid != :companyid', array('userid' => $adduser->id, 'roletype' => 1, 'companyid' => $this->selectedcompany))) {
                                 // We have a company manager from another company.
                                 // We need to add another record.
                                 $company = new company($this->selectedcompany);
                                 $company->assign_user_to_company($adduser->id);
                                 $DB->set_field('company_users', 'managertype', 1, array('userid' => $adduser->id, 'companyid' => $this->selectedcompany));
                                 // Deal with company courses.
//.........这里部分代码省略.........
开发者ID:sumitnegi933,项目名称:Moodle_lms_New,代码行数:101,代码来源:company_managers_form.php

示例15: delete_role

/**
 * function that deletes a role and cleanups up after it
 * @param roleid - id of role to delete
 * @return success
 */
function delete_role($roleid)
{
    global $CFG, $USER;
    $success = true;
    // mdl 10149, check if this is the last active admin role
    // if we make the admin role not deletable then this part can go
    $systemcontext = get_context_instance(CONTEXT_SYSTEM);
    if ($role = get_record('role', 'id', $roleid)) {
        if (record_exists('role_capabilities', 'contextid', $systemcontext->id, 'roleid', $roleid, 'capability', 'moodle/site:doanything')) {
            // deleting an admin role
            $status = false;
            if ($adminroles = get_roles_with_capability('moodle/site:doanything', CAP_ALLOW, $systemcontext)) {
                foreach ($adminroles as $adminrole) {
                    if ($adminrole->id != $roleid) {
                        // some other admin role
                        if (record_exists('role_assignments', 'roleid', $adminrole->id, 'contextid', $systemcontext->id)) {
                            // found another admin role with at least 1 user assigned
                            $status = true;
                            break;
                        }
                    }
                }
            }
            if ($status !== true) {
                error('You can not delete this role because there is no other admin roles with users assigned');
            }
        }
    }
    // first unssign all users
    if (!role_unassign($roleid)) {
        debugging("Error while unassigning all users from role with ID {$roleid}!");
        $success = false;
    }
    // cleanup all references to this role, ignore errors
    if ($success) {
        // MDL-10679 find all contexts where this role has an override
        $contexts = get_records_sql("SELECT contextid, contextid\n                                     FROM {$CFG->prefix}role_capabilities\n                                     WHERE roleid = {$roleid}");
        delete_records('role_capabilities', 'roleid', $roleid);
        delete_records('role_allow_assign', 'roleid', $roleid);
        delete_records('role_allow_assign', 'allowassign', $roleid);
        delete_records('role_allow_override', 'roleid', $roleid);
        delete_records('role_allow_override', 'allowoverride', $roleid);
        delete_records('role_names', 'roleid', $roleid);
    }
    // finally delete the role itself
    // get this before the name is gone for logging
    $rolename = get_field('role', 'name', 'id', $roleid);
    if ($success and !delete_records('role', 'id', $roleid)) {
        debugging("Could not delete role record with ID {$roleid}!");
        $success = false;
    }
    if ($success) {
        add_to_log(SITEID, 'role', 'delete', 'admin/roles/action=delete&roleid=' . $roleid, $rolename, '', $USER->id);
    }
    return $success;
}
开发者ID:edwinphillips,项目名称:moodle-485cb39,代码行数:61,代码来源:accesslib.php


注:本文中的role_unassign函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。