Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
 /**
 * The other half to print_entry, this checks the form data
 *
 * This function checks that the user has completed the task on the
 * enrolment entry page and then enrolls them.
 *
 * @param    form    the form data submitted, as an object
 * @param    course  the current course, as an object
 */
 function check_entry($form, $course)
 {
     global $CFG, $USER, $SESSION, $THEME;
     if (empty($form->password)) {
         $form->password = '';
     }
     if (empty($course->password)) {
         // do not allow entry when no course password set
         // automatic login when manual primary, no login when secondary at all!!
         error('illegal enrolment attempted');
     }
     $groupid = $this->check_group_entry($course->id, $form->password);
     if (stripslashes($form->password) == $course->password or $groupid !== false) {
         if (isguestuser()) {
             // only real user guest, do not use this for users with guest role
             $USER->enrolkey[$course->id] = true;
             add_to_log($course->id, 'course', 'guest', 'view.php?id=' . $course->id, getremoteaddr());
         } else {
             /// Update or add new enrolment
             if (enrollUserInCourse($USER->username, $USER->username, $course->fullname, true)) {
                 if (enrol_into_course($course, $USER, 'manual')) {
                     // force a refresh of mycourses
                     send_enrollment_notification($course, $USER);
                     // Added: 05/08/2012
                     unset($USER->mycourses);
                     if ($groupid !== false) {
                         if (!groups_add_member($groupid, $USER->id)) {
                             print_error('couldnotassigngroup');
                         }
                     }
                     if (!enrollQSUser($USER, $course)) {
                         //Added: 01.06.2011
                         admin_webservicefailed_email($USER, 'enrollUser', $course);
                     }
                 } else {
                     enrollUserInCourse($USER->username, $USER->username, $course->fullname, false);
                     print_error('couldnotassignrole');
                 }
             } else {
                 admin_webservicefailed_email($USER, 'enrollUser', $course);
                 print_error('couldnotassignrole');
             }
         }
         if ($SESSION->wantsurl) {
             $destination = $SESSION->wantsurl;
             unset($SESSION->wantsurl);
         } else {
             $destination = "{$CFG->wwwroot}/course/view.php?id={$course->id}";
         }
         redirect($destination);
     } else {
         if (!isset($CFG->enrol_manual_showhint) or $CFG->enrol_manual_showhint) {
             $this->errormsg = get_string('enrolmentkeyhint', '', substr($course->password, 0, 1));
         } else {
             $this->errormsg = get_string('enrolmentkeyerror', 'enrol_manual');
         }
     }
 }