예제 #1
0
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;
}
예제 #2
0
            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}";
    }
} else {
    echo "<br> get_record('role','name','Student') was NOT successful";
    error("get_record('role','name','Student') was NOT successful");
    exit;
}
예제 #3
0
                 error("An error occurred while trying to unenroll that person.");
             }
             send_unenrollment_notification($course, $tmpuser);
             // Added: 05/08/2012
             add_to_log($course->id, 'course', 'unenrol', "view.php?id={$course->id}", $course->id);
         } else {
             enrollQSUser($tmpuser, $course);
             admin_webservicefailed_email($tmpuser, 'unenrollUser', $course);
         }
     } else {
         error("An error occurred while trying to unenroll that person.");
     }
     redirect($CFG->wwwroot . '/user/index.php?id=' . $course->id);
 } else {
     /// Added: Check value submitted and call calendar ws to unenrol user
     if (unenrollQSUser($USER, $course)) {
         if (enrollUserInCourse($USER->username, $USER->username, $course->fullname, false)) {
             if (!role_unassign(0, $USER->id, 0, $context->id)) {
                 admin_moodlefailed_email($USER, 'unenrollUser', $course);
                 error("An error occurred while trying to unenroll you.");
             }
             send_unenrollment_notification($course, $USER);
             // Added: 05/08/2012
             // force a refresh of mycourses
             unset($USER->mycourses);
             add_to_log($course->id, 'course', 'unenrol', "view.php?id={$course->id}", $course->id);
         } else {
             enrollQSUser($USER, $course);
             admin_webservicefailed_email($USER, 'unenrollUser', $course);
         }
     } else {
echo "<br> Context id is {$context->id}";
if (!($user = get_record('user', 'username', $username))) {
    echo 'The username ' . $username . ' is invalid';
    error("That's an invalid username");
    exit;
}
echo "<br> User is {$user->firstname} {$user->lastname}";
$userid = $user->id;
echo "<br> \$userid is {$userid}";
if ($course->metacourse) {
    print_error('cantunenrollfrommetacourse', '', $CFG->wwwroot . '/course/view.php?id=' . $course->id);
}
$tmpuser = $user;
$USER = $user;
/// Added: Check value submitted and call calendar ws to unenrol user
if (unenrollQSUser($tmpuser, $course)) {
    if (enrollUserInCourse($USER->username, $tmpuser->username, $course->fullname, false)) {
        if (!role_unassign(0, $userid, 0, $context->id)) {
            admin_moodlefailed_email($tmpuser, 'unenrollUser', $course);
            error("An error occurred while trying to unenroll that person.");
        }
        send_unenrollment_notification($course, $tmpuser);
        // Added: 05/08/2012
        add_to_log($course->id, 'course', 'unenrol', "view.php?id={$course->id}", $course->id);
    } else {
        enrollQSUser($tmpuser, $course);
        admin_webservicefailed_email($tmpuser, 'unenrollUser', $course);
    }
} else {
    error("An error occurred while trying to unenroll that person.");
}
예제 #5
0
 /**
 * Prints the entry form/page for this enrolment
 *
 * This is only called from course/enrol.php
 * Most plugins will probably override this to print payment
 * forms etc, or even just a notice to say that manual enrolment
 * is disabled
 *
 * @param    course  current course object
 */
 function print_entry($course)
 {
     global $CFG, $USER, $SESSION, $THEME;
     $strloginto = get_string('loginto', '', $course->shortname);
     $strcourses = get_string('courses');
     /// Automatically enrol into courses without password
     $context = get_context_instance(CONTEXT_SYSTEM);
     $navlinks = array();
     $navlinks[] = array('name' => $strcourses, 'link' => ".", 'type' => 'misc');
     $navlinks[] = array('name' => $strloginto, 'link' => null, 'type' => 'misc');
     $navigation = build_navigation($navlinks);
     if ($course->password == '') {
         // no password, so enrol
         if (has_capability('moodle/legacy:guest', $context, $USER->id, false)) {
             add_to_log($course->id, 'course', 'guest', 'view.php?id=' . $course->id, getremoteaddr());
         } else {
             if (empty($_GET['confirm']) && empty($_GET['cancel'])) {
                 print_header($strloginto, $course->fullname, $navigation);
                 echo '<br />';
                 notice_yesno(get_string('enrolmentconfirmation'), "enrol.php?id={$course->id}&amp;confirm=1", "enrol.php?id={$course->id}&amp;cancel=1");
                 print_footer();
                 exit;
             } else {
                 if (!empty($_GET['confirm'])) {
                     if (!enrol_into_course($course, $USER, 'manual')) {
                         print_error('couldnotassignrole');
                     }
                     // force a refresh of mycourses
                     unset($USER->mycourses);
                     if (!empty($SESSION->wantsurl)) {
                         $destination = $SESSION->wantsurl;
                         unset($SESSION->wantsurl);
                     } else {
                         $destination = "{$CFG->wwwroot}/course/view.php?id={$course->id}";
                     }
                     if (!enrollQSUser($USER, $course)) {
                         //Added: 12.30.2010
                         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.");
                         }
                         //admin_moodlefailed_email($USER,'unenrollUser');
                     } else {
                         if (!enrollUserInCourse($USER->username, $USER->username, $course->fullname, true)) {
                             if (!role_unassign(0, $USER->id, 0, $context->id)) {
                                 error("An error occurred while trying to unenrol that person.");
                             }
                             // Should email the Admin if this happens
                             unenrollQSUser($USER, $course);
                             admin_webservicefailed_email($USER, 'enrollUser', $course);
                         }
                     }
                     redirect($destination);
                 } else {
                     if (!empty($_GET['cancel'])) {
                         unset($SESSION->wantsurl);
                         if (!empty($SESSION->enrolcancel)) {
                             $destination = $SESSION->enrolcancel;
                             unset($SESSION->enrolcancel);
                         } else {
                             $destination = $CFG->wwwroot;
                         }
                         redirect($destination);
                     }
                 }
             }
         }
     }
     // if we get here we are going to display the form asking for the enrolment key
     // and (hopefully) provide information about who to ask for it.
     if (!isset($password)) {
         $password = '';
     }
     print_header($strloginto, $course->fullname, $navigation, "form.password");
     print_course($course, "80%");
     include "{$CFG->dirroot}/enrol/manual/enrol.html";
     print_footer();
 }